Commit e24dfacd authored by Matthias Clasen's avatar Matthias Clasen

gsettings-tool: Support completion for enum values

https://bugzilla.gnome.org/show_bug.cgi?id=631264
parent 6298e885
......@@ -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'
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment