diff options
author | Aaron LI <aaronly.me@gmail.com> | 2016-01-30 16:45:56 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@gmail.com> | 2016-01-30 16:45:56 +0800 |
commit | 1a80abd95d93db9e0a3b0646bd346ee9e6a5fcd5 (patch) | |
tree | ff5b43ab61daf533239b8bfcec7cb83e1abf76c4 /_zsh/functions.zsh | |
parent | b62cedb2184891fbb480b13dae4485c375450edd (diff) | |
download | dotfiles-1a80abd95d93db9e0a3b0646bd346ee9e6a5fcd5.tar.bz2 |
Rip out the heavy oh-my-zsh ...
Credits:
[1] https://github.com/spicycode/ze-best-zsh-config
[2] Zsh Configuration from the Ground Up
http://zanshin.net/2013/02/02/zsh-configuration-from-the-ground-up/
Diffstat (limited to '_zsh/functions.zsh')
-rw-r--r-- | _zsh/functions.zsh | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/_zsh/functions.zsh b/_zsh/functions.zsh new file mode 100644 index 0000000..9b817c1 --- /dev/null +++ b/_zsh/functions.zsh @@ -0,0 +1,93 @@ +# +# zsh/functions.zsh +# + +function zsh_recompile { + autoload -U zrecompile + rm -f ~/.zsh/*.zwc + [[ -f ~/.zshrc ]] && zrecompile -p ~/.zshrc + [[ -f ~/.zshrc.zwc.old ]] && rm -f ~/.zshrc.zwc.old + + for f in ~/.zsh/**/*.zsh; do + [[ -f $f ]] && zrecompile -p $f + [[ -f $f.zwc.old ]] && rm -f $f.zwc.old + done + + [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump + [[ -f ~/.zcompdump.zwc.old ]] && rm -f ~/.zcompdump.zwc.old + + source ~/.zshrc +} + + +function extract { + echo Extracting $1 ... + if [ -f "$1" ] ; then + case "$1" in + *.tar.bz2) + tar xjf "$1";; + *.tar.gz) + tar xzf "$1";; + *.bz2) + bunzip2 "$1";; + *.rar) + unrar x "$1";; + *.gz) + gunzip "$1";; + *.tar) + tar xf "$1";; + *.tbz2) + tar xjf "$1";; + *.tgz) + tar xzf "$1";; + *.zip) + unzip "$1";; + *.Z) + uncompress "$1";; + *.7z) + 7z x "$1";; + *) + echo "'$1' cannot be extracted via extract()" ;; + esac + else + echo "'$1' is not a valid file" + fi +} + + +function trash () { + local path + for path in "$@"; do + # ignore any arguments + if [[ "${path}" = -* ]]; then + : + else + local dst="${path##*/}" + # append the time if necessary + while [ -e ~/.trash/"${dst}" ]; do + dst="${dst} "$(date +%H-%M-%S) + done + \mv "${path}" ~/.trash/"${dst}" + fi + done +} + + +function strip_diff_leading_symbols { + local color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K])" + + # simplify the unified patch diff header + sed -r "s/^($color_code_regex)diff --git .*$//g" | \ + sed -r "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \ + sed -r "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\ + # actually strips the leading symbols + sed -r "s/^($color_code_regex)[\+\-]/\1 /g" +} + + +## Print a horizontal rule +rule() { + printf "%$(tput cols)s\n" | tr ' ' '─' +} + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # |