From 3142ef6dbc10afa33beee9d838e55074e70e0946 Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Sat, 25 Jan 2020 15:54:49 +0900 Subject: [PATCH] Add interface label/name to the completions for -b --- share/completions/ssh.fish | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/share/completions/ssh.fish b/share/completions/ssh.fish index 4f4011b2a..ff3876737 100644 --- a/share/completions/ssh.fish +++ b/share/completions/ssh.fish @@ -18,7 +18,19 @@ complete -c ssh -n 'test (__fish_number_of_cmd_args_wo_opts) -ge 2' -d "Command complete -c ssh -s a -d "Disables forwarding of the authentication agent" complete -c ssh -s A -d "Enables forwarding of the authentication agent" -complete -x -c ssh -s b -d "Local address to bind to" -a "(__fish_print_addresses)" + +function __ssh_print_local_addresses_with_labels + if command -sq ip + command ip --oneline address | string replace -r '\d+:\s+(\S+)\s+\S+\s+(.+)/.*' '$2\t$1' + else if command -sq ifconfig + # This is for OSX/BSD/anything else that doesn't have `ip` installed. + # Since ifconfig output is not guaranteed to be the same on these systems, + # for now we will limit the completions to just the IP address. + # TODO: check ifconfig output on each system and rework below to include label. + ifconfig | awk '/^\tinet/ { print $2 } ' + end +end +complete -x -c ssh -s b -d "Local address to bind to" -a '(__ssh_print_local_addresses_with_labels)' complete -x -c ssh -s e -d "Escape character" -a "\^ none" complete -c ssh -s f -d "Go to background"