fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
0df6fa791
master
1# Fish completions for systemd's "busctl" dbus tool 2# TODO: 3# One issue is that sometimes these will come to a dead-end e.g. when a particular interface has no properties 4# Another is that some busnames aren't accessible by the current user 5# but this can't be predicted via the user that owns that name, e.g. `org.freedesktop.login1` 6# is usually owned by a root-owned process, yet accessible (at least in part) by normal users 7 8# A simple wrapper to call busctl with the correct mode and output 9function __fish_busctl 10# TODO: If there's a "--address" argument we need to pass that 11# We also need to pass the _last_ of these (`busctl --user --system` operates on the system bus) 12set -l mode 13if __fish_contains_opt user 14set mode --user 15else 16set mode --system 17end 18command busctl$mode $argv --no-legend --no-pager2> /dev/null 19end 20 21function _fish_busctl 22set -l args a-address= s-show-machine u-unique A-acquired ä-activatable\ 23 m-match= S-size= l-list q-quiet v-verbose e-expect-reply= Ä-auto-start=\ 24 1-allow-interactive-authorization= t-timeout= 2-augment-creds= U-user 3-system\ 25 H/host= M/machine= n-no-pager N-no-legend h/help V-version 26set -l cmdline( commandline -xpc) ( commandline -ct) 27set -e cmdline[ 1 ] 28argparse $args --$cmdline 2> /dev/null 29or return 30set -l cmd$argv [ 1 ] 31set -e argv[ 1 ] 32switch " $cmd " 33case list help 34# Accepts nothing 35return 36case status 37# A service 38if not set -q argv[ 2 ] 39__fish_busctl_busnames 40end 41case monitor capture tree 42# Services 43__fish_busctl_busnames 44case introspect 45# Service Object Interface 46if not set -q argv[ 2 ] 47__fish_busctl_busnames 48else if not set -q argv[ 3 ] 49__fish_busctl_objects $argv [ 1 ] 50else if not set -q argv[ 4 ] 51__fish_busctl_interfaces $argv [ 1 .. 2 ] 52end 53case call 54# SERVICE OBJECT INTERFACE METHOD [SIGNATURE [ARGUMENT...]] 55if not set -q argv[ 2 ] 56__fish_busctl_busnames 57else if not set -q argv[ 3 ] 58__fish_busctl_objects $argv [ 1 ] 59else if not set -q argv[ 4 ] 60__fish_busctl_interfaces $argv [ 1 .. 2 ] 61else if not set -q argv[ 5 ] 62__fish_busctl_members method$argv [ 1 .. 3 ] 63else if not set -q argv[ 6 ] 64__fish_busctl_signature $argv [ 1 .. 4 ] 65end 66case get-property 67# SERVICE OBJECT INTERFACE PROPERTY... 68if not set -q argv[ 2 ] 69__fish_busctl_busnames 70else if not set -q argv[ 3 ] 71__fish_busctl_objects $argv [ 1 ] 72else if not set -q argv[ 4 ] 73__fish_busctl_interfaces $argv [ 1 .. 2 ] 74else 75__fish_busctl_members property$argv [ 1 .. 3 ] 76end 77case set-property 78# SERVICE OBJECT INTERFACE PROPERTY SIGNATURE ARGUMENT... 79if not set -q argv[ 2 ] 80__fish_busctl_busnames 81else if not set -q argv[ 3 ] 82__fish_busctl_objects $argv [ 1 ] 83else if not set -q argv[ 4 ] 84__fish_busctl_interfaces $argv [ 1 .. 2 ] 85else if not set -q argv[ 5 ] 86__fish_busctl_members property$argv [ 1 .. 3 ] 87else if not set -q argv[ 6 ] 88__fish_busctl_members signature$argv [ 1 .. 4 ] 89end 90end 91end 92 93function __fish_busctl_busnames 94__fish_busctl list --acquired| string replace -r'\s+.*$' '' 95# Describe unique names (":1.32") with their process (e.g. `:1.32\tsteam`) 96__fish_busctl list --unique| string replace -r'\s+\S+\s+(\S+)\s+.*$' '\t$1' 97end 98 99function __fish_busctl_objects -a busname 100__fish_busctl tree --list$busname | string replace -r'\s+.*$' '' 101end 102 103function __fish_busctl_interfaces -a busname -a object 104__fish_busctl introspect --list$busname $object | string replace -r'\s+.*$' '' 105end 106 107function __fish_busctl_members -a type -a busname -a object -a interface 108__fish_busctl introspect --list$busname $object $interface \ 109| string match --"* $type *" | string replace -r'.(\S+) .*' '$1' 110end 111 112function __fish_busctl_signature -a busname -a object -a interface -a member 113__fish_busctl introspect --list$busname $object $interface \ 114| string match". $member *" | while read -l a b c d 115echo $c 116end 117end 118 119### Commands 120set -l commands list status monitor capture tree introspect call get-property set-property help 121 122complete -f -c busctl 123complete -f -c busctl -n"not __fish_seen_subcommand_from $commands " -a" $commands " 124 125### Arguments to commands 126complete -f -c busctl -a'(_fish_busctl)' 127 128# Flags 129# These are incomplete as I have no idea how to complete --address= or --match= 130complete -f -c busctl -n"__fish_seen_subcommand_from call" -l quiet -d'Suppress message payload display' 131complete -f -c busctl -n"__fish_seen_subcommand_from call get-property" -l verbose 132complete -f -c busctl -n"__fish_seen_subcommand_from tree" -l list -d'Show a flat list instead of a tree' 133complete -x -c busctl -n"__fish_seen_subcommand_from call" -l expect-reply -a"yes no" 134complete -x -c busctl -n"__fish_seen_subcommand_from call" -l auto-start -a"yes no" -d'Activate the peer if necessary' 135complete -x -c busctl -n"__fish_seen_subcommand_from call" -l allow-interactive-authorization -a"yes no" 136complete -x -c busctl -n"__fish_seen_subcommand_from call" -l timeout -a"(seq 0 100)" 137complete -f -c busctl -n"__fish_seen_subcommand_from list" -l unique -d'Only show unique (:X.Y) names' 138complete -f -c busctl -n"__fish_seen_subcommand_from list" -l acquired -d'Only show well-known names' 139complete -f -c busctl -n"__fish_seen_subcommand_from list" -l activatable -d'Only show peers that have not been activated yet but can be' 140complete -f -c busctl -n"__fish_seen_subcommand_from list" -l show-machine -d'Show the machine the peers belong to' 141complete -x -c busctl -n"__fish_seen_subcommand_from list status" -l augment-creds -a"yes no" 142complete -f -c busctl -l user 143complete -f -c busctl -l system 144complete -f -c busctl -s H -l host -a"(__fish_print_hostnames)" 145complete -f -c busctl -s M -l machine -a"(__fish_systemd_machines)" 146complete -f -c busctl -l no-pager 147complete -f -c busctl -l no-legend 148complete -f -c busctl -s h -l help 149complete -f -c busctl -l version