Skip to content

Commit 4247522

Browse files
author
huyng
committed
Merge pull request huyng#29 from daveharris/master
Added 'Moving to <target>' and '<target> does not exist' messages when using g
2 parents 227ae63 + 6c3ee80 commit 4247522

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bashmarks.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ if [ ! -n "$SDIRS" ]; then
3838
fi
3939
touch $SDIRS
4040

41+
RED="0;31m"
42+
GREEN="0;33m"
43+
4144
# save current directory to bookmarks
4245
function s {
4346
check_help $1
@@ -53,7 +56,13 @@ function s {
5356
function g {
5457
check_help $1
5558
source $SDIRS
56-
cd "$(eval $(echo echo $(echo \$DIR_$1)))"
59+
target="$(eval $(echo echo $(echo \$DIR_$1)))"
60+
if [ -n "$target" ]; then
61+
echo -e "\033[${GREEN}Moving to ${target}\033[00m"
62+
cd "$target"
63+
else
64+
echo -e "\033[${RED}${1} does not exist\033[00m"
65+
fi
5766
}
5867

5968
# print bookmark
@@ -92,7 +101,7 @@ function l {
92101
source $SDIRS
93102

94103
# if color output is not working for you, comment out the line below '\033[1;32m' == "red"
95-
env | sort | awk '/DIR_.+/{split(substr($0,5),parts,"="); printf("\033[1;31m%-20s\033[0m %s\n", parts[1], parts[2]);}'
104+
env | sort | awk '/DIR_.+/{split(substr($0,5),parts,"="); printf("\033[0;33m%-20s\033[0m %s\n", parts[1], parts[2]);}'
96105

97106
# uncomment this line if color output is not working with the line above
98107
# env | grep "^DIR_" | cut -c5- | sort |grep "^.*="

0 commit comments

Comments
 (0)