chore(fish): simplified fish config to be the "same" as my zsh config

This commit is contained in:
Afonso Franco 2025-02-05 16:56:35 +00:00
parent 4933308689
commit e0b9a10150
Signed by: afonso
SSH key fingerprint: SHA256:gkVPzsQQJzqi21ntQBV6pXTx4bYI53rFGI4XtvCpwd4
34 changed files with 176 additions and 1188 deletions

View file

@ -0,0 +1,63 @@
# Credits to https://github.com/BrewingWeasel/fishbang
function last_history_item
echo $history[1]
end
function nth_history_item
# Times by negative one because in fish $history[1] is the last used command
# while running !1 in bash returns the first command in your history ($history[-1] in fish)
set index (math (echo $argv[1] | cut -c 2- ) x -1)
echo $history[$index]
end
function _nth_history_arg
echo $history[1] | read -t --list args
echo $args[(math $argv[1] + 1)]
end
function last_history_arg
echo $history[1] | read -t --list args
echo $args[-1]
end
function first_history_arg
echo $history[1] | read -t --list args
echo $args[2]
end
function history_args
echo (string split --max 1 " " $history[1])[2]
end
function nth_history_arg
_nth_history_arg (echo $argv[1] | cut -c 3-)
end
function history_prefix_search
set cmd (echo $argv[1] | cut -c 2- )
history -p $cmd | head -n 1
end
function history_search
set cmd (echo $argv[1] | cut -c 3- )
history $cmd | head -n 1
end
# Commmands
abbr -a bang_history_prefix_search --position anywhere --regex '!([a-zA-Z0-9_.-]*)' --function history_prefix_search # !dnf returns the last command that started with dnf
abbr -a bang_history_search --position anywhere --regex '!\?([a-zA-Z0-9_.-]*)' --function history_search # !?abc returns the last command that included abc
abbr -a bang_negative_nth_history_item --position anywhere --regex '!-?([0-9]*)' --function nth_history_item # !3 returns the 3rd command used. !-3 returns the 3rd most recent command used.
abbr -a !! --position anywhere --function last_history_item # !! returns the last command. Taken from the fish documentation
# Arguments
abbr -a !^ --position anywhere --function first_history_arg # !^ returns the first argument of the last command
abbr -a !\$ --position anywhere --function last_history_arg # !$ returns the last argument of the last command
abbr -a !\* --position anywhere --function history_args # !* returns all arguments of the last command
abbr -a bang_nth_arg --position anywhere --regex '!:([0-9]*)' --function nth_history_arg # !$ returns the last argument of the last command
bind -M insert enter expand-abbr execute
bind -M default enter expand-abbr execute
bind enter expand-abbr execute

View file

@ -1,28 +0,0 @@
# fzf.fish is only meant to be used in interactive mode. If not in interactive mode and not in CI, skip the config to speed up shell startup
if not status is-interactive && test "$CI" != true
exit
end
# Because of scoping rules, to capture the shell variables exactly as they are, we must read
# them before even executing _fzf_search_variables. We use psub to store the
# variables' info in temporary files and pass in the filenames as arguments.
# This variable is global so that it can be referenced by fzf_configure_bindings and in tests
set --global _fzf_search_vars_command '_fzf_search_variables (set --show | psub) (set --names | psub)'
# Install the default bindings, which are mnemonic and minimally conflict with fish's preset bindings
fzf_configure_bindings
# Doesn't erase autoloaded _fzf_* functions because they are not easily accessible once key bindings are erased
function _fzf_uninstall --on-event fzf_uninstall
_fzf_uninstall_bindings
set --erase _fzf_search_vars_command
functions --erase _fzf_uninstall _fzf_migration_message _fzf_uninstall_bindings fzf_configure_bindings
complete --erase fzf_configure_bindings
set_color cyan
echo "fzf.fish uninstalled."
echo "You may need to manually remove fzf_configure_bindings from your config.fish if you were using custom key bindings."
set_color normal
end

View file

@ -0,0 +1,39 @@
function vim
if test -z "$argv"
if test -f "./.session.vim"
nvim -S .session.vim -c 'lua vim.g.savesession = true'
else
nvim -c 'lua vim.g.savesession = true'
end
else
nvim $argv
end
end
function routevpn
sudo route -n add $argv 10.8.0.1
end
# Aliases
alias ls="eza --icons -l --sort type"
alias lg="lazygit"
alias routes="netstat -rn -f inet"
alias lc="lazygit --work-tree=$HOME --git-dir=$HOME/dotfiles"
alias config="git --work-tree=$HOME --git-dir=$HOME/dotfiles"
alias nvim_update='nvim --headless "+Lazy! sync" +qa'
function qmk_flash_right
echo "Flashing right side, waiting 5 seconds"
sleep 5
qmk flash -kb lily58 -km afonso -bl avrdude-split-right
end
function qmk_flash_left
echo "Flashing left side, waiting 5 seconds"
sleep 5
qmk flash -kb lily58 -km afonso -bl avrdude-split-left
end
function cd
builtin cd $argv; and ls
end

View file

@ -1,20 +0,0 @@
function _plugin-bang-bang_key_bindings --on-variable fish_key_bindings
bind --erase --all !
bind --erase --all '$'
switch "$fish_key_bindings"
case 'fish_default_key_bindings'
bind --mode default ! __history_previous_command
bind --mode default '$' __history_previous_command_arguments
case 'fish_vi_key_bindings' 'fish_hybrid_key_bindings'
bind --mode insert ! __history_previous_command
bind --mode insert '$' __history_previous_command_arguments
end
end
function _plugin-bang-bang_uninstall --on-event plugin-bang-bang_uninstall
bind --erase --all !
bind --erase --all '$'
functions --erase _plugin-bang-bang_uninstall
end
_plugin-bang-bang_key_bindings

View file

@ -0,0 +1,33 @@
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
set -l normal (set_color $fish_color_normal)
set -l status_color (set_color brgreen)
set -l cwd_color (set_color $fish_color_cwd)
set -l vcs_color (set_color yellow)
set -l prompt_status ""
# Since we display the prompt on a new line allow the directory names to be longer.
set -q fish_prompt_pwd_dir_length
or set -lx fish_prompt_pwd_dir_length 0
# Color the prompt in red on error
if test $last_status -ne 0
set status_color (set_color $fish_color_error)
set prompt_status $status_color "[" $last_status "]" $normal
end
echo -s $cwd_color (prompt_pwd) $vcs_color (fish_vcs_prompt) $normal ' ' $prompt_status
echo -n -s $status_color '' ' ' $normal
end
function fish_mode_prompt
switch $fish_bind_mode
case default
set_color --bold red
echo '[N] '
case visual
set_color --bold brmagenta
echo '[V] '
end
set_color normal
end