[misc] refactory

This commit is contained in:
Klesh Wong 2020-10-26 23:16:34 +08:00
parent fa6aca3c61
commit 5ebbb9f368

View File

@ -1,11 +1,16 @@
#!/usr/bin/env fish #!/usr/bin/env fish
#
set -U FZF_COMPLETE 0
set -gx EDITOR nvim set -gx EDITOR nvim
set -gx PGDATA /usr/local/var/postgres
set -gx LESS "-SRXF" # enable fzf completion hotkey
set -gx LS_COLORS 'ow=34;42;40' set -U FZF_COMPLETE 0
# no line-wrapping, good for `docker ps`
set -gx LESS "-SXF"
# nvm plugin
set -gx nvm_mirror http://npm.taobao.org/mirrors/node set -gx nvm_mirror http://npm.taobao.org/mirrors/node
# change OTHER-WRITABLE color for `ls` command
set -gx LS_COLORS 'ow=34;42;40'
# ranger highlighting color theme
set -gx HIGHLIGHT_OPTIONS --style=solarized-dark set -gx HIGHLIGHT_OPTIONS --style=solarized-dark
# tune git icon for nerdfont # tune git icon for nerdfont
@ -20,14 +25,14 @@ set -g __fish_git_prompt_char_conflictedstate "x"
set -g __fish_git_prompt_char_cleanstate "✔ " set -g __fish_git_prompt_char_cleanstate "✔ "
function append-path-if-exists function append-path-if-exists
if test -e $argv if test -e $argv
set -gx PATH $argv $PATH set -gx PATH $argv $PATH
end end
end end
function source-file-if-exists function source-file-if-exists
if test -e $argv if test -e $argv
source $argv source $argv
end end
end end
@ -39,86 +44,76 @@ append-path-if-exists /usr/local/bin
append-path-if-exists ~/.local/bin append-path-if-exists ~/.local/bin
append-path-if-exists ~/.yarn/bin append-path-if-exists ~/.yarn/bin
append-path-if-exists /snap/bin append-path-if-exists /snap/bin
#/usr/bin/xmodmap /home/klesh/.Xmodmap
if which pip 1>/dev/null 2>/dev/null; and pip show virtualfish > /dev/null 2>/dev/null # source virtualfish if available
eval (python -m virtualfish auto_activation) if which pip &>/dev/null && pip show virtualfish &>/dev/null
eval (python -m virtualfish auto_activation)
end end
# pronounce a English word # datetime in filename format
function dp
set play afplay
if not which $play 2>/dev/null
set play ffplay -nodisp -autoexit
end
wget -O /tmp/sound.mp3 "http://dict.youdao.com/dictvoice?audio=$argv[1]&type=1">/dev/null 2>/dev/null
and eval $play /tmp/sound.mp3 1>/dev/null 2>/dev/null
end
# print current datetime as in plain format which could be use a filename etc
function dt function dt
date "+%Y%m%d-%H%M%S" date "+%Y%m%d-%H%M%S"
end end
# translation
function d function d
set word $argv set meta (
set escaped_word (string escape --style url "$word") curl -SsLG "http://cn.bing.com/dict/search" --data-urlencode "q=$argv" | \
curl -SsL "http://cn.bing.com/dict/search?q=$escaped_word" |\ string match -r '<meta name="description" content="必应词典为您提供.+的释义,(.+?)" />'
grep -Eo '<meta name="description" content="(.+) " ?/>' |\ )
sed -E 's/<meta name="description" content="必应词典为您提供.+的释义,(.+)" ?\/>/\1/' |\ set trans (string replace -ra '\W(?=(\w+\.|网络释义:))' \n $meta[2])
sed -E 's/(.*)()(.*)/\1 \3/' | awk -v WORD=$word '{ string join \n $trans
c=0; end
print WORD;
for(i=1;i<=NF;i++) { # pronounciation
if(match($i, "^[a-z]+\\.|网络释义:$") != 0) { function dp
if(c==0) printf "\n"; set play afplay
printf "\n"; if not which $play 2>/dev/null
c++; set play ffplay -nodisp -autoexit
} end
printf "%s ",$i; wget -O /tmp/sound.mp3 "http://dict.youdao.com/dictvoice?audio=$argv[1]&type=1" &>/dev/null
} and eval $play /tmp/sound.mp3 1>/dev/null 2>/dev/null
printf "\n";
}' 2>/dev/null
end end
function clean-taobao-link function clean-taobao-link
echo "$argv" | sed 's/^\(.*\)?\(.*&\)\?\(id=[^&]\+\).*$/\1?\3/g' | xsel -sb echo "$argv" | sed 's/^\(.*\)?\(.*&\)\?\(id=[^&]\+\).*$/\1?\3/g' | xsel -sb
end end
# for WSL # for WSL
function sync-ssh-config function sync-ssh-config
# sshconfig has a restricted file permission requirement which normally hard to # sshconfig has a restricted file permission requirement which normally hard to
# be met on Window (i.e., syncing your config by Nextcloud on drive D). # be met on Window (i.e., syncing your config by Nextcloud on drive D).
# this function pour contents of files within ~/.ssh/config.d to ~/.ssh/config # this function pours contents of files within ~/.ssh/config.d to ~/.ssh/config
if test -d ~/.ssh/config.d if test -d ~/.ssh/config.d
rm -rf ~/.ssh/config rm -rf ~/.ssh/config
for cfg in (ls ~/.ssh/config.d) for cfg in (ls ~/.ssh/config.d)
cat ~/.ssh/config.d/$cfg >> ~/.ssh/config cat ~/.ssh/config.d/$cfg >> ~/.ssh/config
end
chmod 600 ~/.ssh/config
end end
chmod 600 ~/.ssh/config
end
end end
function swap-caps-esc function swap-caps-esc
setxkbmap -option caps:swapescape setxkbmap -option caps:swapescape
end end
function caps-to-grave function caps-to-grave
xmodmap -e "clear Lock" xmodmap -e "clear Lock"
xmodmap -e "keycode 66 = grave asciitilde" xmodmap -e "keycode 66 = grave asciitilde"
end end
# print out all colors with their index
function show-colors function show-colors
bash -c '(x=`tput op` y=`printf %76s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done)' bash -c '(x=`tput op` y=`printf %76s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done)'
end end
# auto startx # auto startx
if test -z "$DISPLAY" -a -n "$XDG_VTNR" -a "$XDG_VTNR" -eq "1" -a -z "$STARTED" if test -z "$STARTED" -a -z "$DISPLAY" -a -n "$XDG_VTNR" -a "$XDG_VTNR" -eq "1"
set -gx STARTED true set -gx STARTED true
startx startx
end end
alias k=kubectl alias k="kubectl"
alias kcc="k config get-contexts" alias kcc="k config get-contexts"
alias kcu="k config use-context" alias kcu="k config use-context"
alias kgd="k get deployment" alias kgd="k get deployment"
@ -128,7 +123,6 @@ alias kl="k logs -f --all-containers"
alias issh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' alias issh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
alias iscp='scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' alias iscp='scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
status is-interactive && cd $last_pwd
source-file-if-exists ~/.profile.fish source-file-if-exists ~/.profile.fish
status is-interactive && cd $last_pwd