Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for issues #19 and #23 #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions bashmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,27 @@ function s {
check_help $1
_bookmark_name_valid "$@"
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 "$@" ]; then
_purge_line "$SDIRS" "export DIR_DEFAULT="
CURDIR=$(echo $PWD| sed "s#^$HOME#\$HOME#g")
echo "export DIR_DEFAULT=\"$CURDIR\"" >> $SDIRS
else
_purge_line "$SDIRS" "export DIR_$1="
CURDIR=$(echo $PWD| sed "s#^$HOME#\$HOME#g")
echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS
fi
fi
}

# jump to bookmark
function g {
check_help $1
source $SDIRS
cd "$(eval $(echo echo $(echo \$DIR_$1)))"
if [ -z "$@" ]; then
cd "$(eval $(echo echo $(echo \$DIR_DEFAULT)))"
else
cd "$(eval $(echo echo $(echo \$DIR_$1)))"
fi
}

# print bookmark
Expand Down Expand Up @@ -106,10 +116,7 @@ function _l {
# validate bookmark name
function _bookmark_name_valid {
exit_message=""
if [ -z $1 ]; then
exit_message="bookmark name required"
echo $exit_message
elif [ "$1" != "$(echo $1 | sed 's/[^A-Za-z0-9_]//g')" ]; then
if [ "$1" != "$(echo $1 | sed 's/[^A-Za-z0-9_]//g')" ]; then
exit_message="bookmark name is not valid"
echo $exit_message
fi
Expand Down Expand Up @@ -137,7 +144,7 @@ function _purge_line {
trap "rm -f -- '$t'" EXIT

# purge line
sed "/$2/d" "$1" > "$t"
sed "/$2/d" "$1" >! "$t"
mv "$t" "$1"

# cleanup temp file
Expand Down