_z 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #compdef zshz ${ZSHZ_CMD:-${_Z_CMD:-z}}
  2. #
  3. # Zsh-z - jump around with Zsh - A native Zsh version of z without awk, sort,
  4. # date, or sed
  5. #
  6. # https://github.com/agkozak/zsh-z
  7. #
  8. # Copyright (c) 2018-2023 Alexandros Kozak
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining a copy
  11. # of this software and associated documentation files (the "Software"), to deal
  12. # in the Software without restriction, including without limitation the rights
  13. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. # copies of the Software, and to permit persons to whom the Software is
  15. # furnished to do so, subject to the following conditions:
  16. #
  17. # The above copyright notice and this permission notice shall be included in all
  18. # copies or substantial portions of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. # SOFTWARE.
  27. #
  28. # z (https://github.com/rupa/z) is copyright (c) 2009 rupa deadwyler and
  29. # licensed under the WTFPL license, Version 2.a
  30. #
  31. # shellcheck shell=ksh
  32. ############################################################
  33. # Zsh-z COMPLETIONS
  34. ############################################################
  35. emulate -L zsh
  36. (( ZSHZ_DEBUG )) &&
  37. setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL NO_WARN_NESTED_VAR 2> /dev/null
  38. # TODO: This routine currently reproduces z's feature of allowing spaces to be
  39. # used as wildcards in completions, so that
  40. #
  41. # z us lo bi
  42. #
  43. # can expand to
  44. #
  45. # z /usr/local/bin
  46. #
  47. # but it also reproduces z's buggy display on the commandline, viz.
  48. #
  49. # z us lo /usr/local/bin
  50. #
  51. # Address.
  52. local completions expl completion
  53. local -a completion_list
  54. completions=$(zshz --complete ${(@)words:1})
  55. [[ -z $completions ]] && return 1
  56. for completion in ${(f)completions[@]}; do
  57. if (( ZSHZ_TILDE )) && [[ $completion == ${HOME}* ]]; then
  58. completion="~${(q)${completion#${HOME}}}"
  59. else
  60. completion="${(q)completion}"
  61. fi
  62. completion_list+=( $completion )
  63. done
  64. _description -V completion_list expl 'directories'
  65. if [[ $ZSHZ_COMPLETION == 'legacy' ]]; then
  66. compadd "${expl[@]}" -QU -- "${completion_list[@]}"
  67. else
  68. compadd "${expl[@]}" -QU -V zsh-z -- "${completion_list[@]}"
  69. fi
  70. compstate[insert]=menu
  71. return 0
  72. # vim: ft=zsh:fdm=indent:ts=2:et:sts=2:sw=2: