about summary refs log tree commit diff
path: root/Functions/Misc/nslookup
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Misc/nslookup')
-rw-r--r--Functions/Misc/nslookup59
1 files changed, 34 insertions, 25 deletions
diff --git a/Functions/Misc/nslookup b/Functions/Misc/nslookup
index 15afb2ff1..e03e55cd5 100644
--- a/Functions/Misc/nslookup
+++ b/Functions/Misc/nslookup
@@ -1,34 +1,43 @@
 # Simple wrapper function for `nslookup'. With completion if you are using
 # the function based completion system.
 
-setopt localoptions completealiases
+setopt localoptions localtraps completealiases
 
-local char line compcontext=nslookup pid
+local tmp line compcontext=nslookup curcontext='nslookup:::' pmpt
+local pager opager="$PAGER"
+typeset +g -x PAGER=cat
 
-trap 'print -p exit;return' INT
+zmodload -e zsh/zpty || zmodload -i zsh/zpty
 
-coproc command nslookup
-pid=$!
+trap 'return 130' INT
+trap 'zpty -d nslookup' EXIT
 
-while read -pk1 char; do
-  line="$line$char"
-  [[ "$line" = *'
-> ' ]] && break
-done
-print -nr - "$line"
-
-line=''
-while vared -p '> ' line; do
-  print -p "$line"
-  line=''
-  while read -pk1 char; do
-    line="$line$char"
-    [[ "$line" = *'
-> ' ]] && break
-  done
-  print -nr - "$line"
-  line=''
+pmpt=()
+zstyle -s ':nslookup' prompt tmp && pmpt=(-p "$tmp")
+zstyle -s ':nslookup' rprompt tmp && pmpt=("$pmpt[@]" -r "$tmp")
+zstyle -s ':nslookup' pager tmp &&
+    [[ -z "$pager" ]] && pager="${opager:-more}"
+(( $#pmpt )) || pmpt=(-p '> ')
+
+zpty nslookup nslookup
+
+zpty -r nslookup line '*
+> '
+print -nr "$line"
+
+while line=''; vared -he "$pmpt[@]" line; do
+  print -s "$line"
+  [[ "$line" = exit ]] && break
+
+  zpty -w nslookup "$line"
+
+  zpty -r nslookup line '*
+> '
+  if [[ -n "$pager" && ${#${(f)line}} -gt LINES ]]; then
+    print -nr "$line" | "$pager"
+  else
+    print -nr "$line"
+  fi
 done
 
-print -p exit
-wait $pid
+zpty -w nslookup 'exit'