1bda62dffadf175091fe144cb423db348e3029df
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/shrink-path/README.md b/plugins/shrink-path/README.md
2index 33dc3f8ae2a288b483311dde905019058b9e3f54..71a242b2cd7776de73057c2e8b4b35acb0620658 100644
3--- a/plugins/shrink-path/README.md
4+++ b/plugins/shrink-path/README.md
5@@ -1,43 +1,50 @@
6-# A plugin to shrink directory paths for brevity and pretty-printing
7+# shrink-path
8
9+A plugin to shrink directory paths for brevity and pretty-printing.
10+
11+To use it, add `shrink-path` to the plugins array in your zshrc file:
12+
13+```zsh
14+plugins=(... shrink-path)
15+```
16
17 ## Examples
18
19 For this directory tree:
20 ```
21- /home/
22- me/
23- f o o/ # The prefix f is ambiguous between "f o o" and "f i g".
24- bar/
25- quux/
26- biz/ # The prefix b is ambiguous between bar and biz.
27- f i g/
28- baz/
29+/home/
30+ me/
31+ f o o/ # The prefix f is ambiguous between "f o o" and "f i g".
32+ bar/
33+ quux/
34+ biz/ # The prefix b is ambiguous between bar and biz.
35+ f i g/
36+ baz/
37 ```
38 here are the results of calling `shrink_path <option> /home/me/foo/bar/quux`:
39 ```
40- Option Result
41- <none> /h/m/f o/ba/q
42- -l|--last /h/m/f o/ba/q
43- -s|--short /h/m/f/b/q
44- -t|--tilde ~/f o/ba/q
45- -f|--fish ~/f/b/quux
46- -g|--glob /h*/m*/f o*/ba*/q*
47- -3 /hom/me/f o/bar/quu
48- -e '$' -3 /hom$/me/f o$/bar/quu$
49- -q /h/m/f\ o/ba/q
50- -g -q /h*/m*/f\ o*/ba*/q*
51+Option Result
52+<none> /h/m/f o/ba/q
53+-l|--last /h/m/f o/ba/q
54+-s|--short /h/m/f/b/q
55+-t|--tilde ~/f o/ba/q
56+-f|--fish ~/f/b/quux
57+-g|--glob /h*/m*/f o*/ba*/q*
58+-3 /hom/me/f o/bar/quu
59+-e '$' -3 /hom$/me/f o$/bar/quu$
60+-q /h/m/f\ o/ba/q
61+-g -q /h*/m*/f\ o*/ba*/q*
62+-x /home/me/foo/bar/quux
63 ```
64
65-
66 ## Usage
67
68 For a fish-style working directory in your command prompt, add the following to
69 your theme or zshrc:
70
71-```
72- setopt prompt_subst
73- PS1='%n@%m $(shrink_path -f)>'
74+```zsh
75+setopt prompt_subst
76+PS1='%n@%m $(shrink_path -f)>'
77 ```
78
79 The following options are available:
80@@ -54,17 +61,45 @@ The following options are available:
81 ellipsis character(s) (defaulting to 1).
82 -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
83 -q, --quote Quote special characters in the shrunk path
84+ -x, --expand Print the full path. This takes precedence over the other options
85 ```
86
87 The long options can also be set via zstyle, like
88-```
89- zstyle :prompt:shrink_path fish yes
90+```zsh
91+zstyle :prompt:shrink_path fish yes
92 ```
93
94 Note: Directory names containing two or more consecutive spaces are not yet
95 supported.
96
97
98+## Trick: toggle shrinking with a keyboard shortcut
99+
100+You can use the `expand` option to disable the path shrinking. You can combine that
101+with a key binding widget to toggle path shrinking on and off.
102+
103+```zsh
104+# Toggle off path shrinking
105diff --git a/plugins/shrink-path/shrink-path.plugin.zsh b/plugins/shrink-path/shrink-path.plugin.zsh
106index f0ed6513839dbb53b1611b3cf0d39017a0cbc2cf..373fd5b054289c4fd3523afbc5188148a8ca1108 100644
107--- a/plugins/shrink-path/shrink-path.plugin.zsh
108+++ b/plugins/shrink-path/shrink-path.plugin.zsh
109@@ -45,6 +45,7 @@ shrink_path () {
110 typeset -i length=1
111 typeset ellipsis=""
112 typeset -i quote=0
113+ typeset -i expand=0
114
115 if zstyle -t ':prompt:shrink_path' fish; then
116 lastfull=1
117@@ -60,6 +61,7 @@ shrink_path () {
118 zstyle -t ':prompt:shrink_path' tilde && tilde=1
119 zstyle -t ':prompt:shrink_path' glob && ellipsis='*'
120 zstyle -t ':prompt:shrink_path' quote && quote=1
121+ zstyle -t ':prompt:shrink_path' expand && expand=1
122
123 while [[ $1 == -* ]]; do
124 case $1 in
125@@ -85,6 +87,8 @@ shrink_path () {
126 print ' ellipsis character(s) (defaulting to 1).'
127 print ' -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.'
128 print ' -q, --quote Quote special characters in the shrunk path'
129+ print ' -x, --expand Print the full path. This takes precedence over the other options'
130+ print ''
131 print 'The long options can also be set via zstyle, like'
132 print ' zstyle :prompt:shrink_path fish yes'
133 return 0
134@@ -109,6 +113,9 @@ shrink_path () {
135 -q|--quote)
136 quote=1
137 ;;
138+ -x|--expand)
139+ expand=1
140+ ;;
141 esac
142 shift
143 done
144@@ -120,6 +127,11 @@ shrink_path () {
145
146 [[ -d $dir ]] || return 0
147
148+ if (( expand )) {
149+ echo "$dir"
150+ return 0
151+ }
152+
153 if (( named )) {
154 for part in ${(k)nameddirs}; {
155 [[ $dir == ${nameddirs[$part]}(/*|) ]] && dir=${dir/#${nameddirs[$part]}/\~$part}