3 ms·
Inspired by a colleague, I wrote this (for bash): https://gist.github.com/archi/2a2331401842c0548fa8de0f69796f58 https://gist.github.com/archi/2a2331401842c054
by archi42 7y ago
Inspired by a colleague, I wrote this (for bash):
https://gist.github.com/archi/2a2331401842c0548fa8de0f69796f58 https://gist.github.com/archi/2a2331401842c0548fa8de0f69796f...
> up 4
go up 4 folders (=> "cd .." 4 times).
> up
goes up one folder, and you can repeat pressing ENTER to go up one more. Press anything else to drop back to the shell.
Could probably be "better" (e.g. no subshells), but works well for me.
- RadiantSecurity 7y agoThats cool! I'm not sure where it comes from, but I get similar behavior in zsh with 'cd ....' - similar doesn't happen in bash though. I mapped 'cd' to 'c' in my bashrc, but while doing it I also mapped 'c' to execute 'ls' as the latter was basically muscle memory whenever I was using cd. The .bashrc function looks like this: c() { builtin cd "$@" && ls; }
- imglorp 7y agoHey guys, I have the same thing, but I called the command ".." (no it doesn't conflict with the directory). ".." by itself is the same as ".. 3" .. () { local arg=${1:-1}; while [ $arg -gt 0 ]; do builtin cd .. &> /dev/null; arg=$(($arg - 1)); done; }
- msoucy 7y agoMine is similar, but only does one cd command - to allow better use of `cd -` up() { local ups="." for((i=0;i<${1:-1};i++)); do ups="${ups}/.." done builtin cd "$ups" }
- anjanb 7y agoI've written aliases like cd2='cd ../..'. similarly cd3='cd ../../..' . Similarly cd4 and cd5. next time I'll think of this!