mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Made pwd a builtin
Fixed a thread error when autosuggesting with a command substitution
This commit is contained in:
parent
afd78f3f0b
commit
f92b24221a
2 changed files with 26 additions and 5 deletions
14
builtin.cpp
14
builtin.cpp
|
@ -1470,6 +1470,19 @@ static int builtin_echo( parser_t &parser, wchar_t **argv )
|
|||
return STATUS_BUILTIN_OK;
|
||||
}
|
||||
|
||||
/** The pwd builtin. We don't respect -P to resolve symbolic links because we try to always resolve them. */
|
||||
static int builtin_pwd( parser_t &parser, wchar_t **argv )
|
||||
{
|
||||
wchar_t dir_path[4096];
|
||||
wchar_t *res = wgetcwd( dir_path, 4096 );
|
||||
if (res == NULL) {
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
} else {
|
||||
stdout_buffer.append(dir_path);
|
||||
stdout_buffer.push_back(L'\n');
|
||||
return STATUS_BUILTIN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The function builtin, used for providing subroutines.
|
||||
|
@ -3601,6 +3614,7 @@ static const builtin_data_t builtin_datas[]=
|
|||
{ L"jobs", &builtin_jobs, N_( L"Print currently running jobs" ) },
|
||||
{ L"not", &builtin_generic, N_( L"Negate exit status of job" ) },
|
||||
{ L"or", &builtin_generic, N_( L"Execute command if previous command failed" ) },
|
||||
{ L"pwd", &builtin_pwd, N_( L"Print the working directory" ) },
|
||||
{ L"random", &builtin_random, N_( L"Generate random number" ) },
|
||||
{ L"read", &builtin_read, N_( L"Read a line of input into variables" ) },
|
||||
{ L"return", &builtin_return, N_( L"Stop the currently evaluated function" ) },
|
||||
|
|
17
complete.cpp
17
complete.cpp
|
@ -269,6 +269,14 @@ class completer_t {
|
|||
|
||||
bool condition_test( const wcstring &condition );
|
||||
|
||||
expand_flags_t expand_flags() const {
|
||||
/* Never do command substitution in autosuggestions */
|
||||
expand_flags_t result = 0;
|
||||
if (type == COMPLETE_AUTOSUGGEST)
|
||||
result |= EXPAND_SKIP_CMDSUBST;
|
||||
return result;
|
||||
}
|
||||
|
||||
void get_commands_to_load(wcstring_list_t *lst) {
|
||||
if (lst)
|
||||
lst->insert(lst->end(), commands_to_load.begin(), commands_to_load.end());
|
||||
|
@ -988,7 +996,7 @@ void completer_t::complete_cmd( const wcstring &str, bool use_function, bool use
|
|||
if( use_command && wants_description )
|
||||
{
|
||||
|
||||
if( expand_string(str, this->completions, ACCEPT_INCOMPLETE | EXECUTABLES_ONLY ) != EXPAND_ERROR )
|
||||
if( expand_string(str, this->completions, ACCEPT_INCOMPLETE | EXECUTABLES_ONLY | this->expand_flags() ) != EXPAND_ERROR )
|
||||
{
|
||||
this->complete_cmd_desc( str );
|
||||
}
|
||||
|
@ -1029,8 +1037,7 @@ void completer_t::complete_cmd( const wcstring &str, bool use_function, bool use
|
|||
|
||||
if( expand_string( nxt_completion,
|
||||
this->completions,
|
||||
ACCEPT_INCOMPLETE |
|
||||
EXECUTABLES_ONLY ) != EXPAND_ERROR )
|
||||
ACCEPT_INCOMPLETE | EXECUTABLES_ONLY | this->expand_flags() ) != EXPAND_ERROR )
|
||||
{
|
||||
for( size_t i=prev_count; i< this->completions.size(); i++ )
|
||||
{
|
||||
|
@ -1098,7 +1105,7 @@ void completer_t::complete_cmd( const wcstring &str, bool use_function, bool use
|
|||
|
||||
if( expand_string( nxt_completion,
|
||||
this->completions,
|
||||
ACCEPT_INCOMPLETE | DIRECTORIES_ONLY ) != EXPAND_ERROR )
|
||||
ACCEPT_INCOMPLETE | DIRECTORIES_ONLY | this->expand_flags() ) != EXPAND_ERROR )
|
||||
{
|
||||
}
|
||||
free(nxt_completion);
|
||||
|
@ -1489,7 +1496,7 @@ void completer_t::complete_param_expand( const wcstring &sstr, bool do_file)
|
|||
|
||||
if( expand_string( comp_str,
|
||||
this->completions,
|
||||
flags ) == EXPAND_ERROR )
|
||||
flags | this->expand_flags() ) == EXPAND_ERROR )
|
||||
{
|
||||
debug( 3, L"Error while expanding string '%ls'", comp_str );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue