4 ms·
"cd -" and also using "cd" with no arguments to get back to $HOME are great tips. I also have a bash function called "up" to get back N directories up the hiera
by minimax 13y ago
"cd -" and also using "cd" with no arguments to get back to $HOME are great tips. I also have a bash function called "up" to get back N directories up the hierarchy so I can do "up 5" which is like "cd ../../../../.." but much easier to type.
up () {
if [[ $# -eq 1 && "$1" -gt 0 ]] ; then
local i d
for (( i = 0; i < $1; i++ )) ; do d="../$d" ; done
cd $d
else
echo "Usage: up N"
fi
}
- amboar 13y agoI'm on my phone at the moment, but I did something similar except avoided the counting. I have a shell function called `ct` for "climb tree" where you specify the name of the directory you want to climb to; calling it will place you in the first directory above cwd whose name matches the argument and in addition I wrote a bash completion module for it so I only have to type minimal characters. I'll post the source for both shortly.
- amboar 13y agoHere's the script for ct: http://pastebin.com/M1k1WL88 http://pastebin.com/M1k1WL88 Looks like I wrote the tab-completion script on my work machine. I don't have access to it right now, but if I remember when I do have access I'll pastebin that as well.
- ImprovedSilence 13y agoI like this concept. My solution has been to use '..' '...' and '....' to go up 1,2,and 3 directories.
- jaseemabid 13y agooh-my-zsh does this out of the box.
- vram22 13y agoYour function called "up" reminds me of long-ago-used Novell Netware version, in which, IIRC, you could do: cd .. # to go one level up cd ... # to go two levels up (note: 3 dots, not 4, makes sense when you think of "cd ." and "cd ..") # and so on.