summaryrefslogtreecommitdiff
path: root/net-dialup/sterm/files/0003-Add-completions-for-bash-and-zsh.patch
blob: e198a3ce1a0de433f10c8ce85a84a402edb7d994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From 6f946b6bffb54e045183059be70f92dd0321376e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <cynerd@email.cz>
Date: Sun, 29 Oct 2017 21:24:03 +0100
Subject: [PATCH 3/3] Add completions for bash and zsh

---
 Makefile        |  6 ++++++
 completion.bash | 24 ++++++++++++++++++++++++
 completion.zsh  | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)
 create mode 100644 completion.bash
 create mode 100644 completion.zsh

diff --git a/Makefile b/Makefile
index 539342a..862ab6d 100644
--- 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
index 0000000..eca6d85
--- /dev/null
+++ b/completion.bash
@@ -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
index 0000000..b803ab9
--- /dev/null
+++ b/completion.zsh
@@ -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
-- 
2.13.6