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

Jump helper messages #3

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 47 additions & 16 deletions plugins/jump/jump.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,78 @@
# unmark FOO: delete a mark
# marks: lists all marks
#

export MARKPATH=$HOME/.marks

jump() {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
function jump()
{
if [[ -z $1 ]]; then
echo "Error: no mark name given"
echo "available marks:"
marks
return
fi
if [[ $1 == "--help" ]]; then
echo "Jump plugin:"
echo " 'jump FOO': jump to a mark named FOO"
echo " 'mark FOO': create a mark named FOO"
echo " 'unmark FOO': delete a mark"
echo " 'marks': lists all marks"
return
fi

cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}

mark() {
if (( $# == 0 )); then
MARK=$(basename "$(pwd)")
else
MARK="$1"
fi
if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK"
fi
function mark()
{
if (( $# == 0 )); then
MARK=$(basename "$(pwd)")
else
MARK="$1"
fi
if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK"
fi
}

unmark() {
rm -i "$MARKPATH/$1"
function unmark()
{
rm -i "$MARKPATH/$1"
}

autoload colors
marks() {
function marks()
{
if [[ -d $MARKPATH ]]; then
for link in $MARKPATH/*(@); do
local markname="$fg[cyan]${link:t}$reset_color"
local markpath="$fg[blue]$(readlink $link)$reset_color"
printf "%s\t" $markname
printf "-> %s \t\n" $markpath
done
else
echo "No mark found."
fi
}

_completemarks() {
function _completemarks()
{
reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g'))
}

compctl -K _completemarks jump
compctl -K _completemarks unmark

_mark_expansion() {
function _mark_expansion()
{
setopt extendedglob
autoload -U modify-current-argument
modify-current-argument '$(readlink "$MARKPATH/$ARG")'
}

zle -N _mark_expansion
bindkey "^g" _mark_expansion

alias j='jump'
compdef _jump j=jump