6b0557afe84f671705029bf2a21002dfe9d07be5

Author
deathjest3r <Death.Jester@web.de>
Committer
GitHub <noreply@github.com>
Date

Message

feat(plugins): add `term_tab` plugin to complete other zsh sessions' directories (#3018)

Diff

 1diff --git a/plugins/term_tab/README b/plugins/term_tab/README
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..316062e7328aae02860b9ee238067f003911ea59
 4--- /dev/null
 5+++ b/plugins/term_tab/README
 6@@ -0,0 +1,16 @@
 7+
 8+term_tab - 'cwd' for all open zsh sessions
 9+******************************************
10+
11+What it does:
12+*************
13+This plugin allows to complete the 'cwd' of other Zsh sessions. Sounds
14+complicated but is rather simple. E.g. if you have three zsh sessions open, in
15+each session you are in a different folder, you can hit Ctrl+v in one session
16+to show you the current working directory of the other open zsh sessions.
17+
18+How it works:
19+*************
20+* It uses 'pidof zsh' to determine all zsh PIDs
21+* It reads procfs to get the current working directory of this session
22+* Everything is fed into zsh's completion magic
23diff --git a/plugins/term_tab/term_tab.plugin.zsh b/plugins/term_tab/term_tab.plugin.zsh
24new file mode 100644
25index 0000000000000000000000000000000000000000..1b612df688fe0aeb4bbcf35d235b0237433184e4
26--- /dev/null
27+++ b/plugins/term_tab/term_tab.plugin.zsh
28@@ -0,0 +1,41 @@
29+# Copyright (C) 2014 Julian Vetter <death.jester@web.de>
30+#
31+# This program is free software; you can redistribute it and/or modify
32+# it under the terms of the GNU General Public License as published by
33+# the Free Software Foundation; either version 2 of the License, or
34+# (at your option) any later version.
35+#
36+# This program is distributed in the hope that it will be useful,
37+# but WITHOUT ANY WARRANTY; without even the implied warranty of
38+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39+# GNU General Public License for more details.
40+#
41+# You should have received a copy of the GNU General Public License
42+# along with this program; if not, write to the Free Software
43+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
44+
45+function _term_list(){
46+  local -a expl
47+  local -au dirs
48+
49+  PREFIX="$IPREFIX$PREFIX"
50+  IPREFIX=
51+  SUFFIX="$SUFFIX$ISUFFIX"
52+  ISUFFIX=
53+
54+  [[ -o magicequalsubst ]] && compset -P '*='
55+
56+  case $OSTYPE in
57+    solaris*) dirs=( ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx)"}:#$$:*}%%/*} ) ;;
58+    linux*) dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) ) ;;
59+  esac
60+  dirs=( ${(D)dirs} )
61+
62+  compstate[pattern_match]='*'
63+  _wanted directories expl 'current directory from other shell' \
64+      compadd -Q -M "r:|/=* r:|=*" -f -a dirs
65+}
66+
67+zle -C term_list menu-complete _generic
68+bindkey "^v" term_list
69+zstyle ':completion:term_list::::' completer _term_list