Skip to content

Commit

Permalink
Update and rename .bookmarker to bookmarker.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
pratik60 committed Jul 26, 2014
1 parent 761c196 commit 80593fa
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 91 deletions.
91 changes: 0 additions & 91 deletions .bookmarker

This file was deleted.

93 changes: 93 additions & 0 deletions bookmarker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/sh

# Set of bash functions that allows you to bookmark folders in the command-line.
# To bookmark a folder, simply go to that folder, then bookmark it like so:
# bookmark foo
#
# The bookmark will be named "foo"
#
# When you want to get back to that folder use:
# go foo
#
# To see a list of bookmarks:
# bookmarksshow
#
# Tab completion works, to go to the shoobie bookmark:
# go sho[tab]
#
# Your bookmarks are stored in the ~/.bookmarks file

bookmarks_file=~/.bookmarks

# Create bookmarks_file it if it doesn't exist
if [[ ! -f $bookmarks_file ]]; then
touch $bookmarks_file
fi

bookmark (){
bookmark_name=$1

if [[ -z $bookmark_name ]]; then
bookmark_name=${PWD##*/} #Store the current folder name as bookmark by default
fi

bookmark="`pwd`|$bookmark_name" # Store the bookmark as folder|name

if [[ -z `grep "$bookmark_name$" $bookmarks_file` ]]; then
echo $bookmark >> $bookmarks_file
echo "Bookmark '$bookmark_name' saved"
else
echo "Bookmark with '$bookmark_name' already exists"
echo 'Please provide another name for your bookmark. For example:'
echo ' bookmark foo'
fi
}

unbookmark (){
unbookmark_name=$1

if [[ -z $unbookmark_name ]]; then
echo 'Invalid name, please provide a name that has to be unbookmarked. For example:'
echo ' unbookmark foo'
else
unbookmark="$unbookmark_name$" # Store the bookmark as folder|name

if [[ -z `grep "$unbookmark" $bookmarks_file` ]]; then
echo "Bookmark not present, so can't be unbookmarked. To see a list of bookmarks:"
echo " bookmarksshow"
else
`grep -v "$unbookmark" $bookmarks_file > .bookmark_temp; mv .bookmark_temp $bookmarks_file`
echo "Bookmark '$unbookmark_name' removed"
fi
fi
}


# Show a list of the bookmarks
brewbookmarksshow (){
cat ~/.bookmarks | awk '{ printf "%-40s%-40s%s\n",$1,$2,$3}' FS=\|
}

go(){
bookmark_name=$1

bookmark=`grep "|$bookmark_name$" "$bookmarks_file"`

if [[ -z $bookmark ]]; then
echo 'Invalid name, please provide a valid bookmark name. For example:'
echo ' go foo'
echo
echo 'To bookmark a folder, go to the folder then do this (naming the bookmark 'foo'):'
echo ' bookmark foo'
else
dir=`echo "$bookmark" | cut -d\| -f1`
cd "$dir"
fi
}

_go_complete(){
# Get a list of bookmark names, then grep for what was entered to narrow the list
cat $bookmarks_file | cut -d\| -f2 | grep "$2.*"
}

complete -C _go_complete -o default go

0 comments on commit 80593fa

Please sign in to comment.