4 ms·
Agree. It's why I alias . to pwd and .. to go up a directory.
by arbie 9y ago
Agree. It's why I alias . to pwd and .. to go up a directory.
- jhauris 9y agothose are great, definitely adding those aliases.
- moehm 9y agoAnd "alias ...='cd ../../'" etc. Gotta love this feature.
- kbd 9y agoHere are some of what I use: alias -- -='cd -' alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias l=ls alias la='ls -a' alias ll='ls -l' alias lla='ls -la'
- msoucy 9y agoI personally have a single function that takes care of all of those dotted aliases: function up { local ups="." for((i=0;i<${1:-1};i++)); do ups="${ups}/.." done cd "$ups" }
- kbd 9y agoI appreciate the DRY-ness of it, but that requires you to type 'up ...' which is longer :( A while ago when I was bored I was thinking of golfing those aliases to say (pseudocode): for i in 2..6: alias '.'*i=cd '../'*i but I didn't know all the shell needed and just wound up leaving it as is. Edit: turns out Zsh has a 'repeat' built-in: alias $(repeat 7 echo -n '.')="cd $(repeat 7 echo -n '../')" Still, non-portable, less clear, not worth changing the aliases.
- Symbiote 9y agoI have had this in my .zshrc for years: # Quick ../../.. from https://github.com/blueyed/oh-my-zsh resolve-alias() { # Recursively resolve aliases and echo the command. typeset -a cmd cmd=(${(z)1}) while (( ${+aliases[$cmd[1]]} )) \ && [[ ${aliases[$cmd[1]]} != $cmd ]]; do cmd=(${(z)aliases[${cmd[1]}]}) done echo $cmd } rationalise-dot() { # Auto-expand "..." to "../..", "...." to "../../.." etc. # It skips certain commands (git, tig, p4). # # resolve-alias is defined in a separate function. local MATCH # keep the regex match from leaking to the environment. # Skip pasted text. if (( PENDING > 0 )); then zle self-insert return fi if [[ $LBUFFER =~ '(^|/| ||'$'\n''|\||;|&)\.\.$' ]] \ && ! [[ $(resolve-alias $LBUFFER) =~ '(git|tig|p4)' ]]; then LBUFFER+=/ zle self-insert zle self-insert else zle self-insert fi } zle -N rationalise-dot bindkey . rationalise-dot bindkey -M isearch . self-insert 2>/dev/null For doing "cd ../.." I type "cd ...", each extra "." adds a "/.." to the argument. It works for any command, cp/mv/whatever. There may be nicer versions, certainly shorter versions are there if I search "rationalise-dot" in Google.
- firethief 9y agoWhy stop there? `shopt -s autocd`
- bakul 9y agoI’ve used these aliases since I first started using csh (below syntax for zsh): alias .=cd alias ,=pushd alias ,,=popd alias ,.='dirs -v' No need to alias .. as in zsh you can use a dir name as a command to cd to it. Setting cdpath can further cut down on typing. For example cdpath=(. .. ~/go/src ~/src ~)