Repository navigation
Expand file tree
/
Copy pathlhssh.bash_completion
More file actions
114 lines (102 loc) · 3.25 KB
/
Copy pathlhssh.bash_completion
File metadata and controls
114 lines (102 loc) · 3.25 KB
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
#!/usr/bin/bash
# Bash completion for lhssh and lhssh-cmd
_lhssh() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Long and short options
opts="-h --help -V --version -v --verbose -q --quiet -s --short -p --supershort
-H --with-hostname -C --no-color -n --network -b --begin -f --finish
-u --user -t --timeout -T --session-time -K --kill -U --unkill
-L --list-killed -l --list -e --edit -S --save-config -6 --ipv6
-I --interface"
# Handle options that expect arguments
case $prev in
-n|--network)
# Network prefix or CIDR /24 completion
mapfile -t COMPREPLY < <(compgen -W "192.168.1. 192.168.0. 10.0.0. 172.16.0. 192.168.1.0/24 10.0.0.0/24" -- "$cur")
return 0
;;
-b|--begin|-f|--finish)
# IP range numbers
mapfile -t COMPREPLY < <(compgen -W "1 10 50 100 200 254" -- "$cur")
return 0
;;
-u|--user)
# Common usernames
mapfile -t COMPREPLY < <(compgen -W "root admin user $USER" -- "$cur")
return 0
;;
-t|--timeout)
# Timeout values in seconds
mapfile -t COMPREPLY < <(compgen -W "5 10 15 30 60" -- "$cur")
return 0
;;
-T|--session-time)
# Session timeout values in seconds
mapfile -t COMPREPLY < <(compgen -W "300 600 900 1800 3600" -- "$cur")
return 0
;;
-I|--interface)
# Complete with network interface names
mapfile -t COMPREPLY < <(compgen -W "$(ls /sys/class/net 2>/dev/null)" -- "$cur")
return 0
;;
esac
# If current word starts with dash, complete options
if [[ $cur == -* ]]; then
mapfile -t COMPREPLY < <(compgen -W "$opts" -- "$cur")
return 0
fi
# If no dash and we have a config file, try to complete with known hosts
if [[ -f ~/.lhssh.conf ]]; then
# Source the config to get network settings
local LOCALHOST_HEAD LOCALHOST_START_IP LOCALHOST_END_IP
# shellcheck source=/dev/null
source ~/.lhssh.conf 2>/dev/null || true
# Generate potential IP completions (last octet only)
if [[ -n "$LOCALHOST_HEAD" && -n "$LOCALHOST_START_IP" && -n "$LOCALHOST_END_IP" ]]; then
local ips=()
for ((i=LOCALHOST_START_IP; i<=LOCALHOST_END_IP; i++)); do
ips+=("$i")
done
mapfile -t COMPREPLY < <(compgen -W "${ips[*]}" -- "$cur")
fi
fi
# Fall back to numeric completion for IP last octets
if [[ ${#COMPREPLY[@]} -eq 0 && $cur =~ ^[0-9]*$ ]]; then
local nums=()
for ((i=1; i<=254; i++)); do
if [[ $i =~ ^$cur ]]; then
nums+=("$i")
fi
done
COMPREPLY=("${nums[@]}")
fi
}
_lhssh_cmd() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-h --help -V --version -v --verbose -q --quiet -p --parallel
-P --max-parallel --lhssh"
case $prev in
-P|--max-parallel)
mapfile -t COMPREPLY < <(compgen -W "5 10 20 50" -- "$cur")
return 0
;;
--lhssh)
# Complete with file paths
mapfile -t COMPREPLY < <(compgen -f -- "$cur")
return 0
;;
esac
if [[ $cur == -* ]]; then
mapfile -t COMPREPLY < <(compgen -W "$opts" -- "$cur")
return 0
fi
}
complete -F _lhssh lhssh
complete -F _lhssh_cmd lhssh-cmd