diff --git a/.bookmarker b/.bookmarker deleted file mode 100644 index 041cce1..0000000 --- a/.bookmarker +++ /dev/null @@ -1,91 +0,0 @@ -+# 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 - +bookmarksshowbrew (){ - + 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 diff --git a/bookmarker.sh b/bookmarker.sh new file mode 100644 index 0000000..fb057b6 --- /dev/null +++ b/bookmarker.sh @@ -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