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