4 ms·
Those bunch of dots aliases are a bit ridiculous. What are you gonna do, sit and count dots?
by Saint_Genet 5y ago
Those bunch of dots aliases are a bit ridiculous. What are you gonna do, sit and count dots?
- intarga 5y agoAlso made mostly redundant by shopt autocd
- approxim8ion 5y agoI keep at least 3 in my aliases. So I go up up to 3 levels, and if I need to go further I type it in again.
- aclindsa 5y agoI have a simple pair of functions which I use to go up a level based on typing the portion of the path I want to go up until: # When called as `argu string`, prints the closest ancestor directory which # contains "string". If none is found, or "string" is empty, the current # working directory is printed. This function is useful if you need to specify # a file as an argument, but the relative path to it involves moving several # directories up from the current directory. For example, instead of doing: # $ pwd # /this/is/a/very/long/directory/path/for/demonstration/purposes/ # $ ls ../../../../another/directory/something.log # You could do: # $ ls `argu dir`/another/directory/something.log argu() { if [[ "$1" == "" ]]; then echo "`pwd`/" return fi echo "`pwd | sed "s/^\(.*"$1"[^/]*\)\/.*$/\1/g"`/" } # When called as `cdu string`, changes directories into the closest ancestor # directory of the current directory which contains "string". If none is found, # or "string" is empty, no changes are made to the current directory. cdu() { cd `argu $1` } I also put the following in ~/.zsh/completion/_cdu so I can get tab-completion of the portions of the path: #compdef cdu _cdu_parents=$(pwd | tr '/' ' ') _arguments "1:parents:($_cdu_parents)" Or bash (in ~/.bash/completion/cdu): # bash completion for cdu _cdu() { local cur prev split=false COMPREPLY=() _get_comp_words_by_ref -n : cur prev _dirs=$( pwd | tr '/' ' ' ) COMPREPLY=( $( compgen -W "$_dirs" -- "$cur" ) ) } complete -F _cdu cdu # Local variables: # mode: shell-script # sh-basic-offset: 4 # sh-indent-comment: t # indent-tabs-mode: nil # End: # ex: ts=4 sw=4 et filetype=sh