name change to 'zshmarks' to better represent that this comes from 'bash marks'

added a new function to manually edit the ~/.bookmarks file, using whatever $EDITOR the use has registered
This commit is contained in:
Jocelyn Mallon 2011-10-03 19:25:26 -07:00
commit c103b091d4
3 changed files with 27 additions and 22 deletions

View file

@ -1,50 +0,0 @@
# ------------------------------------------------------------------------------
# FILE: go.plugin.zsh
# DESCRIPTION: oh-my-zsh plugin file.
# AUTHOR: Jocelyn Mallon (jocelyn.e.mallon@gmail.com)
# VERSION: 1.0
# ------------------------------------------------------------------------------
bookmarks_file="$HOME/.zshbookmarks"
# Create bookmarks_file it if it doesn't exist
if [[ ! -f $bookmarks_file ]]; then
touch $bookmarks_file
fi
function bookmark() {
bookmark_name=$1
if [[ -z $bookmark_name ]]; then
echo 'Invalid name, please provide a name for your bookmark. For example:'
echo ' bookmark foo'
else
bookmark="$(pwd)|$bookmark_name" # Store the bookmark as folder|name
if [[ -z $(grep "$bookmark" $bookmarks_file) ]]; then
echo $bookmark >> $bookmarks_file
echo "Bookmark '$bookmark_name' saved"
else
echo "Bookmark already existed"
fi
fi
}
function 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="${bookmark%%|*}"
cd "${dir}"
dir=""
fi
}
# Show a list of the bookmarks
function bookmarksshow(){
cat ~/.bookmarks | awk '{ printf "%-40s%-40s%s\n",$1,$2,$3}' FS=\|
}