[glib] gsettings-tool: Support completion for enum values
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gsettings-tool: Support completion for enum values
- Date: Sat, 30 Oct 2010 05:15:06 +0000 (UTC)
commit e24dfacd5b81ee0b6b596df3739df4448e5bbf04
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Oct 30 01:13:42 2010 -0400
gsettings-tool: Support completion for enum values
https://bugzilla.gnome.org/show_bug.cgi?id=631264
gio/gsettings-bash-completion.sh | 18 ++++++++++++++++++
gio/gsettings-tool.c | 17 +++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/gio/gsettings-bash-completion.sh b/gio/gsettings-bash-completion.sh
index e2b8da4..00f1ca4 100644
--- a/gio/gsettings-bash-completion.sh
+++ b/gio/gsettings-bash-completion.sh
@@ -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'
diff --git a/gio/gsettings-tool.c b/gio/gsettings-tool.c
index 5042d1c..e461925 100644
--- a/gio/gsettings-tool.c
+++ b/gio/gsettings-tool.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]