Skip to content

Instantly share code, notes, and snippets.

@c02y
Last active March 8, 2019 08:00
Show Gist options
  • Save c02y/4e6b92db58d818472a567f9d291b34db to your computer and use it in GitHub Desktop.
Save c02y/4e6b92db58d818472a567f9d291b34db to your computer and use it in GitHub Desktop.
config.fish
1. there are two gitsh in config.fish, delete the second one
2. abbr gitpl 'git pull -v'
3. abbr gitpu 'git push -v'
4. delete z.fish and zz.fish
5. clean config.fish
6. remove stow in ~/.local/bin, it depends on other libs, and find a binary/script replacement
7. replace grep -w with extra space, since -w doesn't parse `-` like t-xa
set -gx Z_PATH ~/.config/fish/functions/
if test -e $Z_PATH/z.lua
source (lua $Z_PATH/z.lua --init fish once echo | psub)
# z.lua using built-in cd which won't affect the cd stack of fish shell, use fish's cd so you can use `cd -`
set -gx _ZL_CD cd
set -gx _ZL_INT_SORT 1
set -gx _ZL_FZF_HEIGHT 0 # 0 means fullscreen
set -gx FZF_DEFAULT_OPTS '-1 -0' # auto select the only match, auto exit if no match
end
function zp -d 'check exists of z.lua, with any given argument, update z.lua'
if test -e $Z_PATH/z.lua; and set -q $argv[1] # z.lua file exists and no any argv is given, two conditions
return 0
else
if not curl https://raw.githubusercontent.com/skywind3000/z.lua/master/z.lua -o /tmp/z.lua
echo "Failed to install/update z.lua due to Internet issue!"
return 1
else
mv /tmp/z.lua $Z_PATH/z.lua
return 0
end
end
end
abbr zb 'z -b' # Bonus: zb .. equals to cd .., zb ... equals to cd ../.. and
# zb .... equals to cd ../../.., and so on. Finally, zb ..20 equals to cd (..)x20.
function zz -d 'z\'s interactive selection mode'
if not zp
echo "Failed to install z.lua!"
return
end
if fzfp # fzf exists, $status = 0
set z_cmd z -I
else
set z_cmd z -i
end
if test (count $argv) = 0
eval $z_cmd .
else
eval $z_cmd $argv
end
end
function zh -d 'z\'s cd into the cd history'
if not zp
echo "Failed to install z.lua!"
return
end
if fzfp # fzf exists, $status = 0
set z_cmd z -I -t
else
set z_cmd z -i -t
end
if test (count $argv) -eq 0
eval $z_cmd .
else
eval $z_cmd $argv
end
end
function bkm -d 'backups manager: rename files/dirs from name to name.bak or backwards(-b) using cp/mv(-m)'
# set optional options
set -l options 'b' 'm'
argparse -n bkm -N 1 $options -- $argv
or return
set -l backward 0 # 0(name->name.bak), 1(backward, name.bak->name)
set -l CMD cp -vr # 0(cp), 1(mv)
if set -q _flag_b
set backward 1
end
if set -q _flag_m
set CMD mv -v
end
for name in $argv # support multiple arguments
if test $backward = 1
set -l result (echo (string split -r -m1 .bak $name)[1])
if test -e $result
echo $result alread exists.
else
eval $CMD $name $result
end
else
set old $name
if test "/" = (echo (string sub --start=-1 $name)) # for dir ending with "/"
set old (echo (string split -r -m1 / $name)[1])
end
if test -e $old.bak
echo $old.bak already exists.
read -n 1 -l -p 'echo "Remove $old.bak first? [y/N]"' answer
if test "$answer" = "y" -o "$answer" = " "
rm -rfv $old.bak
else
continue
end
end
eval $CMD $old{,.bak}
end
end
end
# emacs
# -Q = -q --no-site-file --no-splash, which will not load something like emacs-googies
alias emx 'emacs -nw -q --no-splash --eval "(setq find-file-visit-truename t)"'
abbr emq 'emacs -q --no-splash'
abbr emd 'rm -rfv ~/.emacs.d/init.elc; emacs --debug-init'
abbr eml 'emacs -q --no-splash --load' # load specific init.el
abbr emn 'emacs --no-desktop'
abbr emi 'emacs ~/.emacs.d/init.el'
abbr emc 'emacs ~/.cgdb/cgdbrc'
abbr emf 'emacs $FISH_CONFIG_PATH'
abbr emt 'emacs ~/.tmux.conf'
abbr emv 'emacs ~/.vimrc'
abbr emb 'emacs ~/.bashrc'
abbr em2 'emacs ~/Recentchange/TODO'
abbr emtime "time emacs --debug-init -eval '(kill-emacs)'" # time emacs startup time
replace abbr t with function t
function t -d 'if tmux is running, attach it, if not, create a new tmux session, and check $SHELL'
if not command -sq tmux
echo tmux is not installed, please install it!
end
if test (basename $SHELL) = "bash"
if test -f ~/anaconda3/bin/fish
set -gx SHELL ~/anaconda3/bin/fish
else if command -sq fish
set -gx SHELL (which fish)
end
end
if test "$TERM" != "screen-256color"; and test $TMUX
# not already inside a tmux session, and a tmux session is running
tmux attach
else if test "$TERM" != "screen-256color"; and not test $TMUX
# not already inside a tmux session, and no tmux session is running
tmux
else
echo Already inside a tmux session!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment