fish: Make all aliases into functions

Using alias inside ~/.config/fish/config.fish can slow down shell
start as each alias/function will be eagerly loaded.

alias is slow because it involves eval.

functions support lazy/auto loading.
https://fishshell.com/docs/current/tutorial.html#autoloading-functions
This commit is contained in:
Sanchayan Maity 2021-12-10 16:15:00 +05:30
parent b8ccdaacd6
commit 0d0480a6b2
46 changed files with 138 additions and 61 deletions

View File

@ -16,67 +16,6 @@ else
export EDITOR="nvim"
end
alias b="cd .."
alias c="clear"
alias m="mutt"
alias v="nvim"
alias vc="nvim --clean"
alias vn="nvim -u NONE"
alias vnrc="nvim -u NORC"
alias vnp="nvim --noplugin"
alias tksa="tmux kill-session -a"
alias tks="tmux kill-server"
alias tat="tmux attach -t "
alias tls="tmux ls"
alias vf="v (fzf)"
alias cs="cscope -bqR"
alias cat="bat"
alias t="tokei ."
alias gst="gst-inspect-1.0"
alias gsl="gst-launch-1.0"
alias sds="systemctl status "
alias sde="systemctl enable "
alias sdd="systemctl disable "
alias sfc="source ~/.config/fish/config.fish"
alias icat="kitty +kitten icat (fzf)"
alias jb="journalctl -r -b -1"
alias jf="journalctl -f"
alias jk="journalctl -r -k"
alias jr="journalctl -r"
alias ju="journalctl -u"
alias jx="journalctl -xe"
alias dpw="pw-dump | jq | nvim -c 'setlocal ft=json' -R"
# Git helpers
alias vg="vgrep"
alias vs="vgrep -s"
# Open fugitive with nvim directly
alias gn="nvim +Git +only"
# Open modified files
# ACMRU = Added || Copied || Modified || Renamed || Unmerged
# Edit all uncommitted files that have changes since the last commit (be they staged or unstaged)
alias vd="nvim (git diff HEAD --name-only --diff-filter=ACMR)"
# Edit all staged files that have changes since the last commit
alias vds="nvim (git diff --staged --name-only --diff-filter=ACMR)"
# Edit all files that were altered in the last commit
alias vdc="nvim (git diff HEAD^ --name-only --diff-filter=ACMR)"
# Edit files changed since master
alias vdm="nvim (git diff master --name-only --diff-filter=ACMR)"
# Edit files unmerged
alias vdu="nvim (git diff --name-only --diff-filter=U | uniq)"
# Add unmerged files
alias vdua="git add (git diff --name-only --diff-filter=U)"
# Cargo aliases
alias cba='cargo update && cargo build --all && cargo doc'
alias cbb='cargo build --all'
alias cbc='cargo clean'
alias cbd='cargo doc'
alias cbD='cargo doc --open'
alias cbu='cargo update'
fzf_key_bindings
# https://github.com/fish-shell/fish-shell/issues/7485#issuecomment-728984689

View File

@ -0,0 +1,3 @@
function b --wraps='cd ..' --description 'alias b=cd ..'
cd .. $argv;
end

View File

@ -0,0 +1,3 @@
function c --wraps=clear --description 'alias c=clear'
clear $argv;
end

View File

@ -0,0 +1,3 @@
function cat --wraps=bat --description 'alias cat=bat'
bat $argv;
end

View File

@ -0,0 +1,3 @@
function cbD --wraps='cargo doc --open' --description 'alias cbD=cargo doc --open'
cargo doc --open $argv;
end

View File

@ -0,0 +1,3 @@
function cba --wraps='cargo update && cargo build --all && cargo doc' --description 'alias cba=cargo update && cargo build --all && cargo doc'
cargo update && cargo build --all && cargo doc $argv;
end

View File

@ -0,0 +1,3 @@
function cbb --wraps='cargo build --all' --description 'alias cbb=cargo build --all'
cargo build --all $argv;
end

View File

@ -0,0 +1,3 @@
function cbc --wraps='cargo clean' --description 'alias cbc=cargo clean'
cargo clean $argv;
end

View File

@ -0,0 +1,3 @@
function cbd --wraps='cargo doc' --description 'alias cbd=cargo doc'
cargo doc $argv;
end

View File

@ -0,0 +1,3 @@
function cbu --wraps='cargo update' --description 'alias cbu=cargo update'
cargo update $argv;
end

View File

@ -0,0 +1,3 @@
function dpw --wraps=pw-dump\ \|\ jq\ \|\ nvim\ -c\ \'setlocal\ ft=json\'\ -R --description alias\ dpw=pw-dump\ \|\ jq\ \|\ nvim\ -c\ \'setlocal\ ft=json\'\ -R
pw-dump | jq | nvim -c 'setlocal ft=json' -R $argv;
end

View File

@ -0,0 +1,3 @@
function gn --wraps='nvim +Git +only' --description 'alias gn=nvim +Git +only'
nvim +Git +only $argv;
end

View File

@ -0,0 +1,3 @@
function gsl --wraps=gst-launch-1.0 --description 'alias gsl=gst-launch-1.0'
gst-launch-1.0 $argv;
end

View File

@ -0,0 +1,3 @@
function gst --wraps=gst-inspect-1.0 --description 'alias gst=gst-inspect-1.0'
gst-inspect-1.0 $argv;
end

View File

@ -0,0 +1,3 @@
function icat --wraps='kitty +kitten icat (fzf)' --description 'alias icat=kitty +kitten icat (fzf)'
kitty +kitten icat (fzf) $argv;
end

View File

@ -0,0 +1,3 @@
function jb --wraps='journalctl -r -b -1' --description 'alias jb=journalctl -r -b -1'
journalctl -r -b -1 $argv;
end

View File

@ -0,0 +1,3 @@
function jf --wraps='journalctl -f' --description 'alias jf=journalctl -f'
journalctl -f $argv;
end

View File

@ -0,0 +1,3 @@
function jk --wraps='journalctl -r -k' --description 'alias jk=journalctl -r -k'
journalctl -r -k $argv;
end

View File

@ -0,0 +1,3 @@
function jr --wraps='journalctl -r' --description 'alias jr=journalctl -r'
journalctl -r $argv;
end

View File

@ -0,0 +1,3 @@
function ju --wraps='journalctl -u' --description 'alias ju=journalctl -u'
journalctl -u $argv;
end

View File

@ -0,0 +1,3 @@
function jx --wraps='journalctl -xe' --description 'alias jx=journalctl -xe'
journalctl -xe $argv;
end

View File

@ -0,0 +1,3 @@
function lg
lazygit -ucd ~/.config/lazygit
end

View File

@ -0,0 +1,3 @@
function m --wraps=mutt --description 'alias m=mutt'
mutt $argv;
end

View File

@ -0,0 +1,3 @@
function sdd --wraps='systemctl disable ' --description 'alias sdd=systemctl disable '
systemctl disable $argv;
end

View File

@ -0,0 +1,3 @@
function sde --wraps='systemctl enable ' --description 'alias sde=systemctl enable '
systemctl enable $argv;
end

View File

@ -0,0 +1,3 @@
function sds --wraps='systemctl status ' --description 'alias sds=systemctl status '
systemctl status $argv;
end

View File

@ -0,0 +1,3 @@
function sfc --wraps='source ~/.config/fish/config.fish' --description 'alias sfc=source ~/.config/fish/config.fish'
source ~/.config/fish/config.fish $argv;
end

View File

@ -0,0 +1,3 @@
function t --wraps='tokei .' --description 'alias t=tokei .'
tokei . $argv;
end

View File

@ -0,0 +1,3 @@
function tat --wraps='tmux attach -t ' --description 'alias tat=tmux attach -t '
tmux attach -t $argv;
end

View File

@ -0,0 +1,3 @@
function tks --wraps='tmux kill-server' --description 'alias tks=tmux kill-server'
tmux kill-server $argv;
end

View File

@ -0,0 +1,3 @@
function tksa --wraps='tmux kill-session -a' --description 'alias tksa=tmux kill-session -a'
tmux kill-session -a $argv;
end

View File

@ -0,0 +1,3 @@
function tls --wraps='tmux ls' --description 'alias tls=tmux ls'
tmux ls $argv;
end

View File

@ -0,0 +1,3 @@
function v --wraps=nvim --description 'alias v=nvim'
nvim $argv;
end

View File

@ -0,0 +1,3 @@
function vc --wraps='nvim --clean' --description 'alias vc=nvim --clean'
nvim --clean $argv;
end

View File

@ -0,0 +1,6 @@
# Open modified files
# ACMRU = Added || Copied || Modified || Renamed || Unmerged
# Edit all uncommitted files that have changes since the last commit (be they staged or unstaged)
function vd --wraps='nvim (git diff HEAD --name-only --diff-filter=ACMR)' --description 'alias vd=nvim (git diff HEAD --name-only --diff-filter=ACMR)'
nvim (git diff HEAD --name-only --diff-filter=ACMR) $argv;
end

View File

@ -0,0 +1,3 @@
function vdc --wraps='nvim (git diff HEAD^ --name-only --diff-filter=ACMR)' --description 'Edit all files that were altered in the last commit'
nvim (git diff HEAD^ --name-only --diff-filter=ACMR) $argv;
end

View File

@ -0,0 +1,3 @@
function vdm --wraps='nvim (git diff master --name-only --diff-filter=ACMR)' --description 'Edit files changed since master'
nvim (git diff master --name-only --diff-filter=ACMR) $argv;
end

View File

@ -0,0 +1,3 @@
function vds --wraps='nvim (git diff --staged --name-only --diff-filter=ACMR)' --description 'Edit all staged files that have changes since the last commit'
nvim (git diff --staged --name-only --diff-filter=ACMR) $argv;
end

View File

@ -0,0 +1,3 @@
function vdu --wraps='nvim (git diff --name-only --diff-filter=U | uniq)' --description 'Edit files unmerged'
nvim (git diff --name-only --diff-filter=U | uniq) $argv;
end

View File

@ -0,0 +1,3 @@
function vdua --wraps='git add (git diff --name-only --diff-filter=U)' --description 'Add unmerged files'
git add (git diff --name-only --diff-filter=U) $argv;
end

View File

@ -0,0 +1,3 @@
function vf --wraps='v (fzf)' --description 'alias vf=v (fzf)'
v (fzf) $argv;
end

View File

@ -0,0 +1,3 @@
function vg --wraps=vgrep --description 'alias vg=vgrep'
vgrep $argv;
end

View File

@ -0,0 +1,3 @@
function vn --wraps='nvim -u NONE' --description 'alias vn=nvim -u NONE'
nvim -u NONE $argv;
end

View File

@ -0,0 +1,3 @@
function vnp --wraps='nvim --noplugin' --description 'alias vnp=nvim --noplugin'
nvim --noplugin $argv;
end

View File

@ -0,0 +1,3 @@
function vnrc --wraps='nvim -u NORC' --description 'alias vnrc=nvim -u NORC'
nvim -u NORC $argv;
end

View File

@ -0,0 +1,3 @@
function vs --wraps='vgrep -s' --description 'alias vs=vgrep -s'
vgrep -s $argv;
end