• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..21-Dec-2021-

README.mdH A D21-Dec-20213.1 KiB11791

shrink-path.plugin.zshH A D21-Dec-20217.4 KiB183172

README.md

1# shrink-path
2
3A plugin to shrink directory paths for brevity and pretty-printing.
4
5To use it, add `shrink-path` to the plugins array in your zshrc file:
6
7```zsh
8plugins=(... shrink-path)
9```
10
11## Examples
12
13For this directory tree:
14```
15/home/
16  me/
17    f o o/     # The prefix f is ambiguous between "f o o" and "f i g".
18      bar/
19        quux/
20      biz/     # The prefix b is ambiguous between bar and biz.
21    f i g/
22      baz/
23```
24here are the results of calling `shrink_path <option> /home/me/foo/bar/quux`:
25```
26Option        Result
27<none>        /h/m/f o/ba/q
28-l|--last     /h/m/f o/ba/q
29-s|--short    /h/m/f/b/q
30-t|--tilde    ~/f o/ba/q
31-f|--fish     ~/f/b/quux
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$
35-q            /h/m/f\ o/ba/q
36-g -q         /h*/m*/f\ o*/ba*/q*
37-x            /home/me/foo/bar/quux
38```
39
40## Usage
41
42For a fish-style working directory in your command prompt, add the following to
43your theme or zshrc:
44
45```zsh
46setopt prompt_subst
47PS1='%n@%m $(shrink_path -f)>'
48```
49
50The following options are available:
51
52```
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
65```
66
67The long options can also be set via zstyle, like
68```zsh
69zstyle :prompt:shrink_path fish yes
70```
71
72Note: Directory names containing two or more consecutive spaces are not yet
73supported.
74
75
76## Trick: toggle shrinking with a keyboard shortcut
77
78You can use the `expand` option to disable the path shrinking. You can combine that
79with a key binding widget to toggle path shrinking on and off.
80
81```zsh
82# Toggle off path shrinking
83zstyle ':prompt:shrink_path' expand true
84# Toggle on path shrinking
85zstyle -d ':prompt:shrink_path' expand
86```
87
88Combined with a widget:
89
90```zsh
91# Widget definition
92shrink-path-toggle() {
93  zstyle -t ':prompt:shrink_path' expand \
94    && zstyle -d ':prompt:shrink_path' expand \
95    || zstyle ':prompt:shrink_path' expand true
96  zle reset-prompt
97}
98zle -N shrink-path-toggle
99# Key binding to ALT+SHIFT+S
100bindkey "^[S" shrink-path-toggle
101```
102
103## License
104
105Copyright (C) 2008 by Daniel Friesel <derf@xxxxxxxxxxxxxxxxxx>
106Copyright (C) 2018-2020 by Pavel N. Krivitsky
107
108License: WTFPL <http://www.wtfpl.net>
109
110Ref: https://www.zsh.org/mla/workers/2009/msg00415.html
111     https://www.zsh.org/mla/workers/2009/msg00419.html
112
113
114## Misc
115
116Keywords: prompt directory truncate shrink collapse fish
117