Agree. It's why I alias . to pwd and .. to go up a directory.
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' function up {
local ups="."
for((i=0;i<${1:-1};i++)); do
ups="${ups}/.."
done
cd "$ups"
}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. # 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.
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 ~)