Created
August 24, 2018 10:16
-
-
Save sathishvj/a0c02b892bb495eb3c1c593d4672e071 to your computer and use it in GitHub Desktop.
Bash script to go back up to any dir in path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A very useful (and very much used) bash script I found recently to go back up to any dir in the current path. Supports autocomplete also which is awesome. | |
# go back up to a directory - https://unix.stackexchange.com/questions/14303/bash-cd-up-until-in-certain-folder | |
function up() | |
{ | |
if [ -z "$1" ]; then | |
return | |
fi | |
local upto=$1 | |
cd "${PWD/\/$upto\/*//$upto}" | |
} | |
# command line autocomplete | |
function _up() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local d=${PWD//\//\ } | |
COMPREPLY=( $( compgen -W "$d" -- "$cur" ) ) | |
} | |
complete -F _up up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment