mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
gsettings-tool: Support completion for enum values
https://bugzilla.gnome.org/show_bug.cgi?id=631264
This commit is contained in:
parent
6298e88538
commit
e24dfacd5b
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user