functions.zsh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ## fixme, i duplicated this in xterms - oops
  2. function title {
  3. if [[ $TERM == "screen" ]]; then
  4. # Use these two for GNU Screen:
  5. print -nR $'\033k'$1$'\033'\\\
  6. print -nR $'\033]0;'$2$'\a'
  7. elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]]; then
  8. # Use this one instead for XTerms:
  9. print -nR $'\033]0;'$*$'\a'
  10. fi
  11. }
  12. function precmd {
  13. title zsh "$PWD"
  14. }
  15. function preexec {
  16. emulate -L zsh
  17. local -a cmd; cmd=(${(z)1})
  18. title $cmd[1]:t "$cmd[2,-1]"
  19. }
  20. function zsh_stats() {
  21. history | awk '{print $2}' | sort | uniq -c | sort -rn | head
  22. }
  23. function uninstall_oh_my_zsh() {
  24. /bin/sh $ZSH/tools/uninstall.sh
  25. }
  26. function upgrade_oh_my_zsh() {
  27. /bin/sh $ZSH/tools/upgrade.sh
  28. }
  29. function take() {
  30. mkdir -p $1
  31. cd $1
  32. }
  33. function extract() {
  34. unset REMOVE_ARCHIVE
  35. if test "$1" = "-r"; then
  36. REMOVE=1
  37. shift
  38. fi
  39. if [[ -f $1 ]]; then
  40. case $1 in
  41. *.tar.bz2) tar xvjf $1;;
  42. *.tar.gz) tar xvzf $1;;
  43. *.tar.xz) tar xvJf $1;;
  44. *.tar.lzma) tar --lzma -xvf $1;;
  45. *.bz2) bunzip $1;;
  46. *.rar) unrar $1;;
  47. *.gz) gunzip $1;;
  48. *.tar) tar xvf $1;;
  49. *.tbz2) tar xvjf $1;;
  50. *.tgz) tar xvzf $1;;
  51. *.zip) unzip $1;;
  52. *.Z) uncompress $1;;
  53. *.7z) 7z x $1;;
  54. *) echo "'$1' cannot be extracted via >extract<";;
  55. esac
  56. if [[ $REMOVE_ARCHIVE -eq 1 ]]; then
  57. echo removing "$1";
  58. /bin/rm "$1";
  59. fi
  60. else
  61. echo "'$1' is not a valid file"
  62. fi
  63. }