bc67a55fe8ff6fce8fdc2c002dbb7159c6008aa0

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

jump: fix issues in plugin and document CTRL+G key binding

- Fixes `readlink -e` dependency which isn't supported in macOS
  (fixes #3235).
- Uses native zsh wildcard expansion instead of calls to `ls`.
- Prepends commands with `command` and `builtin` to bypass aliases
  and functions.
- Documents CTRL+G key binding to substitute mark name in the command
  line with the mark path (https://github.com/ohmyzsh/ohmyzsh/pull/2045#issuecomment-22826540).

Diff

 1diff --git a/plugins/jump/README.md b/plugins/jump/README.md
 2index ed64152896120cc93440fd6f167b8fb071909e4c..1b0ce68c034066f95dce2c2eb3d36efb161c400e 100644
 3--- a/plugins/jump/README.md
 4+++ b/plugins/jump/README.md
 5@@ -17,3 +17,15 @@ plugins=(... jump)
 6 | `mark [mark-name]`   | Create a mark with the given name or with the name of the current directory if none is provided |
 7 | `unmark <mark-name>` | Remove the given mark                                                                           |
 8 | `marks`              | List the existing marks and the directories they point to                                       |
 9+
10+## Key bindings
11+
12+Pressing `CTRL`+`G` substitutes the written mark name for the full path of the mark.
13+For example, with a mark named `mymark` pointing to `/path/to/my/mark`:
14+```zsh
15+$ cp /tmp/file mymark<C-g>
16+```
17+will become:
18+```zsh
19+$ cp /tmp/file /path/to/my/mark
20+```
21diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh
22index d161a6da032eafaffad44fe3cc7154f4982efebe..4f9134fcdcfaf3d0f2d071fe3bf19db05e457467 100644
23--- a/plugins/jump/jump.plugin.zsh
24+++ b/plugins/jump/jump.plugin.zsh
25@@ -9,22 +9,23 @@
26 export MARKPATH=$HOME/.marks
27 
28 jump() {
29-	cd -P "$MARKPATH/$1" 2>/dev/null || {echo "No such mark: $1"; return 1}
30+	builtin cd -P "$MARKPATH/$1" 2>/dev/null || {echo "No such mark: $1"; return 1}
31 }
32 
33 mark() {
34-	if [[ ( $# == 0 ) || ( "$1" == "." ) ]]; then
35-		MARK=$(basename "$PWD")
36+	if [[ $# -eq 0 || "$1" = "." ]]; then
37+		MARK=${PWD:t}
38 	else
39 		MARK="$1"
40 	fi
41-	if read -q \?"Mark $PWD as ${MARK}? (y/n) "; then
42-		mkdir -p "$MARKPATH"; ln -sfn "$PWD" "$MARKPATH/$MARK"
43+	if read -q "?Mark $PWD as ${MARK}? (y/n) "; then
44+		command mkdir -p "$MARKPATH"
45+		command ln -sfn "$PWD" "$MARKPATH/$MARK"
46 	fi
47 }
48 
49 unmark() {
50-	rm -i "$MARKPATH/$1"
51+	LANG= command rm -i "$MARKPATH/$1"
52 }
53 
54 marks() {
55@@ -44,13 +45,7 @@ marks() {
56 }
57 
58 _completemarks() {
59-	if [[ $(ls "${MARKPATH}" | wc -l) -gt 1 ]]; then
60-		reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_a-zA-Z0-9\.\-]*):$/\2/g'))
61-	else
62-		if readlink -e "${MARKPATH}"/* &>/dev/null; then
63-			reply=($(ls "${MARKPATH}"))
64-		fi
65-	fi
66+	reply=("${MARKPATH}"/*(N:t))
67 }
68 compctl -K _completemarks jump
69 compctl -K _completemarks unmark