my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.6 KiB

3 years ago
  1. #compdef wd
  2. zstyle ':completion::complete:wd:*:descriptions' format '%B%d%b'
  3. zstyle ':completion::complete:wd:*:commands' group-name commands
  4. zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
  5. zstyle ':completion::complete:wd::' list-grouped
  6. zmodload zsh/mapfile
  7. function _wd() {
  8. local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
  9. local ret=1
  10. local -a commands
  11. local -a warp_points
  12. warp_points=( "${(f)mapfile[$WD_CONFIG]//$HOME/~}" )
  13. typeset -A points
  14. while read -r line
  15. do
  16. arr=(${(s,:,)line})
  17. name=${arr[1]}
  18. target_path=${arr[2]}
  19. # replace ~ from path to fix completion (#17)
  20. target_path=${target_path/#\~/$HOME}
  21. points[$name]=$target_path
  22. done < $WD_CONFIG
  23. commands=(
  24. 'add:Adds the current working directory to your warp points'
  25. 'add!:Overwrites existing warp point'
  26. 'export:Export warp points as static named directories'
  27. 'rm:Removes the given warp point'
  28. 'list:Outputs all stored warp points'
  29. 'ls:Show files from given warp point'
  30. 'path:Show path to given warp point'
  31. 'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
  32. 'help:Show this extremely helpful text'
  33. 'clean:Remove points warping to nonexistent directories'
  34. 'clean!:Remove nonexistent directories without confirmation'
  35. '..:Go back to last directory'
  36. )
  37. _arguments -C \
  38. '1: :->first_arg' \
  39. '2: :->second_arg' && ret=0
  40. local target=$words[2]
  41. case $state in
  42. first_arg)
  43. _describe -t warp_points "Warp points" warp_points && ret=0
  44. _describe -t commands "Commands" commands && ret=0
  45. ;;
  46. second_arg)
  47. case $target in
  48. add\!|rm)
  49. _describe -t points "Warp points" warp_points && ret=0
  50. ;;
  51. add)
  52. _message 'Write the name of your warp point' && ret=0
  53. ;;
  54. show)
  55. _describe -t points "Warp points" warp_points && ret=0
  56. ;;
  57. ls)
  58. _describe -t points "Warp points" warp_points && ret=0
  59. ;;
  60. path)
  61. _describe -t points "Warp points" warp_points && ret=0
  62. ;;
  63. *)
  64. if [[ -v points[$target] ]]; then
  65. # complete sub directories from the warp point
  66. _path_files -W "(${points[$target]})" -/ && ret=0
  67. fi
  68. # don't complete anything if warp point is not valid
  69. ;;
  70. esac
  71. ;;
  72. esac
  73. return $ret
  74. }
  75. _wd "$@"
  76. # Local Variables:
  77. # mode: Shell-Script
  78. # sh-indentation: 2
  79. # indent-tabs-mode: nil
  80. # sh-basic-offset: 2
  81. # End:
  82. # vim: ft=zsh sw=2 ts=2 et