Skip to content

Instantly share code, notes, and snippets.

@WeponX
Last active March 8, 2017 02:39
Show Gist options
  • Select an option

  • Save WeponX/3e65d567e8a8374d388abf2f39318ccf to your computer and use it in GitHub Desktop.

Select an option

Save WeponX/3e65d567e8a8374d388abf2f39318ccf to your computer and use it in GitHub Desktop.
Ubuntu dir change script
export MARKPATH=$HOME/.marks
export MARKDEFAULT=gavin#设置你的默认书签,可以直接输入g跳转
function g {
local m=$1
if [ "$m" = "" ]; then m=$MARKDEFAULT; fi
cd -P "$MARKPATH/$m" 2>/dev/null || echo "No such mark: $m"
}
function mark {
mkdir -p "$MARKPATH"
local m=$1
if [ "$m" = "" ]; then m=$MARKDEFAULT; fi
rm -f "$MARKPATH/$m"
ln -s "$(pwd)" "$MARKPATH/$m"
}
function unmark {
local m=$1
if [ "$m" = "" ]; then m=$MARKDEFAULT; fi
rm -i "$MARKPATH/$m"
}
function gs {
ls -l "$MARKPATH" | grep ^l | cut -d ' ' -f 10-
}
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(ls -l "$MARKPATH" | grep ^l | cut -d ' ' -f 10)
COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
return 0
}
complete -F _completemarks g unmark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment