How can I move faster around the shell? 

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

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.