mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 08:11:15 -03:00
Don't include child directories of $PATH in completions
Directories are completed like commands, because of implicit cd. However, directories found inside $PATH entries should not be completed, as implicit cd doesn't work there. Similarly, directories should not be completed after the `command` builtin. Fixes #1695.
This commit is contained in:
15
complete.cpp
15
complete.cpp
@@ -412,7 +412,8 @@ public:
|
||||
void complete_cmd(const wcstring &str,
|
||||
bool use_function,
|
||||
bool use_builtin,
|
||||
bool use_command);
|
||||
bool use_command,
|
||||
bool use_implicit_cd);
|
||||
|
||||
void complete_from_args(const wcstring &str,
|
||||
const wcstring &args,
|
||||
@@ -1133,7 +1134,7 @@ static wcstring complete_function_desc(const wcstring &fn)
|
||||
|
||||
\param comp the list to add all completions to
|
||||
*/
|
||||
void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool use_builtin, bool use_command)
|
||||
void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool use_builtin, bool use_command, bool use_implicit_cd)
|
||||
{
|
||||
/* Paranoia */
|
||||
if (str_cmd.empty())
|
||||
@@ -1156,6 +1157,10 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool
|
||||
}
|
||||
}
|
||||
}
|
||||
if (use_implicit_cd)
|
||||
{
|
||||
(void)expand_string(str_cmd, this->completions, ACCEPT_INCOMPLETE | DIRECTORIES_ONLY | this->expand_flags(), NULL);
|
||||
}
|
||||
if (str_cmd.find(L'/') == wcstring::npos && str_cmd.at(0) != L'~')
|
||||
{
|
||||
if (use_command)
|
||||
@@ -1861,6 +1866,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
|
||||
bool use_command = 1;
|
||||
bool use_function = 1;
|
||||
bool use_builtin = 1;
|
||||
bool use_implicit_cd = 1;
|
||||
|
||||
//debug( 1, L"Complete '%ls'", cmd.c_str() );
|
||||
|
||||
@@ -1942,6 +1948,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
|
||||
use_command = true;
|
||||
use_function = true;
|
||||
use_builtin = true;
|
||||
use_implicit_cd = true;
|
||||
break;
|
||||
|
||||
case parse_statement_decoration_command:
|
||||
@@ -1949,19 +1956,21 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
|
||||
use_command = true;
|
||||
use_function = false;
|
||||
use_builtin = false;
|
||||
use_implicit_cd = false;
|
||||
break;
|
||||
|
||||
case parse_statement_decoration_builtin:
|
||||
use_command = false;
|
||||
use_function = false;
|
||||
use_builtin = true;
|
||||
use_implicit_cd = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd_node && cmd_node->location_in_or_at_end_of_source_range(pos))
|
||||
{
|
||||
/* Complete command filename */
|
||||
completer.complete_cmd(current_token, use_function, use_builtin, use_command);
|
||||
completer.complete_cmd(current_token, use_function, use_builtin, use_command, use_implicit_cd);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user