Last active
April 26, 2019 03:05
-
-
Save c02y/e1255f604896532cd93bb5d231671642 to your computer and use it in GitHub Desktop.
clean abbrs/functions in config.fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace tk and tka functions with one single function: | |
function tk -d 'tmux kill-session all(default)/single(id)/multiple(id1 id2)/except(-e)/list(-l) sessions' | |
if test (ps -ef | grep -v grep | grep -i tmux | wc -l ) = 0 | |
echo "No tmux server is running!!!" | |
return | |
end | |
set -l options 'e' 'l' | |
argparse -n tk $options -- $argv | |
or return | |
if set -q _flag_l | |
tmux ls | |
if set -q TMUX_PANE # check if running inside a tmux session | |
echo | |
echo Already inside tmux session: (tmux display-message -p '#S') | |
end | |
return | |
end | |
if set -q $argv[1] # no arguments | |
if set -q TMUX_PANE # check if running inside a tmux session | |
echo Inside a tmux session! | |
read -n 1 -l -p 'echo "Kill all sessions include current running one? [y/N]"' answer | |
if test "$answer" = "y" | |
echo tmux kill-server # kill all sessions include current one | |
end | |
end | |
return | |
end | |
if test (count $argv) -gt 0 | |
set -l sid (tmux ls | nl | awk '{print $2}' | sed 's/://g') | |
for i in $sid | |
if set -q _flag_e | |
if not contains $i $argv | |
tmux kill-session -t $i | |
echo Tmux session $i is killed | |
end | |
else | |
if contains $i $argv | |
tmux kill-session -t $i | |
echo Tmux session $i is killed | |
end | |
end | |
end | |
echo \n--------------\n | |
echo Left sessions: | |
tmux ls | |
end | |
end | |
# repalce f, fl, fv, fe, fex, ff, fcc, fing functions with finds functions | |
function finds -d 'find a file/folder and view/edit using less/vim/emacs/emx/cd/readlink with fzf' | |
set -l options 'l' 'v' 'e' 'x' 'c' 'p' 'g' | |
argparse -n finds $options -- $argv | |
or return | |
if not fzfp # fzf doesn't exist, $status != 0 | |
find $argv[1] -name "*$argv[2]*" | |
return | |
end | |
if set -q _flag_l # find a file and view it using less | |
less (find $argv[1] -name "*$argv[2]*" | fzf) | |
else if set -q _flag_v # find a file and view it using vim | |
vim (find $argv[1] -name "*$argv[2]*" | fzf) | |
else if set -q _flag_e # find a file and view it using emm | |
emm (find $argv[1] -name "*$argv[2]*" | fzf) | |
else if set -q _flag_x # find a file and view it using emx | |
emx (find $argv[1] -name "*$argv[2]*" | fzf) | |
else if set -q _flag_c # find a folder and try cd into it | |
cd (find $argv[1] -type d -name "*$argv[2]*" | fzf) | |
else if set -q _flag_p # find a file/folder and copy/echo its path | |
if not test $DISPLAY | |
readlink -f (find $argv[1] -name "*$argv[2]*" | fzf) | |
else | |
find $argv[1] -name "*$argv[2]*" | fzf | xc | |
end | |
else if set -q _flag_g # find all the .git directory | |
if set -q $argv[1] # no argument | |
find . -type d -name .git | sort | |
else | |
find $argv[1] -type d -name .git | sort | |
end | |
else | |
if set -q $argv[2] # no argv[2] | |
find . -name "*$argv[1]*" | |
else | |
find $argv[1] -name "*$argv[2]*" | |
end | |
end | |
end | |
# replace ft, ftr, ftc, ftcr, lcl functions with fts function | |
function fts -d 'find the temporary files such as a~ or #a or .a~, and files for latex, if no argv is passed, use the current dir' | |
set -l options 'c' 'C' 'r' 'R' 'l' | |
argparse -n fts $options -- $argv | |
or return | |
if set -q $argv[1] # no ARGV | |
set ARGV "." | |
else | |
set ARGV $argv | |
end | |
if set -q _flag_c # one level, not recursive, print | |
find $ARGV -maxdepth 1 \( -name "*~" -o -name "#?*#" -o -name ".#?*" -o -name "*.swp" \) | xargs -r ls -lhd | nl | |
else if set -q _flag_C # one level, not recursive, remove | |
find $ARGV -maxdepth 1 \( -name "*~" -o -name "#?*#" -o -name ".#?*" -o -name "*.swp" \) | xargs rm -rfv | |
else if set -q _flag_r # recursive, print | |
find $ARGV \( -name "*~" -o -name "#?*#" -o -name ".#?*" -o -name "*.swp" \) | xargs -r ls -lhd | nl | |
else if set -q _flag_R # recursive, remove | |
find $ARGV \( -name "*~" -o -name "#?*#" -o -name ".#?*" -o -name "*.swp" \) | xargs rm -rfv | |
else if set -q _flag_l # remove temporary files for latex | |
if not find $ARGV -maxdepth 1 -name "*.tex" | egrep '.*' # normal find returns 0 no matter what | |
echo "$ARGV is not a LaTeX directory!" | |
return | |
end | |
for EXT in ind ilg toc out idx aux fls log fdb_latexmk nav snm | |
# ind ilg toc out idx aux fls log fdb_latexmk faq blg bbl brf nlo dvi ps lof pdfsync synctex.gz | |
find $ARGV -maxdepth 1 \( -name "*.$EXT" -o -name "auto" \) | xargs -r rm -rv | |
end | |
fts -C | |
end | |
end | |
# replace t-xa, t-ca, t-ta, t-xxx and dt with tars function | |
function tars -d 'tar extract(x)/list(l)/create(l, add extra arg to include .git dir), or others using dtrx(d)' | |
set -l options 'x' 'l' 'c' 'd' | |
argparse -n tars $options -- $argv | |
or return | |
if set -q _flag_x # extract | |
tar xvfa $argv | |
else if set -q _flag_l # list contents | |
tar tvfa $argv | |
else if set -q _flag_c # create archive | |
# remove the end slash in argv | |
set ARGV (echo $argv[1] | sed 's:/*$::') | |
if test (count $argv) = 1 | |
tar cvfa $ARGV.tar.xz $ARGV --exclude-vcs | |
else | |
tar cvfa $ARGV.tar.xz $ARGV | |
end | |
else if set -q _flag_d | |
if command -sq dtrx | |
dtrx -v $argv | |
else | |
echo "dtrx command is not installed!" | |
end | |
end | |
end | |
# replace debl and debx with deb function | |
function deb -d 'deb package, list(default)/extract(x)' | |
set -l options 'x' | |
argparse -n deb $options -- $argv | |
or return | |
if set -q _flag_x # extract | |
set pkgname (basename $argv[1] .deb) | |
mkdir -v $pkgname | |
if command -sq dpkg # check if dpkg command exists, replace which | |
dpkg -x $argv[1] $pkgname | |
else | |
set dataname (ar t $argv[1] | ag data) | |
if not ar p $argv[1] $dataname | tar Jxv -C $pkgname ^/dev/null # failed, $status != 0 | |
if not ar p $argv[1] $dataname | tar zxv -C $pkgname ^/dev/null # failed, $status != 0 | |
rm -rfv $pkgname | |
return | |
end | |
end | |
end | |
echo ----in $pkgname ---- | |
else # default, list | |
dpkg -c $argv | |
end | |
end | |
# replace rpmi, rpml and rpmx functions with rpm function | |
function rpm -d 'rpm file, install(i)/extract(x)/list(default)' | |
set -l options 'i' 'l' 'x' | |
argparse -n rpm $options -- $argv | |
or return | |
if set -q _flag_i # install | |
sudo rpm -Uvh $argv | |
else if set -q _flag_x # extract | |
for i in $argv | |
echo \<$i\> | |
echo ------------------- | |
rpm2cpio $i | cpio -idmv | |
end | |
else # default list | |
for i in $argv | |
echo \<$i\> | |
echo ------------------- | |
rpm -qlpv $i | less | |
end | |
end | |
end | |
# remove cdls, cdll, cdla functions | |
# rename bin/b2 to bin/num since b2 is in anaconda2/bin | |
# remove cdf, dos2 | |
abbr condas 'binstar search -t conda' # [packagename] | |
abbr condai 'conda install -c' # [channel] [packagename] | |
abbr condau 'conda upgrade --all -vy; conda clean -avy' | |
abbr condac 'conda clean -avy' | |
abbr condaS 'anaconda show' # [channel/packagename] | |
abbr lessem 'less ~/.local/bin/emm' | |
# after `abbr xc` | |
abbr rl 'readlink -f' | |
# Download anaconda from https://mirrors.cloud.tencent.com/anaconda/archive/ | |
# Check ~/.condarc for configuration | |
# https://www.piqizhu.com/tools/anaconda | |
#conda install -c binstar binstar # renamed to anaconda-client, so `conda install anaconda-client` | |
#binstar search -t conda packgename # get the channel(user) name | |
#conda install -c channel packagename | |
# After install package using `conda install -c CHANNEL PKG`, you have to manually | |
# conda config --add channels your_new_channel, or these packages won't be updateed when `condau` | |
# | |
# The packages needed to be installed using conda are(only if you have no sudo permission or the offcial is old) | |
# conda install -c conda-forge ncurses emacs w3m fish the_silver_searcher source-highlight | |
# conda install -c ripl-org tmux | |
# conda install -c lebedov tig | |
abbr condas 'binstar search -t conda' # [packagename] | |
abbr condai 'conda install -c' # [channel] [packagename] | |
abbr condau 'conda upgrade --all -vy; conda clean -avy' | |
abbr condac 'conda clean -avy' | |
abbr condaS 'anaconda show' # [channel/packagename] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment