Last active
September 12, 2017 14:46
-
-
Save Semmu/3e4f3cba3a89ba02d34bc3e9300d9596 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# | |
# SIMPLE FILESYSTEM BOOKMARK MANAGEMENT | |
# | |
# usage: | |
# - create a bookmark for your current working directory with `bkmrk $NAME` | |
# - cd to any of your bookmarks with `jump $NAME` | |
# - list your bookmarks and their destinations with `lsbkmrks` | |
# - remove any of your bookmarks with `rmbkmrk $NAME` | |
# | |
# autocompletition for `jump` and `rmbkmrk` works | |
# | |
function bkmrk { | |
if [ ! -d ~/bkmrks ]; then | |
mkdir ~/bkmrks | |
fi | |
if ! [[ $1 =~ ^[a-zA-Z0-9._-]+$ ]]; then | |
echo "Invalid bookmark name." >&2 | |
return 1 | |
else | |
echo `pwd` > ~/bkmrks/$1 | |
fi | |
_refresh_bkmrk_autocompl | |
} | |
function rmbkmrk { | |
if [ ! -f ~/bkmrks/$1 ]; then | |
echo "No bookmark with this name." >&2 | |
return 1 | |
else | |
rm -f ~/bkmrks/$1 | |
fi | |
_refresh_bkmrk_autocompl | |
} | |
function lsbkmrks { | |
FILE=`mktemp` | |
for BKMRK in ~/bkmrks/* | |
do | |
echo `basename $BKMRK` `cat $BKMRK` >> $FILE | |
done | |
sort $FILE -o $FILE | |
sed -i '1s/^/NAME LOCATION\n---- --------\n/' $FILE | |
column -t -s' ' $FILE | |
rm -f $FILE | |
} | |
function jump { | |
if [ ! -f ~/bkmrks/$1 ]; then | |
echo "No bookmark with this name." >&2 | |
return 1 | |
else | |
cd `cat ~/bkmrks/$1` | |
fi | |
} | |
function _refresh_bkmrk_autocompl { | |
complete -W "`find ~/bkmrks -type f -printf "%f " 2>/dev/null`" jump | |
complete -W "`find ~/bkmrks -type f -printf "%f " 2>/dev/null`" rmbkmrk | |
} | |
_refresh_bkmrk_autocompl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment