fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a9618477e
master
1# Fish completions for glibs's "gsettings" configuration tool 2 3function __fish_complete_gsettings_args 4set -l schema_commands get monitor writable range describe set reset reset-recursively list-keys list-children list-recursively 5set -l key_commands get monitor writable range describe set reset 6 7set -l schemadir 8set -l cmd( commandline -pxc) 9set -e cmd[ 1 ] 10 11if set -q cmd[ 2 ] 12and string match -q -- --schemadir$cmd [ 1 ] 13# TODO: This needs to support proper expansion of paths (~, variables, etc.) 14set schemadir --schemadir$cmd [ 2 ] 15set -e cmd[ 1..2] 16end 17 18if not set -q cmd[ 1 ] 19return 1 20end 21 22set -l subcommand$cmd [ 1 ] 23 24if not contains --$subcommand $schema_commands 25return 1 26end 27 28if not set -q cmd[ 2 ] 29# Non-relocatable schemas 30gsettings $schemadir list-schemas2> /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 '/'. 34gsettings $schemadir list-relocatable-schemas2> /dev/null| string replace -r\$ ':/' 35return 0 36end 37 38if not contains --$subcommand $key_commands 39return 1 40end 41 42set -l schema$cmd [ 2 ] 43 44if not set -q cmd[ 3 ] 45gsettings $schemadir list-keys$schema 2> /dev/null 46return 0 47end 48 49if test $subcommand != set 50return 1 51end 52 53if not set -q cmd[ 4 ] 54set -l key$cmd [ 3 ] 55set -l range( gsettings $schemadir range$schema $key 2> /dev/null) 56set -l key_type$range [ 1 ] 57set -e range[ 1 ] 58switch $key_type 59case 'type b' 60echo true 61echo false 62case enum 63string join\n $range 64case '*' 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. 67gsettings $schemadir get$schema $key 2> /dev/null 68end 69return 0 70end 71 72return 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)"