3 A plugin to shrink directory paths for brevity and pretty-printing.
5 To use it, add `shrink-path` to the plugins array in your zshrc file:
8 plugins=(... shrink-path)
13 For this directory tree:
17 f o o/ # The prefix f is ambiguous between "f o o" and "f i g".
20 biz/ # The prefix b is ambiguous between bar and biz.
24 here are the results of calling `shrink_path <option> /home/me/foo/bar/quux`:
28 -l|--last /h/m/f o/ba/q
32 -g|--glob /h*/m*/f o*/ba*/q*
33 -3 /hom/me/f o/bar/quu
34 -e '$' -3 /hom$/me/f o$/bar/quu$
36 -g -q /h*/m*/f\ o*/ba*/q*
37 -x /home/me/foo/bar/quux
42 For a fish-style working directory in your command prompt, add the following to
47 PS1='%n@%m $(shrink_path -f)>'
50 The following options are available:
53 -f, --fish fish simulation, equivalent to -l -s -t.
54 -g, --glob Add asterisk to allow globbing of shrunk path (equivalent to -e "*")
55 -l, --last Print the last directory's full name.
56 -s, --short Truncate directory names to the number of characters given by -. Without
57 -s, names are truncated without making them ambiguous.
58 -t, --tilde Substitute ~ for the home directory.
59 -T, --nameddirs Substitute named directories as well.
60 -# Truncate each directly to at least this many characters inclusive of the
61 ellipsis character(s) (defaulting to 1).
62 -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
63 -q, --quote Quote special characters in the shrunk path
64 -x, --expand Print the full path. This takes precedence over the other options
67 The long options can also be set via zstyle, like
69 zstyle :prompt:shrink_path fish yes
72 Note: Directory names containing two or more consecutive spaces are not yet
76 ## Trick: toggle shrinking with a keyboard shortcut
78 You can use the `expand` option to disable the path shrinking. You can combine that
79 with a key binding widget to toggle path shrinking on and off.
82 # Toggle off path shrinking
83 zstyle ':prompt:shrink_path' expand true
84 # Toggle on path shrinking
85 zstyle -d ':prompt:shrink_path' expand
88 Combined with a widget:
92 shrink-path-toggle() {
93 zstyle -t ':prompt:shrink_path' expand \
94 && zstyle -d ':prompt:shrink_path' expand \
95 || zstyle ':prompt:shrink_path' expand true
98 zle -N shrink-path-toggle
99 # Key binding to ALT+SHIFT+S
100 bindkey "^[S" shrink-path-toggle
105 Copyright (C) 2008 by Daniel Friesel <derf@xxxxxxxxxxxxxxxxxx>
106 Copyright (C) 2018-2020 by Pavel N. Krivitsky
108 License: WTFPL <http://www.wtfpl.net>
110 Ref: https://www.zsh.org/mla/workers/2009/msg00415.html
111 https://www.zsh.org/mla/workers/2009/msg00419.html
116 Keywords: prompt directory truncate shrink collapse fish