Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: terminal name completion



It's been annoying me that completion after TERM= doesn't work
on FreeBSD. I only get a few names for entries in $TERMINFO
(/usr/local/share/site-terminfo). The system makes use of those so we
need to complete them but the only wider source for names I could find
is in /etc/termcap. I adapted the printcap parsing from _printers to
handle that. This is also applicable on dragonfly (and perhaps
elsewhere). It also provides descriptions.

NetBSD compiles terminfo to it's own .cdb database format. But the
source file - the same one you'd find in a download of ncurses - is left
around and can be parsed. Again there may be other systems where this
can be used and it allows for descriptions.

As on linux, the recursive terminfo glob works also for OpenBSD.

Terminal definitions support inclusions. From looking at the names, it
appears to be a convention to use a + in the naming of incomplete
entries. So alacritty+common should not be completed while
alacritty-direct should. So this will filter those (but not for a
trailing +, e.g. vt100+).

Finally, on at least the Arch Linux system I checked, the alternatives we
try for terminfo includes two that are symlinks to the other so the
recursive glob gets done three times. So this first reduces that to the
one physical path.

Oliver

diff --git a/Completion/Unix/Type/_terminals b/Completion/Unix/Type/_terminals
index 04ece1167..156ba7e96 100644
--- a/Completion/Unix/Type/_terminals
+++ b/Completion/Unix/Type/_terminals
@@ -1,8 +1,37 @@
 #compdef infocmp -value-,TERM,-default-
 
-local desc expl
+local entry
+local -aU desc
+local -a terms names
 
-desc=( $TERMINFO ~/.terminfo $TERMINFO_DIRS /usr/{,share/}{,lib/}terminfo /{etc,lib}/terminfo )
+desc=(
+  $TERMINFO ~/.terminfo $TERMINFO_DIRS /usr/{,share/}{,lib/}terminfo
+  /{etc,lib}/terminfo
+)
+desc=( $desc(N:P) ) # may have symlinks to the same path
+terms=( $desc/*/^*+?*(N:t) ) # entries named with a + are common includes
 
-_wanted terminals expl 'terminal name' \
-    compadd "$@" - $desc/*/*(N:t)
+if [[ $OSTYPE = (freebsd|dragonfly)* ]]; then
+  while read entry; do
+    [[ "$entry" != [^[:blank:]\#\*_]*:* ]] && continue
+
+    names=( ${${(s:|:)entry%%:*}##[[:blank:]]#} )
+    if [[ $#names -gt 1 && $names[-1] = *\ * ]]; then
+      terms+=( ${^names[1,-2]:#*[ +]?*}:${names[-1]} )
+    else
+      terms+=( ${names:#*\ *} )
+    fi
+  done < /etc/termcap
+
+elif [[ $OSTYPE = netbsd* ]]; then
+  grep $'^[^#\t]*,$' /usr/share/misc/terminfo | while read entry; do
+    names=( ${(s:|:)entry%,} )
+    if [[ $#names -gt 1 && $names[-1] = *\ * ]]; then
+      terms+=( ${^names[1,-2]:#*[ +]?*}:${names[-1]} )
+    else
+      terms+=( ${names:#*\ *} )
+    fi
+  done
+fi
+
+_describe -t terminals 'terminal name' terms "$@"




Messages sorted by: Reverse Date, Date, Thread, Author