alias.zsh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #
  2. # Editor
  3. #
  4. if -exe emacs; then
  5. export EDITOR='emacs -nw'
  6. fi
  7. if -exe vim; then
  8. export EDITOR='vim'
  9. fi
  10. alias e=$EDITOR
  11. if [ -n "$EDITOR" -a -n "$SUDO_USER" -a "$UID" = 0 -a "$EDITOR[1,5]" = 'emacs' ]; then
  12. e="$EDITOR -u $SUDO_USER"
  13. fi
  14. #
  15. # Pager
  16. #
  17. if -exe vim; then
  18. export PAGER=~/.vim/bin/vimpager
  19. alias less="$PAGER"
  20. alias more="$PAGER"
  21. elif -exe less; then
  22. export PAGER=less
  23. alias more="$PAGER"
  24. elif -exe more; then
  25. export PAGER=more
  26. fi
  27. export GIT_PAGER="$PAGER"
  28. #
  29. # Common aliases / functions
  30. #
  31. alias rm='rm -i'
  32. alias mv='mv -i'
  33. alias cp='cp -i'
  34. alias vlock='clear;vlock'
  35. alias q='clear;exit'
  36. export GREP_OPTIONS="--color=auto"
  37. alias mgrep="grep -rnisH"
  38. alias rsu="sudo -E zsh"
  39. alias reloadsh="exec zsh"
  40. alias tmux="tmux -2"
  41. alias md="mkdir -p"
  42. mcd() { mkdir -p "$@" && cd "$@" }
  43. # show tar archive content
  44. ltar() { gunzip -c $1 | tar -tf - -- | $PAGER }
  45. # show zip archive content
  46. lzip() { unzip -l $1 | $PAGER }
  47. # show rar archive content
  48. lrar() { rar l $1 | $PAGER }
  49. ffi() {
  50. find -iname "$@"
  51. }
  52. #
  53. # Log viewers aliases
  54. #
  55. if -exe ccze; then
  56. alias alog="tail -n 300 -F /var/log/auth.log | ccze"
  57. alias mlog="tail -n 300 -F /var/log/mail.log | ccze"
  58. alias slog="tail -n 300 -F /var/log/syslog | ccze"
  59. alias xlog="tail -n 300 -F /var/log/Xorg.0.log | ccze"
  60. else
  61. alias alog="tail -n 300 -F /var/log/auth.log"
  62. alias mlog="tail -n 300 -F /var/log/mail.log"
  63. alias slog="tail -n 300 -F /var/log/syslog"
  64. alias xlog="tail -n 300 -F /var/log/Xorg.0.log"
  65. fi
  66. # using colortail if available (freebsd)
  67. if -exe colortail; then
  68. alias slog="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog"
  69. fi
  70. #
  71. # System tools aliases
  72. #
  73. alias df='df -h'
  74. if -exe pydf; then
  75. alias df="pydf -h"
  76. fi
  77. if -exe python; then
  78. alias httpserver="python -m SimpleHTTPServer"
  79. fi
  80. function mount() {
  81. if [ $# = 0 ]; then
  82. command mount -lv | column -t
  83. else
  84. command mount $@
  85. fi
  86. }
  87. #
  88. # Sysadmin stuff
  89. #
  90. if -exe dig ; then
  91. alias mx="dig +short MX"
  92. alias ns="dig +short NS"
  93. elif -exe host ; then
  94. alias mx="host -t MX"
  95. alias ns="host -t NS"
  96. fi
  97. alias scp_nosec="scp -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'"
  98. alias ssh_nosec="ssh -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'"
  99. # OpenSSL
  100. for i in sha512 sha256 sha1 md5 ; do
  101. ssl-cert-$i() {
  102. openssl x509 -noout -fingerprint -$i -in $1
  103. }
  104. done
  105. ssl-cert-fingerprints() {
  106. for i in sha512 sha256 sha1 md5; do
  107. ssl-cert-$i $1
  108. done
  109. }
  110. ssl-cert-info() {
  111. openssl x509 -noout -text -in $1
  112. ssl-cert-fingerprints $1
  113. }
  114. #
  115. # Devel tools aliases
  116. #
  117. DIFFTOOL=
  118. if -exe colordiff; then
  119. DIFFTOOL='colordiff'
  120. if -exe tput; then
  121. alias DIFFTOOL='colordiff -yW$(tput cols)'
  122. fi
  123. fi
  124. if [ -n "$DIFFTOOL" ]; then
  125. alias diff="$DIFFTOOL"
  126. fi
  127. udiff() {
  128. $DIFFTOOL -Naur $*
  129. }
  130. if -exe colormake; then
  131. alias make="colormake"
  132. fi
  133. #
  134. # Mssh stuff
  135. #
  136. if [ -f ~/.ssh/config ]; then
  137. hosts=($(grep '^Host [^*]' ~/.ssh/config | sed 's/Host //'))
  138. compctl -k hosts mssh
  139. fi
  140. #
  141. # Misc stuff
  142. #
  143. # Save and restore directory, based on
  144. # http://chris-lamb.co.uk/2011/07/30/optimising-directory-navigation-multiple-terminals/
  145. rcd() {
  146. cd "$(cat ~/.zsh.d/history/saved_dir)"
  147. }
  148. scd() {
  149. echo "$(pwd)" > ~/.zsh.d/history/saved_dir
  150. }