gsettings-tool: Support completion for enum values

https://bugzilla.gnome.org/show_bug.cgi?id=631264
This commit is contained in:
Matthias Clasen 2010-10-30 01:13:42 -04:00
parent 6298e88538
commit e24dfacd5b
2 changed files with 35 additions and 0 deletions

View File

@ -38,6 +38,24 @@ __gsettings() {
;;
esac
;;
4)
case "${COMP_WORDS[1]}" in
set)
range=($(gsettings range ${COMP_WORDS[2]} ${COMP_WORDS[3]} 2> /dev/null))
case "${range[0]}" in
enum)
unset range[0]
;;
*)
unset range
;;
esac
local IFS=$'\n'
choices="${range[*]}"
;;
esac
;;
esac
local IFS=$'\n'

View File

@ -394,12 +394,27 @@ gsettings_set (GSettings *settings,
GError *error = NULL;
GVariant *existing;
GVariant *new;
gchar *freeme = NULL;
existing = g_settings_get_value (settings, key);
type = g_variant_get_type (existing);
parse:
new = g_variant_parse (type, value, NULL, NULL, &error);
/* A common error is to specify a string with single quotes
* (or use completion for that), and forget that the shell
* will eat one level of quoting, resulting in 'unknown keyword'
* error from the gvariant parser.
* To handle this case, try to parse again with an extra level
* of quotes.
*/
if (new == NULL && !freeme && strstr (error->message, "unknown keyword"))
{
value = freeme = g_strdup_printf ("\"%s\"", value);
goto parse;
}
if (new == NULL)
{
g_printerr ("%s\n", error->message);
@ -418,6 +433,8 @@ gsettings_set (GSettings *settings,
g_variant_unref (new);
g_settings_sync ();
g_free (freeme);
}
static int