gnu-utils.plugin.zsh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # ------------------------------------------------------------------------------
  2. # FILE: gnu-utils.plugin.zsh
  3. # DESCRIPTION: oh-my-zsh plugin file.
  4. # AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com)
  5. # VERSION: 1.0.0
  6. # ------------------------------------------------------------------------------
  7. if [[ -x "${commands[gwhoami]}" ]]; then
  8. __gnu_utils() {
  9. emulate -L zsh
  10. local gcmds
  11. local gcmd
  12. local cmd
  13. local prefix
  14. # coreutils
  15. gcmds=('g[' 'gbase64' 'gbasename' 'gcat' 'gchcon' 'gchgrp' 'gchmod'
  16. 'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate'
  17. 'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand'
  18. 'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid'
  19. 'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum'
  20. 'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc'
  21. 'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd'
  22. 'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum'
  23. 'gsha256sum' 'gsha384sum' 'gsha512sum' 'gshred' 'gshuf' 'gsleep' 'gsort'
  24. 'gsplit' 'gstat' 'gstty' 'gsum' 'gsync' 'gtac' 'gtail' 'gtee' 'gtest'
  25. 'gtimeout' 'gtouch' 'gtr' 'gtrue' 'gtruncate' 'gtsort' 'gtty' 'guname'
  26. 'gunexpand' 'guniq' 'gunlink' 'guptime' 'gusers' 'gvdir' 'gwc' 'gwho'
  27. 'gwhoami' 'gyes')
  28. # Not part of coreutils, installed separately.
  29. gcmds+=('gsed' 'gtar' 'gtime')
  30. for gcmd in "${gcmds[@]}"; do
  31. #
  32. # This method allows for builtin commands to be primary but it's
  33. # lost if hash -r or rehash -f is executed. Thus, those two
  34. # functions have to be wrapped.
  35. #
  36. (( ${+commands[$gcmd]} )) && hash ${gcmd[2,-1]}=${commands[$gcmd]}
  37. #
  38. # This method generates wrapper functions.
  39. # It will override shell builtins.
  40. #
  41. # (( ${+commands[$gcmd]} )) && \
  42. # eval "function $gcmd[2,-1]() { \"${prefix}/${gcmd//"["/"\\["}\" \"\$@\"; }"
  43. #
  44. # This method is inflexible since the aliases are at risk of being
  45. # overriden resulting in the BSD coreutils being called.
  46. #
  47. # (( ${+commands[$gcmd]} )) && \
  48. # alias "$gcmd[2,-1]"="${prefix}/${gcmd//"["/"\\["}"
  49. done
  50. return 0
  51. }
  52. __gnu_utils;
  53. function hash() {
  54. if [[ "$*" =~ "-(r|f)" ]]; then
  55. builtin hash "$@"
  56. __gnu_utils
  57. else
  58. builtin hash "$@"
  59. fi
  60. }
  61. function rehash() {
  62. if [[ "$*" =~ "-f" ]]; then
  63. builtin rehash "$@"
  64. __gnu_utils
  65. else
  66. builtin rehash "$@"
  67. fi
  68. }
  69. fi