aboutsummaryrefslogtreecommitdiffhomepage
path: root/complete.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-05-02 01:22:39 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-05-02 01:22:39 -0700
commit16b982958bdd648098fd433c5aec47158b7bc383 (patch)
treee386ffc71541ab4cb39950cb2145c33582990846 /complete.cpp
parent0c4819131c3c735a90a81cf774749b9b020f3a5d (diff)
Correctly complete redirections. Fixes #1296
Diffstat (limited to 'complete.cpp')
-rw-r--r--complete.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/complete.cpp b/complete.cpp
index 73d3182e..101faeec 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -1976,28 +1976,42 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
}
}
}
-
+
+ /* If we are not in an argument, we may be in a redirection */
+ bool in_redirection = false;
+ if (matching_arg_index == (size_t)(-1))
+ {
+ const parse_node_t *redirection = tree.find_node_matching_source_location(symbol_redirection, pos, plain_statement);
+ in_redirection = (redirection != NULL);
+ }
+
bool do_file = false;
-
- wcstring current_command_unescape, previous_argument_unescape, current_argument_unescape;
- if (unescape_string(current_command, &current_command_unescape, UNESCAPE_DEFAULT) &&
- unescape_string(previous_argument, &previous_argument_unescape, UNESCAPE_DEFAULT) &&
- unescape_string(current_argument, &current_argument_unescape, UNESCAPE_INCOMPLETE))
+ if (in_redirection)
{
- do_file = completer.complete_param(current_command_unescape,
- previous_argument_unescape,
- current_argument_unescape,
- !had_ddash);
+ do_file = true;
}
+ else
+ {
+ wcstring current_command_unescape, previous_argument_unescape, current_argument_unescape;
+ if (unescape_string(current_command, &current_command_unescape, UNESCAPE_DEFAULT) &&
+ unescape_string(previous_argument, &previous_argument_unescape, UNESCAPE_DEFAULT) &&
+ unescape_string(current_argument, &current_argument_unescape, UNESCAPE_INCOMPLETE))
+ {
+ do_file = completer.complete_param(current_command_unescape,
+ previous_argument_unescape,
+ current_argument_unescape,
+ !had_ddash);
+ }
- /* If we have found no command specific completions at all, fall back to using file completions. */
- if (completer.empty())
- do_file = true;
+ /* If we have found no command specific completions at all, fall back to using file completions. */
+ if (completer.empty())
+ do_file = true;
- /* And if we're autosuggesting, and the token is empty, don't do file suggestions */
- if ((flags & COMPLETION_REQUEST_AUTOSUGGESTION) && current_argument_unescape.empty())
- {
- do_file = false;
+ /* And if we're autosuggesting, and the token is empty, don't do file suggestions */
+ if ((flags & COMPLETION_REQUEST_AUTOSUGGESTION) && current_argument_unescape.empty())
+ {
+ do_file = false;
+ }
}
/* This function wants the unescaped string */