completion/completions: use string match to detect usbip remote

* completion/usbip: use string-match to detect remote (#9250)

* simplify output

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
This commit is contained in:
NextAlone 2022-10-02 00:19:29 +08:00 committed by GitHub
parent 40a0ea9bea
commit 794926d28e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,27 +9,18 @@ end
function __fish_usbip_remote -d 'List remote usbip host' function __fish_usbip_remote -d 'List remote usbip host'
set -l remote (ip r | awk '/via/ {print $3"\t"$5}') set -l remote (ip r | awk '/via/ {print $3"\t"$5}')
for i in $remote printf '%s\n' $remote
echo $i
end
end end
function __fish_usbip_busid -d 'List usbip busid' function __fish_usbip_busid -d 'List usbip busid'
set -l token (commandline -opc) set -l remote (commandline -opc | string match -r '([0-9]{1,3}\.){3}[0-9]{1,3}')
if contains -- -r $token set -l busids (usbip list -r $remote 2> /dev/null | string match -r '\d+-\d+')
set -l remote (commandline -opc | string match -r '([0-9]{1,3}\.){3}[0-9]{1,3}') printf '%s\n' $busids
set -l busids (usbip list -r $remote 2> /dev/null | string match -r '\d+-\d+')
for i in $busids
echo $i
end
end
end end
function __fish_usbip_busid_attached -d 'List usbip busid attached' function __fish_usbip_busid_attached -d 'List usbip busid attached'
set -l usbids (usbip port 2> /dev/null | string match -r '(?<=Port\s)(\d+)') set -l usbids (usbip port 2> /dev/null | string match -r '(?<=Port\s)(\d+)')
for i in $usbids printf '%s\n' $usbids
echo $i
end
end end
complete -f -c usbip complete -f -c usbip