-
-
Save chanux/08c6f53472190a02b33bd49100163d93 to your computer and use it in GitHub Desktop.
Jump to a directory up the tree by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xs | |
# go to /home/chanux/down from /home/chanux/down/the/rabbithole/we/go | |
# by typing xs down | |
# you might also like za http://wp.me/p1rVu-bO | |
set matches (echo "$PWD" | grep -o "/$argv[1][^/]*/" | wc -l) | |
if test $matches -gt 1 | |
cd (echo $PWD | sed "s:/$argv[1]/.*:/:")$argv[1] | |
else if echo "$PWD" | grep -q "/$argv[1]/"; test $status -eq 0 | |
cd (echo $PWD | sed "s:$argv[1].*::")$argv[1] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xs() { | |
# For BASH and ZSH | |
if [[ "$PWD" == */$1/* ]] | |
then | |
cd ${PWD%$1*}$1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had this idea while using za today. Quickly implemented for my shell <"><
Not too shabby!
Known bug: If there are multiple directories by the same name, it'd go to the farthest