d7e0d2
From f224dd99c7dc4d2ce4340b2d16cae6b1e0ed7c8d Mon Sep 17 00:00:00 2001
d7e0d2
From: Pino Toscano <ptoscano@redhat.com>
d7e0d2
Date: Fri, 17 May 2019 15:18:50 +0200
d7e0d2
Subject: [PATCH] * src/augtool.c: hopefully fix readline quoting issues
d7e0d2
d7e0d2
Configure the quoting (also using a detector) and word break characters,
d7e0d2
so it is possible to autocomplete paths with special characters (like
d7e0d2
spaces, which are already quoted by augeas).
d7e0d2
---
d7e0d2
 src/augtool.c | 12 ++++++++++++
d7e0d2
 1 file changed, 12 insertions(+)
d7e0d2
d7e0d2
diff --git a/src/augtool.c b/src/augtool.c
d7e0d2
index b42ef630..31a991eb 100644
d7e0d2
--- a/src/augtool.c
d7e0d2
+++ b/src/augtool.c
d7e0d2
@@ -267,10 +267,22 @@ static char *get_home_dir(uid_t uid) {
d7e0d2
     return result;
d7e0d2
 }
d7e0d2
 
d7e0d2
+/* Inspired from:
d7e0d2
+ * https://thoughtbot.com/blog/tab-completion-in-gnu-readline
d7e0d2
+ */
d7e0d2
+static int quote_detector(char *str, int index) {
d7e0d2
+    return index > 0
d7e0d2
+           && str[index - 1] == '\\'
d7e0d2
+           && quote_detector(str, index - 1) == 0;
d7e0d2
+}
d7e0d2
+
d7e0d2
 static void readline_init(void) {
d7e0d2
     rl_readline_name = "augtool";
d7e0d2
     rl_attempted_completion_function = readline_completion;
d7e0d2
     rl_completion_entry_function = readline_path_generator;
d7e0d2
+    rl_completer_quote_characters = "\"'";
d7e0d2
+    rl_completer_word_break_characters = (char *) " ";
d7e0d2
+    rl_char_is_quoted_p = &quote_detector;
d7e0d2
 
d7e0d2
     /* Set up persistent history */
d7e0d2
     char *home_dir = get_home_dir(getuid());
d7e0d2
-- 
d7e0d2
2.24.1
d7e0d2