2017-04-30 23:48:41 +00:00
# Fish completions for glibs's "gsettings" configuration tool
function __fish_complete_gsettings_args
set -l schema_commands get monitor writable range describe set reset reset -recursively list-keys list-children list-recursively
set -l key_commands get monitor writable range describe set reset
set -l schemadir
set -l cmd ( commandline -poc )
set -e cmd [ 1 ]
if set -q cmd [ 2 ]
2020-03-09 18:36:12 +00:00
and string match -q -- --schemadir $cmd [ 1 ]
2017-04-30 23:48:41 +00:00
# TODO: This needs to support proper expansion of paths (~, variables, etc.)
set schemadir --schemadir $cmd [ 2 ]
set -e cmd [ 1 .. 2 ]
end
if not set -q cmd [ 1 ]
return 1
end
set -l subcommand $cmd [ 1 ]
if not contains -- $subcommand $schema_commands
return 1
end
if not set -q cmd [ 2 ]
# Non-relocatable schemas
2018-04-01 20:42:38 +00:00
gsettings $schemadir list-schemas 2 > /dev/null
2017-04-30 23:48:41 +00:00
# Relocatable schemas require a dconf path, but there is no universal way of
# finding the right paths to suggest here. Just default to '/'.
2018-04-01 20:42:38 +00:00
gsettings $schemadir list-relocatable-schemas 2 > /dev/null | string replace -r \$ ':/'
2017-04-30 23:48:41 +00:00
return 0
end
if not contains -- $subcommand $key_commands
return 1
end
set -l schema $cmd [ 2 ]
if not set -q cmd [ 3 ]
2018-04-01 20:42:38 +00:00
gsettings $schemadir list-keys $schema 2 > /dev/null
2017-04-30 23:48:41 +00:00
return 0
end
2020-03-09 18:36:12 +00:00
if test $subcommand != set
2017-04-30 23:48:41 +00:00
return 1
end
if not set -q cmd [ 4 ]
set -l key $cmd [ 3 ]
2018-04-01 20:42:38 +00:00
set -l range ( gsettings $schemadir range $schema $key 2 > /dev/null)
2017-04-30 23:48:41 +00:00
set -l key_type $range [ 1 ]
set -e range [ 1 ]
switch $key_type
2019-05-05 10:53:09 +00:00
case 'type b'
echo true
echo false
2020-03-09 18:36:12 +00:00
case enum
2019-05-05 10:53:09 +00:00
string join \n $range
case '*'
# If no sensible suggestions can be made, just use the current value.
# It gives a good indication on the expected format and is likely already close to what the user wants.
gsettings $schemadir get $schema $key 2 > /dev/null
2017-04-30 23:48:41 +00:00
end
return 0
end
return 1
end
set -l valid_commands get monitor writable range describe set reset reset -recursively list-schemas list-relocatable-schemas list-keys list-children list-recursively help
2020-03-07 06:56:26 +00:00
complete -f -c gsettings
2017-04-30 23:48:41 +00:00
2020-03-09 18:36:12 +00:00
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -l version -d 'Print the version information'
complete -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -l schemadir -d 'Specify a custom schemas directory' -xa "(__fish_complete_directories (commandline -ct))"
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a get -d 'Get the value of a key'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a writable -d 'Determine if a key is writable'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a range -d 'Determine the valid value range of a key'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a describe -d 'Print the description of a key'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a set -d 'Set the value of a key'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a reset -d 'Reset a key to its default value'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a reset-recursively -d 'Reset all keys under the given schema'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a list-schemas -d 'List all installed, non-relocatable schemas'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a list-relocatable-schemas -d 'List all installed, relocatable schemas'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a list-keys -d 'List all keys in a schema'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a list-children -d 'List all children of a schema'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a list-recursively -d 'List keys and values, recursively'
complete -f -c gsettings -n " not __fish_seen_subcommand_from $valid_commands " -a help -d 'Print help'
2017-04-30 23:48:41 +00:00
complete -f -c gsettings -n " __fish_seen_subcommand_from $valid_commands " -xa "(__fish_complete_gsettings_args)"