Skip to content

Commit 7a8e408

Browse files
committed
screen: add //telnet completion
1 parent 9cde25b commit 7a8e408

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

completions/screen

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ _screen()
2525
local cur prev words cword
2626
_init_completion || return
2727

28-
if [[ $cword -eq 1 && $cur == /dev* ]]; then
29-
COMPREPLY=( $(compgen -W "$(shopt -s nullglob; printf '%s\n' \
30-
/dev/serial/by-id/* /dev/ttyUSB* /dev/ttyACM* 2>/dev/null)" \
31-
-- "$cur") )
32-
return
28+
if ((cword == 1)); then
29+
if [[ $cur == /dev* ]]; then
30+
COMPREPLY=( $(compgen -W "$(shopt -s nullglob; printf '%s\n' \
31+
/dev/serial/by-id/* /dev/ttyUSB* /dev/ttyACM* 2>/dev/null)" \
32+
-- "$cur") )
33+
return
34+
fi
35+
if [[ $cur == //* ]]; then
36+
COMPREPLY=( $(compgen -W '//telnet' -- "$cur") )
37+
return
38+
fi
3339
fi
3440

41+
case ${words[1]} in
42+
//telnet)
43+
((cword == 2)) && _known_hosts_real -- "$cur"
44+
return
45+
;;
46+
esac
47+
3548
if ((cword > 2)); then
3649
case ${words[cword-2]} in
3750
-*[dD])

test/fixtures/shared/.ssh/known_hosts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bash-completion-canary-host.local

test/t/test_screen.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ def test_4(self, completion):
2222
@pytest.mark.complete("screen -T foo cat")
2323
def test_5(self, completion):
2424
assert completion
25+
26+
@pytest.mark.complete("screen //")
27+
def test_telnet(self, completion):
28+
assert completion == "//telnet"
29+
30+
@pytest.mark.complete("screen cat //")
31+
def test_not_telnet(self, completion):
32+
assert completion != "//telnet"
33+
34+
@pytest.mark.complete("screen //telnet ", env=dict(HOME="$PWD/shared"))
35+
def test_telnet_first_arg(self, completion):
36+
assert "bash-completion-canary-host.local" in completion
37+
38+
@pytest.mark.complete("screen //telnet foo ", env=dict(HOME="$PWD/shared"))
39+
def test_telnet_other_args(self, completion):
40+
assert not completion

0 commit comments

Comments
 (0)