Skip to content

To make bashmark compatible with files #81

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

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
22 changes: 17 additions & 5 deletions bashmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ 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
}

Expand All @@ -59,6 +68,8 @@ function g {
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
Expand All @@ -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 <bookmark_name> - Saves the current directory as "bookmark_name"'
echo 'g <bookmark_name> - Goes (cd) to the directory associated with "bookmark_name"'
echo 'p <bookmark_name> - Prints the directory associated with "bookmark_name"'
echo 's <bookmark_name> - Saves the current directory or file as "bookmark_name"'
echo 'g <bookmark_name> - Goes (cd) to the directory or open the file associated with "bookmark_name"'
echo 'p <bookmark_name> - Prints the directory or file associated with "bookmark_name"'
echo 'd <bookmark_name> - Deletes the bookmark'
echo 'l - Lists all available bookmarks'
kill -SIGINT $$
Expand Down