init.zsh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #
  2. # Utility Functions and Options
  3. #
  4. #
  5. # Colours
  6. #
  7. if (( terminfo[colors] >= 8 )); then
  8. # ls Colours
  9. if (( ${+commands[dircolors]} )); then
  10. # GNU
  11. (( ! ${+LS_COLORS} )) && if [[ -s ${HOME}/.dir_colors ]]; then
  12. eval "$(dircolors --sh ${HOME}/.dir_colors)"
  13. else
  14. export LS_COLORS='di=1;34:ln=35:so=32:pi=33:ex=31:bd=1;36:cd=1;33:su=30;41:sg=30;46:tw=30;42:ow=30;43'
  15. fi
  16. alias ls='ls --group-directories-first --color=auto'
  17. else
  18. # BSD
  19. (( ! ${+CLICOLOR} )) && export CLICOLOR=1
  20. (( ! ${+LSCOLORS} )) && export LSCOLORS='ExfxcxdxbxGxDxabagacad'
  21. # stock OpenBSD ls does not support colors at all, but colorls does.
  22. if [[ ${OSTYPE} == openbsd* && ${+commands[colorls]} -ne 0 ]]; then
  23. alias ls='colorls'
  24. fi
  25. fi
  26. # grep Colours
  27. (( ! ${+GREP_COLOR} )) && export GREP_COLOR='37;45' #BSD
  28. (( ! ${+GREP_COLORS} )) && export GREP_COLORS="mt=${GREP_COLOR}" #GNU
  29. if [[ ${OSTYPE} == openbsd* ]]; then
  30. (( ${+commands[ggrep]} )) && alias grep='ggrep --color=auto'
  31. else
  32. alias grep='grep --color=auto'
  33. fi
  34. # less Colours
  35. if [[ ${PAGER} == 'less' ]]; then
  36. (( ! ${+LESS_TERMCAP_mb} )) && export LESS_TERMCAP_mb=$'\E[1;31m' # Begins blinking.
  37. (( ! ${+LESS_TERMCAP_md} )) && export LESS_TERMCAP_md=$'\E[1;31m' # Begins bold.
  38. (( ! ${+LESS_TERMCAP_me} )) && export LESS_TERMCAP_me=$'\E[0m' # Ends mode.
  39. (( ! ${+LESS_TERMCAP_se} )) && export LESS_TERMCAP_se=$'\E[0m' # Ends standout-mode.
  40. (( ! ${+LESS_TERMCAP_so} )) && export LESS_TERMCAP_so=$'\E[7m' # Begins standout-mode.
  41. (( ! ${+LESS_TERMCAP_ue} )) && export LESS_TERMCAP_ue=$'\E[0m' # Ends underline.
  42. (( ! ${+LESS_TERMCAP_us} )) && export LESS_TERMCAP_us=$'\E[1;32m' # Begins underline.
  43. fi
  44. fi
  45. #
  46. # ls Aliases
  47. #
  48. alias ll='ls -lh' # long format and human-readable sizes
  49. alias l='ll -A' # long format, all files
  50. [[ -n ${PAGER} ]] && alias lm="l | ${PAGER}" # long format, all files, use pager
  51. alias lr='ll -R' # long format, recursive
  52. alias lk='ll -Sr' # long format, largest file size last
  53. alias lt='ll -tr' # long format, newest modification time last
  54. alias lc='lt -c' # long format, newest status change (ctime) last
  55. #
  56. # File Downloads
  57. #
  58. # order of preference: aria2c, axel, wget, curl. This order is derrived from speed based on personal tests.
  59. if (( ${+commands[aria2c]} )); then
  60. alias get='aria2c --max-connection-per-server=5 --continue'
  61. elif (( ${+commands[axel]} )); then
  62. alias get='axel --num-connections=5 --alternate'
  63. elif (( ${+commands[wget]} )); then
  64. alias get='wget --continue --progress=bar --timestamping'
  65. elif (( ${+commands[curl]} )); then
  66. alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time'
  67. fi
  68. #
  69. # Resource Usage
  70. #
  71. alias df='df -h'
  72. alias du='du -h'
  73. #
  74. # GNU only
  75. #
  76. if (( ${+commands[dircolors]} )); then
  77. alias lx='ll -X' # long format, sort by extension
  78. # Always wear a condom
  79. alias chmod='chmod --preserve-root -v'
  80. alias chown='chown --preserve-root -v'
  81. fi
  82. # not aliasing rm -i, but if safe-rm is available, use condom.
  83. # if safe-rmdir is available, the OS is suse which has its own terrible 'safe-rm' which is not what we want
  84. if (( ${+commands[safe-rm]} && ! ${+commands[safe-rmdir]} )); then
  85. alias rm='safe-rm'
  86. fi