>From be1ff9edf02d7a28b1a4d18d8e996ef4ba56c490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Fri, 27 May 2011 15:00:19 +0200 Subject: [PATCH 3/3] Registered readline "rl_completion_word_break_hook" in bash under "word_break_completion_hook". If the -B flag of the 'complete' builtin has been used, its value is returned and is used by readline to split the word to complete. It allows registration of a $COMP_WORDBREAKS equivalent on a per-completion basis. Eg: It is now possible, without messing-up with $COMP_WORDBREAKS, to use the following in a completion script: _comp() { [...] COMPREPLY=( $(compgen -W "http://foo http://bar" -- "$cur") ) return 0 } then register a completion using: $ complete -F _comp -B "${COMP_WORDBREAKS//:/}" comp --- bashline.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/bashline.c b/bashline.c index 59278e5..692b912 100644 --- a/bashline.c +++ b/bashline.c @@ -132,6 +132,7 @@ static void display_shell_completion_footer __P((void)); static char *variable_completion_function __P((const char *, int)); static char *hostname_completion_function __P((const char *, int)); static char *command_subst_completion_function __P((const char *, int)); +static char *word_break_completion_hook __P((void)); static void build_history_completion_array __P((void)); static char *history_completion_generator __P((const char *, int)); @@ -516,6 +517,12 @@ initialize_readline () /* Tell the filename completer we want a chance to ignore some names. */ rl_ignore_some_completions_function = filename_completion_ignore; + /* returns the break characters readline will use to split words. + Instead of using COMP_WORDBREAKS, this function uses the value specified + with the -B flag of the 'complete' builtin (or return 0 otherwise). + So there is no need to alter $COMP_WORDBREAKS in the user shell environment */ + rl_completion_word_break_hook = word_break_completion_hook; + /* Bind C-xC-e to invoke emacs and run result as commands. */ rl_bind_key_if_unbound_in_map (CTRL ('E'), emacs_edit_and_execute_command, emacs_ctlx_keymap); #if defined (VI_MODE) @@ -576,6 +583,7 @@ bashline_reset () rl_completion_entry_function = NULL; rl_directory_rewrite_hook = bash_directory_completion_hook; rl_ignore_some_completions_function = filename_completion_ignore; + rl_completion_word_break_hook = word_break_completion_hook; } /* Contains the line to push into readline. */ @@ -2848,6 +2856,18 @@ bash_directory_completion_hook (dirname) return (return_value); } +char *word_break_completion_hook(void) { + COMPSPEC *cs; + int start = 0; + int s = find_cmd_start (start); + char *n = find_cmd_name (s); + + cs = progcomp_search (n); + if(cs && cs->word_breaks) + return cs->word_breaks; + return 0; +} + static char **history_completion_array = (char **)NULL; static int harry_size; static int harry_len; -- 1.7.3.4