I’m horrible at waiting, so when things are slow or repetitive I tend to automate them. So when I started working on my first Java project I quickly got fed up by navigating in and out of these crazy paths. For instance moving from src/main/java/com/example/application/package/ to the test path, or back to the root of the project got boring real quick.function backto() { # Go back to folder in path local path=${PWD%/*} while [[ $path ]]; do if [[ “${path##*/}” == “$1” ]]; then cd “$path” || return 1 break else path=${path%/*} fi done } function _backto() { # completion for backto local cur dir all _get_comp_words_by_ref cur all=$(cut -c 2- <<< “${PWD%/*}” | tr ‘/’ ‘\n’) if [[ -z “$cur” ]]; then COMPREPLY=( $( compgen -W “$all”) ) else COMPREPLY=( $(grep -i “^$cur” <(echo “${all}”) | sort -u) ) fi } complete -o nospace -F _backto backto The function backto and it’s auto completion counterpart, will let me chose one of the directories in my current path to jump back to.

Source: How can I move faster around the shell? // Automate attention

Was this post helpful?