Skip to content

Instantly share code, notes, and snippets.

@adiog
Created September 20, 2017 05:44
Show Gist options
  • Save adiog/650419b765161d71b8d0c5318461f761 to your computer and use it in GitHub Desktop.
Save adiog/650419b765161d71b8d0c5318461f761 to your computer and use it in GitHub Desktop.
bash directory bookmarks
# Copyright 2014 Aleksander Gajewski <[email protected]>
# created: Sun 26 Oct 2014 11:01:45 AM CET
# modified: Sun 26 Oct 2014 11:02:17 AM CET
# bash marks
MARKS_DIR=~/.bashmarks
MARKS_CWD=.cwd
mkdir -p $MARKS_DIR
function _l() {
ls $MARKS_DIR
}
function _m() {
pwd > $MARKS_DIR/$1
}
function m() {
[[ -z "$1" ]] && _m $MARKS_CWD
[[ -z "$1" ]] || _m $1
}
function d() {
rm $MARKS_DIR/$1
}
function l(){
echo " : $(< $MARKS_DIR/$MARKS_CWD)"
for m in `_l`; do
echo "$m: $(< $MARKS_DIR/$m)"
done
}
function g() {
[[ -z "$1" ]] && cd "$(< $MARKS_DIR/$MARKS_CWD)" && return
[[ -f "$MARKS_DIR/$1" ]] && cd "$(< $MARKS_DIR/$1)"
[[ -f "$MARKS_DIR/$1" ]] || echo "Mark $1 not set"
}
function _comp {
local curw
COMPREPLY=()
curw=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W '`_l`' -- $curw))
return 0
}
shopt -s progcomp
complete -F _comp g
complete -F _comp l
complete -F _comp d
PROMPT_COMMAND='m'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment