about summary refs log tree commit diff
path: root/Functions/TCP/tcp_rename
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_rename
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_rename')
-rw-r--r--Functions/TCP/tcp_rename43
1 files changed, 43 insertions, 0 deletions
diff --git a/Functions/TCP/tcp_rename b/Functions/TCP/tcp_rename
new file mode 100644
index 000000000..8d926ca0d
--- /dev/null
+++ b/Functions/TCP/tcp_rename
@@ -0,0 +1,43 @@
+# Rename session OLD (defaults to current session) to session NEW.
+# Does not handle aliases; use tcp_alias for all alias redefinitions.
+
+local old new
+
+if (( $# == 1 )); then
+  old=$TCP_SESS
+  new=$1
+elif (( $# == 2 )); then
+  old=$1
+  new=$2
+else
+  print "Usage: $0 OLD NEW" >&2
+  return 1
+fi
+
+local fd=$tcp_by_name[$old]
+if [[ -z $fd ]]; then
+  print "No such session: $old" >&2
+  return 1
+fi
+if [[ -n $tcp_by_name[$new] ]]; then
+  print "Session $new already exists." >&2
+  return 1
+fi
+# Can't rename an alias
+if [[ $tcp_by_fd[$fd] != $old ]]; then
+  print "Use tcp_alias to redefine an alias." >&2
+  return 1
+fi
+
+tcp_by_name[$new]=$fd
+unset "tcp_by_name[$old]"
+
+tcp_by_fd[$fd]=$new
+
+[[ $TCP_SESS = $old ]] && TCP_SESS=$new
+
+if zmodload -i zsh/parameter; then
+  if (( ${+functions[tcp_on_rename]} )); then
+    tcp_on_rename $new $fd $old
+  fi
+fi