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.

116 lines
3.1 KiB

3 years ago
  1. # shrink-path
  2. A plugin to shrink directory paths for brevity and pretty-printing.
  3. To use it, add `shrink-path` to the plugins array in your zshrc file:
  4. ```zsh
  5. plugins=(... shrink-path)
  6. ```
  7. ## Examples
  8. For this directory tree:
  9. ```
  10. /home/
  11. me/
  12. f o o/ # The prefix f is ambiguous between "f o o" and "f i g".
  13. bar/
  14. quux/
  15. biz/ # The prefix b is ambiguous between bar and biz.
  16. f i g/
  17. baz/
  18. ```
  19. here are the results of calling `shrink_path <option> /home/me/foo/bar/quux`:
  20. ```
  21. Option Result
  22. <none> /h/m/f o/ba/q
  23. -l|--last /h/m/f o/ba/q
  24. -s|--short /h/m/f/b/q
  25. -t|--tilde ~/f o/ba/q
  26. -f|--fish ~/f/b/quux
  27. -g|--glob /h*/m*/f o*/ba*/q*
  28. -3 /hom/me/f o/bar/quu
  29. -e '$' -3 /hom$/me/f o$/bar/quu$
  30. -q /h/m/f\ o/ba/q
  31. -g -q /h*/m*/f\ o*/ba*/q*
  32. -x /home/me/foo/bar/quux
  33. ```
  34. ## Usage
  35. For a fish-style working directory in your command prompt, add the following to
  36. your theme or zshrc:
  37. ```zsh
  38. setopt prompt_subst
  39. PS1='%n@%m $(shrink_path -f)>'
  40. ```
  41. The following options are available:
  42. ```
  43. -f, --fish fish simulation, equivalent to -l -s -t.
  44. -g, --glob Add asterisk to allow globbing of shrunk path (equivalent to -e "*")
  45. -l, --last Print the last directory's full name.
  46. -s, --short Truncate directory names to the number of characters given by -. Without
  47. -s, names are truncated without making them ambiguous.
  48. -t, --tilde Substitute ~ for the home directory.
  49. -T, --nameddirs Substitute named directories as well.
  50. -# Truncate each directly to at least this many characters inclusive of the
  51. ellipsis character(s) (defaulting to 1).
  52. -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
  53. -q, --quote Quote special characters in the shrunk path
  54. -x, --expand Print the full path. This takes precedence over the other options
  55. ```
  56. The long options can also be set via zstyle, like
  57. ```zsh
  58. zstyle :prompt:shrink_path fish yes
  59. ```
  60. Note: Directory names containing two or more consecutive spaces are not yet
  61. supported.
  62. ## Trick: toggle shrinking with a keyboard shortcut
  63. You can use the `expand` option to disable the path shrinking. You can combine that
  64. with a key binding widget to toggle path shrinking on and off.
  65. ```zsh
  66. # Toggle off path shrinking
  67. zstyle ':prompt:shrink_path' expand true
  68. # Toggle on path shrinking
  69. zstyle -d ':prompt:shrink_path' expand
  70. ```
  71. Combined with a widget:
  72. ```zsh
  73. # Widget definition
  74. shrink-path-toggle() {
  75. zstyle -t ':prompt:shrink_path' expand \
  76. && zstyle -d ':prompt:shrink_path' expand \
  77. || zstyle ':prompt:shrink_path' expand true
  78. zle reset-prompt
  79. }
  80. zle -N shrink-path-toggle
  81. # Key binding to ALT+SHIFT+S
  82. bindkey "^[S" shrink-path-toggle
  83. ```
  84. ## License
  85. Copyright (C) 2008 by Daniel Friesel <derf@xxxxxxxxxxxxxxxxxx>
  86. Copyright (C) 2018-2020 by Pavel N. Krivitsky
  87. License: WTFPL <http://www.wtfpl.net>
  88. Ref: https://www.zsh.org/mla/workers/2009/msg00415.html
  89. https://www.zsh.org/mla/workers/2009/msg00419.html
  90. ## Misc
  91. Keywords: prompt directory truncate shrink collapse fish