Skip to content

Instantly share code, notes, and snippets.

@wataken44
Last active November 15, 2016 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wataken44/5fe3a04529667ca0ccb7c5ed75956acc to your computer and use it in GitHub Desktop.
Save wataken44/5fe3a04529667ca0ccb7c5ed75956acc to your computer and use it in GitHub Desktop.
function upto() {
if [ $# -eq 0 ]; then
cd ~
else
ptn=$(echo -n $1 | sed -e 's/\/$//g;s/\//\\\//g;')
exp='s/\(.*'$ptn'[^/]*\/\).*/\1/g'
dir=$(pwd)"/"
cd $(echo $dir | sed -e "$exp")
fi
}
function upto_completion() {
COMPREPLY=( $(compgen -W "$(pwd|sed -e 's/\// /g')" ${COMP_WORDS[COMP_CWORD]} ) )
}
complete -F upto_completion upto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment