]> rtime.felk.cvut.cz Git - sojka/sterm.git/commitdiff
Add completions for bash and zsh
authorKarel Kočí <cynerd@email.cz>
Sun, 29 Oct 2017 20:24:03 +0000 (21:24 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 20 Nov 2017 09:39:18 +0000 (10:39 +0100)
Makefile
completion.bash [new file with mode: 0644]
completion.zsh [new file with mode: 0644]

index 539342a6cfd0b41b22e03bf8ab972364d06073e1..862ab6d97c4d08045d1a1d1d166880d18b993b82 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,3 +17,9 @@ ifneq ($(NO_MAN),1)
        $(INSTALL) -m 644 sterm.man $(DESTDIR)$(PREFIX)/share/man/man1/sterm.1
        gzip -f $(DESTDIR)$(PREFIX)/share/man/man1/sterm.1
 endif
+ifneq ($(NO_COMP),1)
+       $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/bash-completion/completions/
+       $(INSTALL) -m 644 completion.bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/sterm
+       $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/zsh/site-functions
+       $(INSTALL) -m 644 completion.zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_sterm
+endif
diff --git a/completion.bash b/completion.bash
new file mode 100644 (file)
index 0000000..eca6d85
--- /dev/null
@@ -0,0 +1,24 @@
+# Bash completion file for sterm
+# vim: ft=sh
+
+_sterm() {
+       local cur prev
+       _init_completion || return
+       COMPREPLY=()
+       #cur="${COMP_WORDS[COMP_CWORD]}"
+       local ops="-h --help -c -d -e -n -r -s -v"
+       case "$prev" in
+               -d|-r)
+                       # No completion for these
+                       ;;
+               -s)
+                       local speeds="0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 9600 19200 38400 57600 115200 230400"
+                       COMPREPLY+=($(compgen -W "${speeds}" -- ${cur}))
+                       ;;
+               *)
+                       COMPREPLY+=($(compgen -W "${ops}" -- ${cur}))
+                       ;;
+       esac
+}
+
+complete -o default -F _sterm sterm
diff --git a/completion.zsh b/completion.zsh
new file mode 100644 (file)
index 0000000..b803ab9
--- /dev/null
@@ -0,0 +1,56 @@
+#compdef sterm
+#autoload
+
+_sterm_defs() {
+       _arguments : \
+               "--help[Output help message]" \
+               "-h[Print help text]" \
+               "-s[Set baudrate]" \
+               "-c[Enter command mode]" \
+               "-d[Make pulse on DTR]" \
+               "-r[Make pulse on RTS]" \
+               "-e[Ignore '~.' escape sequence]" \
+               "-n[Do not switch the device to raw mode]" \
+               "-v[Verbose mode]"
+       _path_files
+}
+
+_sterm() {
+       if (( CURRENT > 2)); then
+               local prev=${words[(( CURRENT - 1))]}
+               case "${prev}" in
+                       -d|-r)
+                               # No completion for these
+                               ;;
+                       -s)
+                               _values "Baudrate" \
+                                       "0" \
+                                       "50" \
+                                       "75" \
+                                       "110" \
+                                       "134" \
+                                       "150" \
+                                       "200" \
+                                       "300" \
+                                       "600" \
+                                       "1200" \
+                                       "1800" \
+                                       "2400" \
+                                       "4800" \
+                                       "9600" \
+                                       "19200" \
+                                       "38400" \
+                                       "57600" \
+                                       "115200" \
+                                       "230400"
+                               ;;
+                       *)
+                               _sterm_defs
+                               ;;
+               esac
+       else
+               _sterm_defs
+       fi
+}
+
+_sterm