6 ms·
I have a bunch of little scripts and aliases I've written over the years, but none are used more than these... alias ..='cd ..' alias ...='cd ../..' alias ..
by revicon 11mo ago
I have a bunch of little scripts and aliases I've written over the years, but none are used more than these...
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias .......='cd ../../../../../..'
- Bishonen88 11mo agoup() { local d="" for ((i=1; i<=$1; i++)); do d="../$d" done cd "$d" } up 2, up 3 etc.
- vunderba 11mo agoDoes zsh support this out-of-the-box? Because I definitely never had to setup any of these kinds of aliases but have been using this shorthand dot notation for years.
- machomaster 11mo agoYes it does.
- Noumenon72 11mo agoNot on my Mac. zsh: permission denied: .. zsh: command not found: ...
- soraminazuki 11mo agoIt's an oh-my-zsh thing.
- tacone 11mo agoI have setup a shortcut: alt+. to run cd.., it's pretty cool. I also aliased - to run cd -
- fragmede 11mo agobut alt-. in bash is used for pasting the last argument to the previous command into the current one.
- tacone 11mo agoGood point, when working with keybindings, you'll inevitably end up overriding built-ins. I see it as a trade-off, between something I don't know of (and wouldn't use) and something I find useful. Works for me :)
- cosmos0072 11mo agoI need this *so* often that I programmed my shell to execute 'cd ..' every time I press KP/ i.e. '/' on the keypad, without having to hit Return. Other single-key bindings I use often are: KP* executes 'ls' KP- executes 'cd -' KP+ executes 'make -j `nproc`'
- sudahtigabulan 11mo agoHow? Readline macros?
- mghilardi 11mo agoLiterally with my own shell: https://github.com/cosmos72/schemesh https://github.com/cosmos72/schemesh
- pfg_ 11mo agofish lets you cd to a folder without 'cd' although you still need the slashes. I use it all the time. c $> pwd /a/b/c c $> dir1 dir1 $> .. c $> ../.. / $>
- lordgrenville 11mo agozsh also does, with `setopt autocd` https://zsh.sourceforge.io/Intro/intro_16.html https://zsh.sourceforge.io/Intro/intro_16.html
- deleted 11mo ago[deleted]
- jcgl 11mo agoIn fish, I have an abbreviation that automatically expands double dots into ../ so that you can just spam double dots and visually see how far you're going. # Modified from # https://github.com/fish-shell/fish-shell/issues/1891#issuecomment-451961517 function append-slash-to-double-dot -d 'expand .. to ../' # Get commandline up to cursor set -l cmd (commandline --cut-at-cursor) # Match last line switch $cmd[-1] case '*.' commandline --insert './' case '*' commandline --insert '.' end end
- Too 11mo agoalias cdtop=’cd $(git rev-parse --show-toplevel)’
- cb321 11mo agoI used to do this, but unary kind of sucks after 3; So maybe others might like this better before their fingers get trained: ..() { # Usage: .. [N=1] -> cd up N levels local d="" i for ((i = 0; i < ${1:-"1"}; i++)) d="$d/.." # Build up a string & do 1 cd to preserve dirstack [[ -z $d ]] || cd ./$d } Of course, what I actually have been doing since the early 90s is realize that a single "." with no-args is normally illegal and people "cd" soooo much more often than sourcing script definitions. So, I hijack that to save one "." in the first 3 cases and then take a number for the general case. # dash allows non-AlphaNumeric alias but not function names; POSIX is silent. cd1 () { if [ $# -eq 0 ]; then cd ..; else command . "$@"; fi; } # nice "cd .." alias .=cd1 cdu() { # Usage: cdu [N=2] -> cd up N levels local i=0 d="" # "." already does 1 level while [ $i -lt ${1:-"2"} ]; do d=$d/..; i=$((i+1)); done [ -z "$d" ] || cd ./$d; } alias ..=cdu alias ...='cd ../../..' # so, "."=1up, ".."=2up, "..."=3up, ".. N"=Nup and as per the comment this even works in lowly dash, but needs a slight workaround. bash can just do a .() and ..() shell function as with the zsh.