Last active
October 8, 2015 02:17
-
-
Save ymt2/3261811 to your computer and use it in GitHub Desktop.
zsh: directory bookmarks
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
## directory bookmarks | |
DB_HISTORY=~/.directory_bookmarks | |
function _cdb_list() { | |
local I=1 | |
while read LINE; | |
do | |
printf "%2d %s\n" ${I} ${LINE} | |
((I++)) | |
done < $DB_HISTORY | |
unset LINE | |
} | |
function cdb() { | |
local USAGE='usage: cdb [command] [bookmark number]' | |
if [ $# = 0 ] | |
then | |
_cdb_list | |
elif [ $# = 1 ] | |
then | |
case $1 in | |
add) | |
touch $DB_HISTORY | |
echo `pwd` >> $DB_HISTORY | |
;; | |
list | ls) | |
_cdb_list | |
;; | |
edit) | |
local E='vi' | |
if [[ -n $EDITOR ]] | |
then | |
E=$EDITOR | |
fi | |
$E $DB_HISTORY | |
;; | |
*) | |
expr ${1} + 1 > /dev/null 2>&1 | |
if [ $? -lt 2 ] | |
then | |
local I=1 | |
while read LINE | |
do | |
if [ ${1} -eq $I ] | |
then | |
cd $LINE | |
fi | |
((I++)) | |
done < $DB_HISTORY | |
unset LINE | |
else | |
echo $USAGE | |
return 1 | |
fi | |
;; | |
esac | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment