about summary refs log tree commit diff
path: root/Functions/TCP/tcp_sess
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-02-06 12:21:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-02-06 12:21:49 +0000
commit5c1f3b65a6f5abeae8459f41adb8fd2316971515 (patch)
tree21a82daa1abab96c967d731c7afe2a3a2bd07fff /Functions/TCP/tcp_sess
parent809ab19dff75185a805b4cbb31a6b89f225167f4 (diff)
downloadzsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.tar.gz
zsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.tar.xz
zsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.zip
18202: New TCP function system plus small error message change in ztcp.
Diffstat (limited to 'Functions/TCP/tcp_sess')
-rw-r--r--Functions/TCP/tcp_sess39
1 files changed, 39 insertions, 0 deletions
diff --git a/Functions/TCP/tcp_sess b/Functions/TCP/tcp_sess
new file mode 100644
index 000000000..ee3d268b3
--- /dev/null
+++ b/Functions/TCP/tcp_sess
@@ -0,0 +1,39 @@
+# try to disguise parameters from the eval'd command in case it's a function.
+integer __myfd=1
+
+if [[ -n $1 ]]; then
+  if [[ -z $tcp_by_name[$1] ]]; then
+    print no such session: $1
+    __myfd=2
+  elif [[ -n $2 ]]; then
+    local TCP_SESS=$1
+    shift
+    # A bit tricky: make sure the first argument gets re-evaluated,
+    # so as to get aliases etc. to work, but make sure the remainder
+    # don't, so as not to bugger up quoting.  This ought to work the
+    # vast majority of the time, anyway.
+    local __cmd=$1
+    shift
+    eval $__cmd \$\*
+    return
+  else
+    TCP_SESS=$1
+    return 0;
+  fi
+fi
+
+# Print out the list of sessions, first the number, than the corresponding
+# file descriptor.  The current session, if any, is marked with an asterisk.
+local cur name fd
+for name in ${(ko)tcp_by_name}; do
+  fd=${tcp_by_name[$name]}
+  # mark current session with an asterisk
+  if [[ ${TCP_SESS} = $name ]]; then
+    cur=" *"
+  else
+    cur=
+  fi
+  print "sess:$name; fd:$fd$cur" >&$__myfd
+done
+
+return $(( __myfd - 1 ))