4 ms·
Instead of creating aliases for .., I use this: function ..() { for i in $(seq 1 $1); do cd ..; done } which enables .. # up 1 dir .. 2 # u
by sandreas 5y ago
Instead of creating aliases for .., I use this:
function ..() {
for i in $(seq 1 $1); do cd ..; done
}
which enables
.. # up 1 dir
.. 2 # up 2 dirs
.. 42 # up 42 dirs
Here are some more: https://pilabor.com/blog/2021/03/unix-shell-tricks/ https://pilabor.com/blog/2021/03/unix-shell-tricks/
- aidos 5y agoClever. Never seen that idea before.
- LilBytes 5y agoThat's amazing.
- ozym4nd145 5y agoThis might be a better alternate to preserve functionality of `cd -` function ..() { cd $(printf '../%.0s' $(seq 1 $1)) }
- sandreas 5y agoMmh, what do you mean with "preserve"...? `cd -` works like a charm for me.
- makeworld 5y ago"cd -" changes to the previous working directory. Your function calls cd multiple times, so calling "cd -" won't bring the user to the previous working directory they expect. ozym4nd145's function only calls cd once.
- sandreas 5y agoAah, now I see. Awesome, I'll try that out. Thank you.
- vbernat 5y agoWith Zsh, I am using: # Expand ... to ../.. function vbe-expand-dot-to-parent-directory-path() { case $LBUFFER in (./..|* ./..) LBUFFER+='.' ;; # In Go: "go list ./..." (..|*[ /=]..) LBUFFER+='/..' ;; (*) LBUFFER+='.' ;; esac } zle -N vbe-expand-dot-to-parent-directory-path bindkey "." vbe-expand-dot-to-parent-directory-path bindkey -M isearch "." self-insert
- sandreas 5y agoWow, this is complex... but interesting, thank you :-) I use zsh, too.
- ajitid 5y agoI made a slightly different thing: If you are on /home/user/projects/app/src/handlers/ and you want to go to `app/`, you'll do: > up src Or give name of any other child folder/file of `app/`. So if `.git` exists in `app/`, > up .git would work too. I made it for Fish shell: https://gist.github.com/ajitid/81a4993be410586c038f8b3fc140b1c7 https://gist.github.com/ajitid/81a4993be410586c038f8b3fc140b...