fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
4.3 KiB96 linesraw
1# Fish completions for glibs's "gsettings" configuration tool
2
3function __fish_complete_gsettings_args
4    set -l schema_commands get monitor writable range describe set reset reset-recursively list-keys list-children list-recursively
5    set -l key_commands get monitor writable range describe set reset
6
7    set -l schemadir
8    set -l cmd (commandline -pxc)
9    set -e cmd[1]
10
11    if set -q cmd[2]
12        and string match -q -- --schemadir $cmd[1]
13        # TODO: This needs to support proper expansion of paths (~, variables, etc.)
14        set schemadir --schemadir $cmd[2]
15        set -e cmd[1..2]
16    end
17
18    if not set -q cmd[1]
19        return 1
20    end
21
22    set -l subcommand $cmd[1]
23
24    if not contains -- $subcommand $schema_commands
25        return 1
26    end
27
28    if not set -q cmd[2]
29        # Non-relocatable schemas
30        gsettings $schemadir list-schemas 2>/dev/null
31
32        # Relocatable schemas require a dconf path, but there is no universal way of
33        # finding the right paths to suggest here. Just default to '/'.
34        gsettings $schemadir list-relocatable-schemas 2>/dev/null | string replace -r \$ ':/'
35        return 0
36    end
37
38    if not contains -- $subcommand $key_commands
39        return 1
40    end
41
42    set -l schema $cmd[2]
43
44    if not set -q cmd[3]
45        gsettings $schemadir list-keys $schema 2>/dev/null
46        return 0
47    end
48
49    if test $subcommand != set
50        return 1
51    end
52
53    if not set -q cmd[4]
54        set -l key $cmd[3]
55        set -l range (gsettings $schemadir range $schema $key 2>/dev/null)
56        set -l key_type $range[1]
57        set -e range[1]
58        switch $key_type
59            case 'type b'
60                echo true
61                echo false
62            case enum
63                string join \n $range
64            case '*'
65                # If no sensible suggestions can be made, just use the current value.
66                # It gives a good indication on the expected format and is likely already close to what the user wants.
67                gsettings $schemadir get $schema $key 2>/dev/null
68        end
69        return 0
70    end
71
72    return 1
73end
74
75set -l valid_commands get monitor writable range describe set reset reset-recursively list-schemas list-relocatable-schemas list-keys list-children list-recursively help
76
77complete -f -c gsettings
78
79complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -l version -d 'Print the version information'
80complete -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -l schemadir -d 'Specify a custom schemas directory' -xa "(__fish_complete_directories (commandline -ct))"
81
82complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a get -d 'Get the value of a key'
83complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a writable -d 'Determine if a key is writable'
84complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a range -d 'Determine the valid value range of a key'
85complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a describe -d 'Print the description of a key'
86complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a set -d 'Set the value of a key'
87complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a reset -d 'Reset a key to its default value'
88complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a reset-recursively -d 'Reset all keys under the given schema'
89complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a list-schemas -d 'List all installed, non-relocatable schemas'
90complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a list-relocatable-schemas -d 'List all installed, relocatable schemas'
91complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a list-keys -d 'List all keys in a schema'
92complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a list-children -d 'List all children of a schema'
93complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a list-recursively -d 'List keys and values, recursively'
94complete -f -c gsettings -n "not __fish_seen_subcommand_from $valid_commands" -a help -d 'Print help'
95
96complete -f -c gsettings -n "__fish_seen_subcommand_from $valid_commands" -xa "(__fish_complete_gsettings_args)"