From 195db6f6d92db006c811a90b2e050dc895797975 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Wed, 14 May 2014 21:51:10 -0600 Subject: [PATCH 1/3] Updates to generalized aliases --- bashmarks.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bashmarks.sh b/bashmarks.sh index 55fbddd..efd141b 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -41,8 +41,12 @@ touch $SDIRS RED="0;31m" GREEN="0;33m" +# set up prefix information +BASHMARKS_DEFAULT_PREFIX="" +BASHMARKS_PREFIX=${BASHMARKS_PREFIX:-$BASHMARKS_DEFAULT_PREFIX} + # save current directory to bookmarks -function s { +function bashmarks_s { check_help $1 _bookmark_name_valid "$@" if [ -z "$exit_message" ]; then @@ -51,9 +55,10 @@ function s { echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS fi } +alias ${BASHMARKS_PREFIX}s=bashmarks_s # jump to bookmark -function g { +function bashmarks_g { check_help $1 source $SDIRS target="$(eval $(echo echo $(echo \$DIR_$1)))" @@ -65,16 +70,18 @@ function g { echo -e "\033[${RED}WARNING: '${target}' does not exist\033[00m" fi } +alias ${BASHMARKS_PREFIX}g=bashmarks_g # print bookmark -function p { +function bashmarks_p { check_help $1 source $SDIRS echo "$(eval $(echo echo $(echo \$DIR_$1)))" } +alias ${BASHMARKS_PREFIX}p=bashmarks_p # delete bookmark -function d { +function bashmarks_d { check_help $1 _bookmark_name_valid "$@" if [ -z "$exit_message" ]; then @@ -82,6 +89,7 @@ function d { unset "DIR_$1" fi } +alias ${BASHMARKS_PREFIX}d=bashmarks_d # print out help for the forgetful function check_help { @@ -97,7 +105,7 @@ function check_help { } # list bookmarks with dirnam -function l { +function bashmarks_l { check_help $1 source $SDIRS @@ -107,11 +115,14 @@ function l { # uncomment this line if color output is not working with the line above # env | grep "^DIR_" | cut -c5- | sort |grep "^.*=" } +alias ${BASHMARKS_PREFIX}l=bashmarks_l + # list bookmarks without dirname -function _l { +function bashmarks__l { source $SDIRS env | grep "^DIR_" | cut -c5- | sort | grep "^.*=" | cut -f1 -d "=" } +alias ${BASHMARKS_PREFIX}_l=bashmarks__l # validate bookmark name function _bookmark_name_valid { From f7d8732bec8f708858eaad1c4bf9df6497eff661 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Wed, 14 May 2014 22:03:00 -0600 Subject: [PATCH 2/3] Updated README.md --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5675fd2..21bb2ef 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,28 @@ 1. git clone git://github.com/huyng/bashmarks.git 2. make install -3. source **~/.local/bin/bashmarks.sh** from within your **~.bash\_profile** or **~/.bashrc** file +3. add optional [command prefix](#command-prefix) +4. source **~/.local/bin/bashmarks.sh** from within your **~.bash\_profile** or **~/.bashrc** file + +## Command Prefix + +Because the aliases that Bashmarks uses might already be in use on your system, Bashmarks allows you +to specify a "command prefix": + +```bash +export BASHMARKS_PREFIX="bm" +``` + +If this is specified, the prefix must be used before any Bashmarks command; if it is not specified, +the aliases can be used as-is. ## Shell Commands - s - Saves the current directory as "bookmark_name" - g - Goes (cd) to the directory associated with "bookmark_name" - p - Prints the directory associated with "bookmark_name" - d - Deletes the bookmark - l - Lists all available bookmarks + s - Saves the current directory as "bookmark_name" + g - Goes (cd) to the directory associated with "bookmark_name" + p - Prints the directory associated with "bookmark_name" + d - Deletes the bookmark + l - Lists all available bookmarks ## Example Usage From b8eb35d3c1a285b6a779306f2a05b034e58a70ce Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Wed, 14 May 2014 22:07:13 -0600 Subject: [PATCH 3/3] More updates --- Makefile | 10 +++++----- bashmarks.sh | 38 +++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 17c41b5..9bfbf7f 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ install: @echo '' @echo 'USAGE:' @echo '------' - @echo 's - Saves the current directory as "bookmark_name"' - @echo 'g - Goes (cd) to the directory associated with "bookmark_name"' - @echo 'p - Prints the directory associated with "bookmark_name"' - @echo 'd - Deletes the bookmark' - @echo 'l - Lists all available bookmarks' + @echo 's - Saves the current directory as "bookmark_name"' + @echo 'g - Goes (cd) to the directory associated with "bookmark_name"' + @echo 'p - Prints the directory associated with "bookmark_name"' + @echo 'd - Deletes the bookmark' + @echo 'l - Lists all available bookmarks' diff --git a/bashmarks.sh b/bashmarks.sh index efd141b..189df0c 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -23,14 +23,14 @@ # USAGE: -# s bookmarkname - saves the curr dir as bookmarkname -# g bookmarkname - jumps to the that bookmark -# g b[TAB] - tab completion is available -# p bookmarkname - prints the bookmark -# p b[TAB] - tab completion is available -# d bookmarkname - deletes the bookmark -# d [TAB] - tab completion is available -# l - list all bookmarks +# s bookmarkname - saves the curr dir as bookmarkname +# g bookmarkname - jumps to the that bookmark +# g b[TAB] - tab completion is available +# p bookmarkname - prints the bookmark +# p b[TAB] - tab completion is available +# d bookmarkname - deletes the bookmark +# d [TAB] - tab completion is available +# l - list all bookmarks # setup file to store bookmarks if [ ! -n "$SDIRS" ]; then @@ -95,11 +95,11 @@ alias ${BASHMARKS_PREFIX}d=bashmarks_d function check_help { if [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ] ; then echo '' - echo 's - Saves the current directory as "bookmark_name"' - echo 'g - Goes (cd) to the directory associated with "bookmark_name"' - echo 'p - Prints the directory associated with "bookmark_name"' - echo 'd - Deletes the bookmark' - echo 'l - Lists all available bookmarks' + echo 's - Saves the current directory as "bookmark_name"' + echo 'g - Goes (cd) to the directory associated with "bookmark_name"' + echo 'p - Prints the directory associated with "bookmark_name"' + echo 'd - Deletes the bookmark' + echo 'l - Lists all available bookmarks' kill -SIGINT $$ fi } @@ -169,12 +169,12 @@ function _purge_line { # bind completion command for g,p,d to _comp if [ $ZSH_VERSION ]; then - compctl -K _compzsh g - compctl -K _compzsh p - compctl -K _compzsh d + compctl -K _compzsh bashmarks_g + compctl -K _compzsh bashmarks_p + compctl -K _compzsh bashmarks_d else shopt -s progcomp - complete -F _comp g - complete -F _comp p - complete -F _comp d + complete -F _comp bashmarks_g + complete -F _comp bashmarks_p + complete -F _comp bashmarks_d fi