aboutsummaryrefslogtreecommitdiff
path: root/shells/bash/files/xpatch-colonbreakswords
blob: 5df21a20f97349872650d43cbfcb52f546e5cc7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--- bashline.c.orig	2009-01-08 06:29:24.000000000 -0800
+++ bashline.c	2009-03-08 01:00:50.000000000 -0800
@@ -226,6 +226,11 @@ int bash_readline_initialized = 0;
    host list. */
 int perform_hostname_completion = 1;
 
+/* If non-zero, we do hostname completion, breaking words at `@' and
+   trying to complete the stuff after the `@' from our own internal
+   host list. */
+int colon_is_wordbreak = 1;
+
 /* If non-zero, we don't do command completion on an empty line. */
 int no_empty_command_completion;
 
@@ -239,7 +244,8 @@ int dircomplete_spelling = 0;
 
 static char *bash_completer_word_break_characters = " \t\n\"'@><=;|&(:";
 static char *bash_nohostname_word_break_characters = " \t\n\"'><=;|&(:";
-/* )) */
+static char *bash_nocolon_word_break_characters = " \t\n\"'@><=;|&(";
+/* ))) */
 
 static rl_hook_func_t *old_rl_startup_hook = (rl_hook_func_t *)NULL;
 
@@ -351,6 +357,80 @@ enable_hostname_completion (on_or_off)
   return (old_value);
 }
 
+/* When this function returns, rl_completer_word_break_characters points to
+   dynamically allocated memory. */
+int
+enable_colon_wordbreak (on_or_off)
+     int on_or_off;
+{
+  int old_value;
+  char *at, *nv, *nval;
+
+  old_value = colon_is_wordbreak;
+
+  if (on_or_off)
+    {
+      colon_is_wordbreak = 1;
+      rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{";	/*}*/
+    }
+  else
+    {
+      colon_is_wordbreak = 0;
+      rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!{";	/*}*/
+    }
+
+  /* Now we need to figure out how to appropriately modify and assign
+     rl_completer_word_break_characters depending on whether we want
+     the colon to be a word break or not. */
+
+  /* If this is the first time this has been called
+     (bash_readline_initialized == 0), use the sames values as before, but
+     allocate new memory for rl_completer_word_break_characters. */
+
+  if (bash_readline_initialized == 0 &&
+      (rl_completer_word_break_characters == 0 || 
+       rl_completer_word_break_characters == rl_basic_word_break_characters))
+    {
+      if (on_or_off)
+	rl_completer_word_break_characters = savestring (bash_completer_word_break_characters);
+      else
+	rl_completer_word_break_characters = savestring (bash_nocolon_word_break_characters);
+    }
+  else
+    {
+      /* See if we have anything to do. */
+      at = strchr (rl_completer_word_break_characters, ':');
+      if ((at == 0 && on_or_off == 0) || (at != 0 && on_or_off != 0))
+        return old_value;
+
+      /* We have something to do.  Do it. */
+      nval = (char *)xmalloc (strlen (rl_completer_word_break_characters) + 1 + on_or_off);
+
+      if (on_or_off == 0)
+	{
+	  /* Turn it off -- just remove `:' from word break chars.  We want
+	     to remove all occurrences of `:' from the char list, so we loop
+	     rather than just copy the rest of the list over AT. */
+	  for (nv = nval, at = rl_completer_word_break_characters; *at; )
+	    if (*at != ':')
+	      *nv++ = *at++;
+	    else
+	      at++;
+	  *nv = '\0';
+	}
+      else
+	{
+	  nval[0] = ':';
+	  strcpy (nval + 1, rl_completer_word_break_characters);
+        }
+
+      free (rl_completer_word_break_characters);
+      rl_completer_word_break_characters = nval;
+    }
+
+  return (old_value);
+}
+
 /* Called once from parse.y if we are going to use readline. */
 void
 initialize_readline ()
@@ -517,7 +597,12 @@ initialize_readline ()
      completion is enabled. */
   enable_hostname_completion (perform_hostname_completion);
 
+  /* This sets rl_completer_word_break_characters and rl_filename_quote_characters
+     to the appropriate values, depending on whether or not a colon
+     should break completion words or not. */
+  enable_colon_wordbreak (colon_is_wordbreak);
+
   /* characters that need to be quoted when appearing in filenames. */
-  rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{~";	/*}*/
+//  rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{~";	/*}*/
   rl_filename_quoting_function = bash_quote_filename;
   rl_filename_dequoting_function = bash_dequote_filename;
--- builtins/shopt.def.orig	2009-01-13 05:43:16.000000000 -0800
+++ builtins/shopt.def	2009-03-08 01:03:39.000000000 -0800
@@ -96,6 +97,8 @@ extern int force_fignore;
 extern int dircomplete_spelling;
 
 extern int enable_hostname_completion __P((int));
+extern int colon_is_wordbreak;
+extern int enable_colon_wordbreak __P((int));
 #endif
 
 #if defined (PROGRAMMABLE_COMPLETION)
@@ -147,6 +150,9 @@ static struct {
 #if defined (READLINE)
   { "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL },
 #endif
+#if defined (READLINE)
+  { "colonbreakswords", &colon_is_wordbreak, enable_colon_wordbreak },
+#endif
   { "dotglob", &glob_dot_filenames, (shopt_set_func_t *)NULL },
   { "execfail", &no_exit_on_failed_exec, (shopt_set_func_t *)NULL },
   { "expand_aliases", &expand_aliases, (shopt_set_func_t *)NULL },
--- doc/bash.1.orig	2009-03-08 00:53:01.000000000 -0800
+++ doc/bash.1	2009-03-08 01:05:32.000000000 -0800
@@ -8473,6 +8473,18 @@ attempts to save all lines of a multiple
 command in the same history entry.  This allows
 easy re-editing of multi-line commands.
 .TP 8
+.B colonbreakswords
+If set, and
+.B readline
+is being used, \fBbash\fP will treat \fB:\fP as
+separating word being completed (see
+.B Completing
+under
+.SM
+.B READLINE
+above).
+This is enabled by default.
+.TP 8
 .B compat31
 If set,
 .B bash
--- doc/bashref.texi.orig	2009-03-08 00:53:01.000000000 -0800
+++ doc/bashref.texi	2009-03-08 01:07:00.000000000 -0800
@@ -4321,6 +4321,11 @@ attempts to save all lines of a multiple
 command in the same history entry.  This allows
 easy re-editing of multi-line commands.
 
+@item colonbreakswords
+If set, and Readline is being used, Bash will treat @samp{:} as
+separating word being completed (@pxref{Commands For Completion}).
+This option is enabled by default.
+