Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
1bda62df
Unverified
Commit
1bda62df
authored
May 21, 2021
by
Marc Cornellà
Committed by
GitHub
May 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(shrink-path): add ability to toggle off path shrinking (#9794)
parent
d646884a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
26 deletions
+73
-26
README.md
plugins/shrink-path/README.md
+61
-26
shrink-path.plugin.zsh
plugins/shrink-path/shrink-path.plugin.zsh
+12
-0
No files found.
plugins/shrink-path/README.md
View file @
1bda62df
#
A plugin to shrink directory paths for brevity and pretty-printing
#
shrink-path
A plugin to shrink directory paths for brevity and pretty-printing.
To use it, add
`shrink-path`
to the plugins array in your zshrc file:
```
zsh
plugins
=(
... shrink-path
)
```
## Examples
## Examples
For this directory tree:
For this directory tree:
```
```
/home/
/home/
me/
me/
f o o/ # The prefix f is ambiguous between "f o o" and "f i g".
f o o/ # The prefix f is ambiguous between "f o o" and "f i g".
bar/
bar/
quux/
quux/
biz/ # The prefix b is ambiguous between bar and biz.
biz/ # The prefix b is ambiguous between bar and biz.
f i g/
f i g/
baz/
baz/
```
```
here are the results of calling
`shrink_path <option> /home/me/foo/bar/quux`
:
here are the results of calling
`shrink_path <option> /home/me/foo/bar/quux`
:
```
```
Option Result
Option Result
<none> /h/m/f o/ba/q
<none> /h/m/f o/ba/q
-l|--last /h/m/f o/ba/q
-l|--last /h/m/f o/ba/q
-s|--short /h/m/f/b/q
-s|--short /h/m/f/b/q
-t|--tilde ~/f o/ba/q
-t|--tilde ~/f o/ba/q
-f|--fish ~/f/b/quux
-f|--fish ~/f/b/quux
-g|--glob /h*/m*/f o*/ba*/q*
-g|--glob /h*/m*/f o*/ba*/q*
-3 /hom/me/f o/bar/quu
-3 /hom/me/f o/bar/quu
-e '$' -3 /hom$/me/f o$/bar/quu$
-e '$' -3 /hom$/me/f o$/bar/quu$
-q /h/m/f\ o/ba/q
-q /h/m/f\ o/ba/q
-g -q /h*/m*/f\ o*/ba*/q*
-g -q /h*/m*/f\ o*/ba*/q*
-x /home/me/foo/bar/quux
```
```
## Usage
## Usage
For a fish-style working directory in your command prompt, add the following to
For a fish-style working directory in your command prompt, add the following to
your theme or zshrc:
your theme or zshrc:
```
```
zsh
setopt prompt_subst
setopt prompt_subst
PS1='%n@%m $(shrink_path -f)>'
PS1
=
'%n@%m $(shrink_path -f)>'
```
```
The following options are available:
The following options are available:
...
@@ -54,17 +61,45 @@ The following options are available:
...
@@ -54,17 +61,45 @@ The following options are available:
ellipsis character(s) (defaulting to 1).
ellipsis character(s) (defaulting to 1).
-e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
-e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.
-q, --quote Quote special characters in the shrunk path
-q, --quote Quote special characters in the shrunk path
-x, --expand Print the full path. This takes precedence over the other options
```
```
The long options can also be set via zstyle, like
The long options can also be set via zstyle, like
```
```
zsh
zstyle :prompt:shrink_path fish yes
zstyle :prompt:shrink_path fish
yes
```
```
Note: Directory names containing two or more consecutive spaces are not yet
Note: Directory names containing two or more consecutive spaces are not yet
supported.
supported.
## Trick: toggle shrinking with a keyboard shortcut
You can use the
`expand`
option to disable the path shrinking. You can combine that
with a key binding widget to toggle path shrinking on and off.
```
zsh
# Toggle off path shrinking
zstyle
':prompt:shrink_path'
expand true
# Toggle on path shrinking
zstyle
-d
':prompt:shrink_path'
expand
```
Combined with a widget:
```
zsh
# Widget definition
shrink-path-toggle
()
{
zstyle
-t
':prompt:shrink_path'
expand
\
&&
zstyle
-d
':prompt:shrink_path'
expand
\
||
zstyle
':prompt:shrink_path'
expand true
zle reset-prompt
}
zle
-N
shrink-path-toggle
# Key binding to ALT+SHIFT+S
bindkey
"^[S"
shrink-path-toggle
```
## License
## License
Copyright (C) 2008 by Daniel Friesel
<derf
@
xxxxxxxxxxxxxxxxxx
>
Copyright (C) 2008 by Daniel Friesel
<derf
@
xxxxxxxxxxxxxxxxxx
>
...
...
plugins/shrink-path/shrink-path.plugin.zsh
View file @
1bda62df
...
@@ -45,6 +45,7 @@ shrink_path () {
...
@@ -45,6 +45,7 @@ shrink_path () {
typeset
-i
length
=
1
typeset
-i
length
=
1
typeset
ellipsis
=
""
typeset
ellipsis
=
""
typeset
-i
quote
=
0
typeset
-i
quote
=
0
typeset
-i
expand
=
0
if
zstyle
-t
':prompt:shrink_path'
fish
;
then
if
zstyle
-t
':prompt:shrink_path'
fish
;
then
lastfull
=
1
lastfull
=
1
...
@@ -60,6 +61,7 @@ shrink_path () {
...
@@ -60,6 +61,7 @@ shrink_path () {
zstyle
-t
':prompt:shrink_path'
tilde
&&
tilde
=
1
zstyle
-t
':prompt:shrink_path'
tilde
&&
tilde
=
1
zstyle
-t
':prompt:shrink_path'
glob
&&
ellipsis
=
'*'
zstyle
-t
':prompt:shrink_path'
glob
&&
ellipsis
=
'*'
zstyle
-t
':prompt:shrink_path'
quote
&&
quote
=
1
zstyle
-t
':prompt:shrink_path'
quote
&&
quote
=
1
zstyle
-t
':prompt:shrink_path'
expand
&&
expand
=
1
while
[[
$1
==
-
*
]]
;
do
while
[[
$1
==
-
*
]]
;
do
case
$1
in
case
$1
in
...
@@ -85,6 +87,8 @@ shrink_path () {
...
@@ -85,6 +87,8 @@ shrink_path () {
print
' ellipsis character(s) (defaulting to 1).'
print
' ellipsis character(s) (defaulting to 1).'
print
' -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.'
print
' -e SYMBOL Postfix symbol(s) to indicate that a directory name had been truncated.'
print
' -q, --quote Quote special characters in the shrunk path'
print
' -q, --quote Quote special characters in the shrunk path'
print
' -x, --expand Print the full path. This takes precedence over the other options'
print
''
print
'The long options can also be set via zstyle, like'
print
'The long options can also be set via zstyle, like'
print
' zstyle :prompt:shrink_path fish yes'
print
' zstyle :prompt:shrink_path fish yes'
return
0
return
0
...
@@ -109,6 +113,9 @@ shrink_path () {
...
@@ -109,6 +113,9 @@ shrink_path () {
-q
|
--quote
)
-q
|
--quote
)
quote
=
1
quote
=
1
;;
;;
-x
|
--expand
)
expand
=
1
;;
esac
esac
shift
shift
done
done
...
@@ -120,6 +127,11 @@ shrink_path () {
...
@@ -120,6 +127,11 @@ shrink_path () {
[[
-d
$dir
]]
||
return
0
[[
-d
$dir
]]
||
return
0
if
((
expand
))
{
echo
"
$dir
"
return
0
}
if
((
named
))
{
if
((
named
))
{
for
part
in
${
(k)nameddirs
}
;
{
for
part
in
${
(k)nameddirs
}
;
{
[[
$dir
==
${
nameddirs
[
$part
]
}
(
/
*
|
)
]]
&&
dir
=
${
dir
/#
${
nameddirs
[
$part
]
}
/\~
$part
}
[[
$dir
==
${
nameddirs
[
$part
]
}
(
/
*
|
)
]]
&&
dir
=
${
dir
/#
${
nameddirs
[
$part
]
}
/\~
$part
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment