zsh-workers
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-workers@zsh.org
Subject: [PATCH] Add completion for picocom utility
Date: Sun,  1 May 2016 03:12:56 +0200	[thread overview]
Message-ID: <1462065176-4503-1-git-send-email-ft@bewatermyfriend.org> (raw)

---
  We're using picocom quite a lot at work, having to remember options
  and baud-rates by heart is getting tiresome, though. So here's a first
  stab at this. If someone has a portable way to generate a list of
  supported baud-rates for serial devices, I love to hear it.

 Completion/Unix/Command/_picocom | 80 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 Completion/Unix/Command/_picocom

diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
new file mode 100644
index 0000000..6653bc2
--- /dev/null
+++ b/Completion/Unix/Command/_picocom
@@ -0,0 +1,80 @@
+#compdef picocom
+
+# The following function uses a generated list; first find out where the B*
+# macros are defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+function _picocom_baudrate () {
+    local expl
+    local -a rates
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+    # -1V removes dupes (which there shouldn't be) and otherwise leaves the
+    # order in the $rates array intact.
+    _wanted -1V baud-rate expl 'baud rate' compadd -a $expl -- rates
+}
+
+function _picocom_flowcontrol () {
+    local expl
+    local -a modes
+    modes=( x h n )
+    _wanted flow-ctrl-mode expl 'flow control mode' compadd -a $expl -- modes
+}
+
+function _picocom_paritymode () {
+    local expl
+    local -a modes
+    modes=( o e n )
+    _wanted parity-mode expl 'parity mode' compadd -a $expl -- modes
+}
+
+function _picocom_databits () {
+    local expl
+    local -a widths
+    widths=( 5 6 7 8 )
+    _wanted data-bits expl 'data bits' compadd -a $expl -- widths
+}
+
+function _picocom_escape () {
+    setopt localoptions braceccl
+    local expl
+    local -a ctrlchars
+    ctrlchars=( {a-z} _ '?' '[' '\' ']' '@' '^' )
+    _wanted escape-key expl 'escape key' compadd -a $expl -- ctrlchars
+}
+
+function _picocom () {
+    local -a args
+
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_picocom_baudrate'
+           '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
+           '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
+           '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
+           '(--escape -e)'{--escape,-e}'[define command mode character]:escape character:_picocom_escape'
+           '(--echo -c)'{--echo,-c}'[enable local echo]'
+           '(--noinit -i)'{--noinit,-i}'[do not initialise serial port]'
+           '(--noreset -r)'{--noreset,-r}'[do not reset serial port]'
+           '(--nolock -l)'{--nolock,-l}'[do not lock serial port]'
+           '(--send-cmd -s)'{--send-cmd,-s}'[define file send command]:file send command:_cmdstring'
+           '(--receive-cmd -v)'{--receive-cmd,-v}'[define file receive command]:file receive command:_cmdstring'
+           '--imap[define input character map]:input character map:'
+           '--omap[define output character map]:output character map:'
+           '--emap[define local echo character map]:local echo character map:'
+           '(--help -h)'{--help,-h}'[display help message]'
+           '*:device:_files -g "*(%c)"' )
+
+    _arguments -C : "${args[@]}"
+}
+
+_picocom "$@"
-- 
2.8.1


             reply	other threads:[~2016-05-01  1:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-01  1:12 Frank Terbeck [this message]
2016-05-01  3:27 ` Ryan Wilson
2016-05-01 10:57   ` Frank Terbeck
2016-05-01 12:47     ` [PATCH] Refactor baud rate completion Frank Terbeck
2016-05-01 13:14     ` [PATCHv2] " Frank Terbeck
2016-05-01 13:27     ` [PATCHv3] " Frank Terbeck
2016-05-01 22:21       ` Frank Terbeck
2016-05-02 12:55       ` Oliver Kiddle
2016-05-03 21:01         ` Frank Terbeck
2016-05-07 21:53         ` Frank Terbeck
2016-05-11 15:08           ` Oliver Kiddle
2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
2016-05-07 22:09           ` [PATCH 1/6] _baudrate → _baudrates Frank Terbeck
2016-05-07 22:09           ` [PATCH 2/6] _baudrates: Use 2 space indentation Frank Terbeck
2016-05-07 22:53             ` Frank Terbeck
2016-05-07 22:09           ` [PATCH 3/6] Use _baudrates helper instead of _baudrate Frank Terbeck
2016-05-07 22:09           ` [PATCH 4/6] _baudrates: Fit better into the general completion framework Frank Terbeck
2016-05-07 22:09           ` [PATCH 5/6] _cu: Remove old -d option of _baudrates Frank Terbeck
2016-05-07 22:09           ` [PATCH 6/6] _baudrates: Make style lookups fit better with the rest of compsys Frank Terbeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462065176-4503-1-git-send-email-ft@bewatermyfriend.org \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).