parent
9539341e1e
commit
ec75b50ad9
@ -0,0 +1,18 @@
|
||||
# bd
|
||||
Jump back to a specific directory, without doing `cd ../../..`
|
||||
|
||||
This is simply [bd](https://github.com/Tarrasch/zsh-bd) ported to a prezto module.
|
||||
|
||||
For further information, e.g. a usage animation, I refer to the [original repository](https://github.com/Tarrasch/zsh-bd).
|
||||
|
||||
## Usage
|
||||
```zsh
|
||||
$ mkdir -p a/b/c/d
|
||||
$ cd a/b/c/d
|
||||
$ bd b
|
||||
$ ls
|
||||
c
|
||||
```
|
||||
|
||||
## Acknowledgements
|
||||
Thanks to [@Tarrasch](https://github.com/Tarrasch) for the zsh implementation of bd!
|
@ -0,0 +1,40 @@
|
||||
bd () {
|
||||
(($#<1)) && {
|
||||
print -- "usage: $0 <name-of-any-parent-directory>"
|
||||
return 1
|
||||
} >&2
|
||||
# Get parents (in reverse order)
|
||||
local parents
|
||||
local num=${#${(ps:/:)${PWD}}}
|
||||
local i
|
||||
for i in {$((num+1))..2}
|
||||
do
|
||||
parents=($parents "`echo $PWD | cut -d'/' -f$i`")
|
||||
done
|
||||
parents=($parents "/")
|
||||
# Build dest and 'cd' to it
|
||||
local dest="./"
|
||||
local parent
|
||||
foreach parent (${parents})
|
||||
do
|
||||
if [[ $1 == $parent ]]
|
||||
then
|
||||
cd $dest
|
||||
return 0
|
||||
fi
|
||||
dest+="../"
|
||||
done
|
||||
print -- "bd: Error: No parent directory named '$1'"
|
||||
return 1
|
||||
}
|
||||
_bd () {
|
||||
# Get parents (in reverse order)
|
||||
local num=${#${(ps:/:)${PWD}}}
|
||||
local i
|
||||
for i in {$((num+1))..2}
|
||||
do
|
||||
reply=($reply "`echo $PWD | cut -d'/' -f$i`")
|
||||
done
|
||||
reply=($reply "/")
|
||||
}
|
||||
compctl -V directories -K _bd bd
|
Loading…
Reference in new issue