Skip to content

Instantly share code, notes, and snippets.

@hoanghuynh
Created July 21, 2017 18:44
Show Gist options
  • Save hoanghuynh/0860550f49133e6d4ae1b381710d70b1 to your computer and use it in GitHub Desktop.
Save hoanghuynh/0860550f49133e6d4ae1b381710d70b1 to your computer and use it in GitHub Desktop.
zsh
# alias
alias l='ls -ClA'
alias 'grep=grep --color=auto'
alias rsync='rsync -rvzpP --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r'
alias rsyncr='rsync -rvzpP --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r -e "ssh -p 31415"'
alias sshrsub='ssh -R 52698:localhost:52698'
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
alias cls='printf "\033c"'
alias gr='git remote update'
alias gp='git push'
alias z=zeus
alias zr='zeus rake'
alias zt='zeus rspec'
alias dbm="zeus rake db:migrate"
alias b=bundle
alias c=cucumber
alias dl='aria2c --file-allocation=none -x16'
# function
# quick find
f() {
echo "find . -iname \"*$1*\""
find . -iname "*$1*"
}
# find files
ff() {
echo "find . -type f -iname \"*$1*\""
find . -type f -iname "*$1*"
}
# find folders
fd() {
echo "find . -type d -iname \"*$1*\""
find . -type d -iname "*$1*"
}
# -------------------------------------------------------------------
# compressed file expander
# (from https://github.com/myfreeweb/zshuery/blob/master/zshuery.sh)
# -------------------------------------------------------------------
ex() {
if [[ -f $1 ]]; then
case $1 in
*.tar.bz2) tar xvjf $1;;
*.tar.gz) tar xvzf $1;;
*.tar.xz) tar xvJf $1;;
*.tar.lzma) tar --lzma xvf $1;;
*.bz2) bunzip $1;;
*.rar) unrar $1;;
*.gz) gunzip $1;;
*.tar) tar xvf $1;;
*.tbz2) tar xvjf $1;;
*.tgz) tar xvzf $1;;
*.zip) unzip $1;;
*.Z) uncompress $1;;
*.7z) 7z x $1;;
*.dmg) hdiutul mount $1;; # mount OS X disk images
*) echo "'$1' cannot be extracted via >ex<";;
esac
else
echo "'$1' is not a valid file"
fi
}
# -------------------------------------------------------------------
# any function from http://onethingwell.org/post/14669173541/any
# search for running processes
# -------------------------------------------------------------------
any() {
emulate -L zsh
unsetopt KSH_ARRAYS
if [[ -z "$1" ]] ; then
echo "any - grep for process(es) by keyword" >&2
echo "Usage: any " >&2 ; return 1
else
ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}"
fi
}
# -------------------------------------------------------------------
# display a neatly formatted path
# -------------------------------------------------------------------
path() {
echo $PATH | tr ":" "\n" | \
awk "{ sub(\"/usr\", \"$fg_no_bold[green]/usr$reset_color\"); \
sub(\"/bin\", \"$fg_no_bold[blue]/bin$reset_color\"); \
sub(\"/opt\", \"$fg_no_bold[cyan]/opt$reset_color\"); \
sub(\"/sbin\", \"$fg_no_bold[magenta]/sbin$reset_color\"); \
sub(\"/local\", \"$fg_no_bold[yellow]/local$reset_color\"); \
print }"
}
# -------------------------------------------------------------------
# nice mount (http://catonmat.net/blog/another-ten-one-liners-from-commandlingfu-explained)
# displays mounted drive information in a nicely formatted manner
# -------------------------------------------------------------------
function nicemount() {
(echo "DEVICE PATH TYPE FLAGS" && mount | awk '$2="";1') | column -t ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment