From 84b7e161c8bca16ad252eabe3663a39c52e2fe19 Mon Sep 17 00:00:00 2001 From: friday-james Date: Sun, 25 Sep 2022 22:12:54 -0700 Subject: [PATCH 1/2] Compatible with files --- bashmarks.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/bashmarks.sh b/bashmarks.sh index b77a8c1..657d863 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -48,17 +48,28 @@ function s { if [ -z "$exit_message" ]; then _purge_line "$SDIRS" "export DIR_$1=" CURDIR=$(echo $PWD| sed "s#^$HOME#\$HOME#g") - echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS + if [ -z "$2" ]; then + echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS + else + if [ -f "$2" ]; then + CURDIR="${CURDIR}/$2" + echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS + else + echo "File doesn't exist" + fi + fi fi } # jump to bookmark -function g { +function c { check_help $1 source $SDIRS target="$(eval $(echo echo $(echo \$DIR_$1)))" if [ -d "$target" ]; then cd "$target" + elif [ -f "$target" ]; then + vim "$target" elif [ ! -n "$target" ]; then echo -e "\033[${RED}WARNING: '${1}' bashmark does not exist\033[00m" else @@ -85,11 +96,12 @@ function d { # print out help for the forgetful function check_help { - if [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ] ; then + if [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ] || [ -z "$1" ]; then + echo 'Remember to add "source ~/.local/bin/bashmarks.sh" to your .bashrc file' 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 's - Saves the current directory or file as "bookmark_name"' + echo 'g - Goes (cd) to the directory or open the file associated with "bookmark_name"' + echo 'p - Prints the directory or file associated with "bookmark_name"' echo 'd - Deletes the bookmark' echo 'l - Lists all available bookmarks' kill -SIGINT $$ From e8352fb198542066ffdb4d1a8a7d4caa1160b0a6 Mon Sep 17 00:00:00 2001 From: friday-james Date: Sun, 25 Sep 2022 22:14:40 -0700 Subject: [PATCH 2/2] Use default key mapping --- bashmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bashmarks.sh b/bashmarks.sh index 657d863..2d0ec7a 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -62,7 +62,7 @@ function s { } # jump to bookmark -function c { +function g { check_help $1 source $SDIRS target="$(eval $(echo echo $(echo \$DIR_$1)))"