Don't suggest non-directories when tab completing cd

Fixes #1059
This commit is contained in:
ridiculousfish 2014-10-31 10:44:32 -07:00
parent 7ac593273e
commit 84372ba79d
2 changed files with 12 additions and 7 deletions

View file

@ -398,7 +398,7 @@ public:
const wcstring &str, const wcstring &str,
bool use_switches); bool use_switches);
void complete_param_expand(const wcstring &str, bool do_file); void complete_param_expand(const wcstring &str, bool do_file, bool directories_only = false);
void complete_cmd(const wcstring &str, void complete_cmd(const wcstring &str,
bool use_function, bool use_function,
@ -1371,7 +1371,6 @@ struct local_options_t
}; };
bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spopt, const wcstring &sstr, bool use_switches) bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spopt, const wcstring &sstr, bool use_switches)
{ {
const wchar_t * const cmd_orig = scmd_orig.c_str(); const wchar_t * const cmd_orig = scmd_orig.c_str();
const wchar_t * const popt = spopt.c_str(); const wchar_t * const popt = spopt.c_str();
const wchar_t * const str = sstr.c_str(); const wchar_t * const str = sstr.c_str();
@ -1610,7 +1609,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop
/** /**
Perform file completion on the specified string Perform file completion on the specified string
*/ */
void completer_t::complete_param_expand(const wcstring &sstr, bool do_file) void completer_t::complete_param_expand(const wcstring &sstr, bool do_file, bool directories_only)
{ {
const wchar_t * const str = sstr.c_str(); const wchar_t * const str = sstr.c_str();
const wchar_t *comp_str; const wchar_t *comp_str;
@ -1628,6 +1627,9 @@ void completer_t::complete_param_expand(const wcstring &sstr, bool do_file)
if (! do_file) if (! do_file)
flags |= EXPAND_SKIP_WILDCARDS; flags |= EXPAND_SKIP_WILDCARDS;
if (directories_only && do_file)
flags |= DIRECTORIES_ONLY;
/* Squelch file descriptions per issue 254 */ /* Squelch file descriptions per issue 254 */
if (this->type() == COMPLETE_AUTOSUGGEST || do_file) if (this->type() == COMPLETE_AUTOSUGGEST || do_file)
@ -2001,7 +2003,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
in_redirection = (redirection != NULL); in_redirection = (redirection != NULL);
} }
bool do_file = false; bool do_file = false, directories_only = false;
if (in_redirection) if (in_redirection)
{ {
do_file = true; do_file = true;
@ -2046,7 +2048,10 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
/* If we have found no command specific completions at all, fall back to using file completions. */ /* If we have found no command specific completions at all, fall back to using file completions. */
if (completer.empty()) if (completer.empty())
do_file = true; do_file = true;
/* Hack. If we're cd, do directories only (#1059) */
directories_only = (current_command_unescape == L"cd");
/* And if we're autosuggesting, and the token is empty, don't do file suggestions */ /* And if we're autosuggesting, and the token is empty, don't do file suggestions */
if ((flags & COMPLETION_REQUEST_AUTOSUGGESTION) && current_argument_unescape.empty()) if ((flags & COMPLETION_REQUEST_AUTOSUGGESTION) && current_argument_unescape.empty())
{ {
@ -2055,7 +2060,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
} }
/* This function wants the unescaped string */ /* This function wants the unescaped string */
completer.complete_param_expand(current_token, do_file); completer.complete_param_expand(current_token, do_file, directories_only);
} }
} }
} }

View file

@ -32,7 +32,7 @@
#define NO_COMMON 2 #define NO_COMMON 2
/** /**
* Only use the argument list specifies with completion after * Only use the argument list specifies with completion after
* option. This is the same as (NO_FILES & NO_COMMON) * option. This is the same as (NO_FILES | NO_COMMON)
*/ */
#define EXCLUSIVE 3 #define EXCLUSIVE 3