From e368bf1d4aea6ac08ae46d60308e0492e9ab3b85 Mon Sep 17 00:00:00 2001 From: Jeroen Janssens Date: Thu, 15 Aug 2013 10:32:01 -0400 Subject: [PATCH 1/8] Add jump plugin, which allows you to easily jump around the file system --- plugins/jump/jump.plugin.zsh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 plugins/jump/jump.plugin.zsh diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh new file mode 100644 index 00000000..b792f544 --- /dev/null +++ b/plugins/jump/jump.plugin.zsh @@ -0,0 +1,21 @@ +# Easily jump around the file system by manually adding marks +# marks are stored as symbolic links in the directory $MARKPATH (default $HOME/.marks) +# +# jump FOO: jump to a mark named FOO +# mark FOO: create a mark named FOO +# unmark FOO: delete a mark +# marks: lists all marks +# +export MARKPATH=$HOME/.marks +function jump { + cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1" +} +function mark { + mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 +} +function unmark { + rm -i $MARKPATH/$1 +} +function marks { + ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo +} From 73c22c146c57afe5c9ce341cff876abf00571463 Mon Sep 17 00:00:00 2001 From: Jeroen Janssens Date: Sun, 18 Aug 2013 14:16:26 -0400 Subject: [PATCH 2/8] Add tab completion for jump plugin --- plugins/jump/jump.plugin.zsh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index b792f544..349d3e01 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -8,14 +8,21 @@ # export MARKPATH=$HOME/.marks function jump { - cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1" + cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" } function mark { - mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 + mkdir -p "$MARKPATH"; ln -s "$(pwd)" $MARKPATH/$1 } function unmark { - rm -i $MARKPATH/$1 + rm -i "$MARKPATH/$1" } function marks { - ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo + ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo } + +function _completemarks { + reply=($(ls $MARKPATH)) +} + +compctl -K _completemarks jump +compctl -K _completemarks unmark From 128cd3f5661d42f10ef3bae742ae3416f401c7ad Mon Sep 17 00:00:00 2001 From: Justin Aiken <60tonangel@gmail.com> Date: Thu, 5 Sep 2013 09:39:22 -0600 Subject: [PATCH 3/8] Filter out missing links with jump autocomplete --- plugins/jump/jump.plugin.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index 349d3e01..8f146820 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -7,13 +7,13 @@ # marks: lists all marks # export MARKPATH=$HOME/.marks -function jump { +function jump { cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" } -function mark { +function mark { mkdir -p "$MARKPATH"; ln -s "$(pwd)" $MARKPATH/$1 } -function unmark { +function unmark { rm -i "$MARKPATH/$1" } function marks { @@ -21,7 +21,7 @@ function marks { } function _completemarks { - reply=($(ls $MARKPATH)) + reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([a-z]*):$/\2/g')) } compctl -K _completemarks jump From a265acee4f991dfd96fb3a9057309e9c1a345a2c Mon Sep 17 00:00:00 2001 From: Justin Aiken <60tonangel@gmail.com> Date: Thu, 5 Sep 2013 10:00:14 -0600 Subject: [PATCH 4/8] Better filename matching --- plugins/jump/jump.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index 8f146820..60eae85a 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -21,7 +21,7 @@ function marks { } function _completemarks { - reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([a-z]*):$/\2/g')) + reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g')) } compctl -K _completemarks jump From 4517db6acc6e4217a25aa353da37fb8de617bfc4 Mon Sep 17 00:00:00 2001 From: Jeroen Janssens Date: Fri, 6 Sep 2013 09:34:27 -0400 Subject: [PATCH 5/8] Add _completemarks function as suggested by pielgrzym in https://github.com/robbyrussell/oh-my-zsh/pull/2045#issuecomment-22826540 --- plugins/jump/jump.plugin.zsh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index 60eae85a..1035191a 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -7,15 +7,19 @@ # marks: lists all marks # export MARKPATH=$HOME/.marks + function jump { cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" } + function mark { mkdir -p "$MARKPATH"; ln -s "$(pwd)" $MARKPATH/$1 } + function unmark { rm -i "$MARKPATH/$1" } + function marks { ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo } @@ -23,6 +27,13 @@ function marks { function _completemarks { reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g')) } - compctl -K _completemarks jump compctl -K _completemarks unmark + +_mark_expansion() { + setopt extendedglob + autoload -U modify-current-argument + modify-current-argument '$(readlink "$MARKPATH/$ARG")' +} +zle -N _mark_expansion +bindkey "^g" _mark_expansion From 55d4873f91b8cebbb2e6df5f3a405022e76e0c2c Mon Sep 17 00:00:00 2001 From: Jeroen Janssens Date: Fri, 6 Sep 2013 09:40:44 -0400 Subject: [PATCH 6/8] Change marks function and remove 'function' keyword as suggested by pielgrzym in https://github.com/robbyrussell/oh-my-zsh/pull/2045#issuecomment-22820224 --- plugins/jump/jump.plugin.zsh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index 1035191a..c6f266ae 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -8,24 +8,30 @@ # export MARKPATH=$HOME/.marks -function jump { +jump() { cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" } -function mark { +mark() { mkdir -p "$MARKPATH"; ln -s "$(pwd)" $MARKPATH/$1 } -function unmark { +unmark() { rm -i "$MARKPATH/$1" } -function marks { - ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo +autoload colors +marks() { + 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 } -function _completemarks { - reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g')) +_completemarks() { + reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g')) } compctl -K _completemarks jump compctl -K _completemarks unmark From 255b0c4f5e16465ace326ddf1884ea2e7c1f3df1 Mon Sep 17 00:00:00 2001 From: Jeroen Janssens Date: Fri, 6 Sep 2013 09:55:43 -0400 Subject: [PATCH 7/8] Mark function asks for confirmation and uses basename of directory when no argument is given --- plugins/jump/jump.plugin.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index c6f266ae..e32a5a0b 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -13,7 +13,15 @@ jump() { } mark() { - mkdir -p "$MARKPATH"; ln -s "$(pwd)" $MARKPATH/$1 + DIR="$(pwd)" + if (( $# == 0 )); then + MARK=$(basename $DIR) + else + MARK=$1 + fi + if read -q \?"Mark ${DIR} as ${MARK}? (y/n) "; then + mkdir -p "$MARKPATH"; ln -s "${DIR}" "$MARKPATH/$MARK" + fi } unmark() { From d3e005d6b42995021ad6f1009734a55cb65be6ce Mon Sep 17 00:00:00 2001 From: Jeroen Janssens Date: Fri, 6 Sep 2013 15:29:14 -0400 Subject: [PATCH 8/8] Fix aliasing pwd --- plugins/jump/jump.plugin.zsh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index e32a5a0b..a3c5cf8c 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -13,14 +13,13 @@ jump() { } mark() { - DIR="$(pwd)" if (( $# == 0 )); then - MARK=$(basename $DIR) + MARK=$(basename "$(pwd)") else - MARK=$1 + MARK="$1" fi - if read -q \?"Mark ${DIR} as ${MARK}? (y/n) "; then - mkdir -p "$MARKPATH"; ln -s "${DIR}" "$MARKPATH/$MARK" + if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then + mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK" fi }