about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2014-11-24 16:24:54 +0100
committerOliver Kiddle <opk@zsh.org>2014-11-25 20:03:53 +0100
commitee38545c623992d968c0729479663f79c816af2e (patch)
treee89c8a46e5662071e86144f24b691ea590d4f08a
parent05e919dc565dc6231f1c89d23d0264bcb98b29aa (diff)
downloadzsh-ee38545c623992d968c0729479663f79c816af2e.tar.gz
zsh-ee38545c623992d968c0729479663f79c816af2e.tar.xz
zsh-ee38545c623992d968c0729479663f79c816af2e.zip
users/19365: completer for current directory of other shell processes
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Base/Completer/_external_pwds39
2 files changed, 45 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ad71ac8f3..0a021339d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-25  Oliver Kiddle  <opk@zsh.org>
+
+	* users/19365 (credit Death Jester and Jan Larres):
+	Completion/Base/Completer/_external_pwds;
+	completer for current directory of other shell processes
+
 2014-11-25  Barton E. Schaefer  <schaefer@zsh.org>
 
 	* 33791: Src/loop.c: fatal errors in the try-block part of an
diff --git a/Completion/Base/Completer/_external_pwds b/Completion/Base/Completer/_external_pwds
new file mode 100644
index 000000000..4ad50f02b
--- /dev/null
+++ b/Completion/Base/Completer/_external_pwds
@@ -0,0 +1,39 @@
+#autoload
+
+# Completes current directories of other zsh processes
+# this is intended to be used via _generic bound to a
+# different key. Note that pattern matching is enabled.
+
+local -a expl
+local -au dirs
+
+# undo work _main_complete did to remove the tilde
+PREFIX="$IPREFIX$PREFIX"
+IPREFIX=
+SUFFIX="$SUFFIX$ISUFFIX"
+ISUFFIX=
+
+[[ -o magicequalsubst ]] && compset -P '*='
+
+case $OSTYPE in
+  solaris*)
+    dirs=(
+      ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx 2>/dev/null)"}:#$$:*}%%/*}
+    )
+  ;;
+  linux*)
+    dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) )
+    dirs=( $^dirs(N^@) )
+  ;;
+  *)
+    if (( $+commands[lsof] )); then
+      dirs=( ${${${(M)${(f)"$(lsof -a -u $EUID -c zsh -p \^$$ -d cwd -F n -w
+          2>/dev/null)"}:#n*}#?}%% \(*} )
+    fi
+  ;;
+esac
+dirs=( ${(D)dirs} )
+
+compstate[pattern_match]='*'
+_wanted directories expl 'current directory from other shell' \
+    compadd -M "r:|/=* r:|=*" -f -a dirs