fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a9618477e
master
1function __fish_usbip_no_subcommand -d'Test if usbip has yet to be given the subcommand' 2for iin ( commandline -xpc) 3if contains --$i attach detach list bind unbind port 4return 1 5end 6end 7return 0 8end 9 10function __fish_usbip_remote -d'List remote usbip host' 11set -l remote( ip r| awk '/via/ {print $3"\t"$5}' ) 12printf '%s\n' $remote 13end 14 15function __fish_usbip_busid -d'List usbip busid' 16set -l remote( commandline -xpc| string match -r'(?<=-r)(emote)?=?\s*(\S+)' | string trim) 17set -l busids( usbip list -r$remote 2> /dev/null| string match -r'\d+-\d+' ) 18printf '%s\n' $busids 19end 20 21function __fish_usbip_busid_attached -d'List usbip busid attached' 22set -l usbids( usbip port2> /dev/null| string match -r'(?<=Port\s)(\d+)' ) 23printf '%s\n' $usbids 24end 25 26complete -f -c usbip 27complete -f -c usbip -n __fish_usbip_no_subcommand -a attach -d'Attach a USB device to the host' 28complete -f -c usbip -n __fish_usbip_no_subcommand -a detach -d'Detach a USB device from the host' 29complete -f -c usbip -n __fish_usbip_no_subcommand -a list -d'List USB devices on the host' 30complete -f -c usbip -n __fish_usbip_no_subcommand -a bind -d'Bind a USB device to a driver' 31complete -f -c usbip -n __fish_usbip_no_subcommand -a unbind -d'Unbind a USB device from a driver' 32complete -f -c usbip -n __fish_usbip_no_subcommand -a port -d'List USB ports on the host' 33 34# attach 35complete -f -c usbip -n'__fish_seen_subcommand_from attach' -s r -l remote -d'The machine with exported USB devices' -xa"(__fish_usbip_remote)" 36complete -f -c usbip -n'__fish_seen_subcommand_from attach' -s b -l busid -d'Busid of the device on <host>' -xa"(__fish_usbip_busid)" 37complete -f -c usbip -n'__fish_seen_subcommand_from attach' -s d -l device -d'Id of the virtual UDB on <host>' 38 39# detach 40complete -f -c usbip -n'__fish_seen_subcommand_from detach' -s p -l port -d'Vhci_hcd port the device is on' -xa"(__fish_usbip_busid_attached)" 41 42# list 43complete -f -c usbip -n'__fish_seen_subcommand_from list' -s p -l parsable -d'Parsable list format' 44complete -f -c usbip -n'__fish_seen_subcommand_from list' -s r -l remote -d'List the exportable USB devices on <host>' -xa"(__fish_usbip_remote)" 45complete -f -c usbip -n'__fish_seen_subcommand_from list' -s l -l local -d'List the local USB devices' 46complete -f -c usbip -n'__fish_seen_subcommand_from list' -s d -l device -d'List the local USB gadgets bound to usbip-vudc' 47 48# Bind 49complete -f -c usbip -n'__fish_seen_subcommand_from bind' -s b -l busid -d'Bind usbip-host.ko to device on <busid>' 50 51# unbind 52complete -f -c usbip -n'__fish_seen_subcommand_from unbind' -s b -l busid -d'Unbind usbip-host.ko to device on <busid>'