gnu-utils.plugin.zsh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # findutils
  29. gcmds+=('gfind' 'gxargs' 'glocate')
  30. # Not part of either coreutils or findutils, installed separately.
  31. gcmds+=('gsed' 'gtar' 'gtime')
  32. for gcmd in "${gcmds[@]}"; do
  33. #
  34. # This method allows for builtin commands to be primary but it's
  35. # lost if hash -r or rehash -f is executed. Thus, those two
  36. # functions have to be wrapped.
  37. #
  38. (( ${+commands[$gcmd]} )) && hash ${gcmd[2,-1]}=${commands[$gcmd]}
  39. #
  40. # This method generates wrapper functions.
  41. # It will override shell builtins.
  42. #
  43. # (( ${+commands[$gcmd]} )) && \
  44. # eval "function $gcmd[2,-1]() { \"${prefix}/${gcmd//"["/"\\["}\" \"\$@\"; }"
  45. #
  46. # This method is inflexible since the aliases are at risk of being
  47. # overridden resulting in the BSD coreutils being called.
  48. #
  49. # (( ${+commands[$gcmd]} )) && \
  50. # alias "$gcmd[2,-1]"="${prefix}/${gcmd//"["/"\\["}"
  51. done
  52. return 0
  53. }
  54. __gnu_utils;
  55. function hash() {
  56. if [[ "$*" =~ "-(r|f)" ]]; then
  57. builtin hash "$@"
  58. __gnu_utils
  59. else
  60. builtin hash "$@"
  61. fi
  62. }
  63. function rehash() {
  64. if [[ "$*" =~ "-f" ]]; then
  65. builtin rehash "$@"
  66. __gnu_utils
  67. else
  68. builtin rehash "$@"
  69. fi
  70. }
  71. fi