mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-23 03:05:13 +08:00
Got rid of multiple cd paths, only current directory will be searched while changing directories, implicit cd (entering directory just by typing it's name) is removed.
This commit is contained in:
parent
3dc56de0ae
commit
bc8a288386
@ -48,8 +48,8 @@ Functions used for implementing the set builtin.
|
||||
static int is_path_variable( const wchar_t *env )
|
||||
{
|
||||
return contains( env,
|
||||
L"PATH",
|
||||
L"CDPATH" );
|
||||
L"PATH"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1035,9 +1035,7 @@ static void complete_cmd( const wchar_t *cmd,
|
||||
std::vector<completion_t> possible_comp;
|
||||
wchar_t *nxt_completion;
|
||||
|
||||
const env_var_t cdpath = env_get_string(L"CDPATH");
|
||||
// wchar_t *cdpath_cpy = wcsdup( cdpath?cdpath:L"." );
|
||||
wchar_t *cdpath_cpy = wcsdup( !cdpath.missing()?cdpath.c_str():L"." );
|
||||
wchar_t *cdpath_cpy = wcsdup(L".");
|
||||
|
||||
if( (wcschr( cmd, L'/') != 0) || (cmd[0] == L'~' ) )
|
||||
{
|
||||
|
2
env.cpp
2
env.cpp
@ -1715,4 +1715,4 @@ const wchar_t *env_vars::get(const wchar_t *key) const
|
||||
return (iter == vars.end() ? NULL : iter->second.c_str());
|
||||
}
|
||||
|
||||
const wchar_t * const env_vars::highlighting_keys[] = {L"PATH", L"CDPATH", L"HIGHLIGHT_DELAY", L"fish_function_path", NULL};
|
||||
const wchar_t * const env_vars::highlighting_keys[] = {L"PATH", L"HIGHLIGHT_DELAY", L"fish_function_path", NULL};
|
||||
|
@ -722,16 +722,6 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
|
||||
is_cmd |= !!path_get_path_string( cmd, tmp, vars );
|
||||
}
|
||||
|
||||
/*
|
||||
Could not find the command. Maybe it is
|
||||
a path for a implicit cd command.
|
||||
*/
|
||||
if( use_builtin || (use_function && function_exists( L"cd") ) )
|
||||
{
|
||||
wcstring tmp;
|
||||
is_cmd |= !!path_get_cdpath_string( cmd, tmp, vars );
|
||||
}
|
||||
|
||||
if( is_cmd )
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMAND;
|
||||
|
27
parser.cpp
27
parser.cpp
@ -1930,31 +1930,7 @@ int parser_t::parse_job( process_t *p,
|
||||
if( p->actual_cmd == NULL )
|
||||
{
|
||||
|
||||
/*
|
||||
That is not a command! Test if it is a
|
||||
directory, in which case, we use 'cd' as the
|
||||
implicit command.
|
||||
*/
|
||||
if(path_can_get_cdpath(args.at(0).completion))
|
||||
{
|
||||
wcstring tmp = args.at(0).completion;
|
||||
// al_truncate( args, 0 );
|
||||
args.clear();
|
||||
// al_push( args, halloc_wcsdup( j, L"cd" ) );
|
||||
args.push_back(completion_t(L"cd"));
|
||||
args.push_back(completion_t(tmp));
|
||||
/*
|
||||
If we have defined a wrapper around cd, use it,
|
||||
otherwise use the cd builtin
|
||||
*/
|
||||
if( use_function && function_exists( L"cd" ) )
|
||||
p->type = INTERNAL_FUNCTION;
|
||||
else
|
||||
p->type = INTERNAL_BUILTIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
int tmp;
|
||||
int tmp;
|
||||
const wchar_t *cmd = args.at( 0 ).completion.c_str();
|
||||
|
||||
/*
|
||||
@ -2038,7 +2014,6 @@ int parser_t::parse_job( process_t *p,
|
||||
job_set_flag( j, JOB_SKIP, 1 );
|
||||
event_fire_generic(L"fish_command_not_found", (wchar_t *)( args.at( 0 ).completion.c_str() ) );
|
||||
proc_set_last_status( err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
path.cpp
14
path.cpp
@ -291,11 +291,8 @@ bool path_get_cdpath_string(const wcstring &dir_str, wcstring &result, const env
|
||||
}
|
||||
else
|
||||
{
|
||||
const wchar_t *path = vars.get(L"CDPATH");
|
||||
if( !path || !wcslen(path) )
|
||||
{
|
||||
path = L".";
|
||||
}
|
||||
|
||||
const wchar_t *path = L".";
|
||||
|
||||
wcstokenizer tokenizer(path, ARRAY_SEP_STR);
|
||||
wcstring next_path;
|
||||
@ -340,6 +337,7 @@ bool path_get_cdpath_string(const wcstring &dir_str, wcstring &result, const env
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
wchar_t *path_allocate_cdpath( const wchar_t *dir )
|
||||
{
|
||||
wchar_t *res = 0;
|
||||
@ -371,9 +369,7 @@ wchar_t *path_allocate_cdpath( const wchar_t *dir )
|
||||
wchar_t *state;
|
||||
wchar_t *whole_path;
|
||||
|
||||
env_var_t path = env_get_string(L"CDPATH");
|
||||
if( path.missing_or_empty() )
|
||||
path = L".";
|
||||
env_var_t path = L".";
|
||||
|
||||
nxt_path = path.c_str();
|
||||
path_cpy = wcsdup( path.c_str() );
|
||||
@ -439,6 +435,7 @@ wchar_t *path_allocate_cdpath( const wchar_t *dir )
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool path_can_get_cdpath(const wcstring &in) {
|
||||
wchar_t *tmp = path_allocate_cdpath(in.c_str());
|
||||
bool result = (tmp != NULL);
|
||||
@ -486,6 +483,7 @@ wchar_t *path_get_config( void *context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool path_get_config(wcstring &path)
|
||||
{
|
||||
int done = 0;
|
||||
|
1
path.h
1
path.h
@ -53,6 +53,7 @@ bool path_get_path_string(const wcstring &cmd, wcstring &output, const env_vars
|
||||
\param in The name of the directory.
|
||||
\return 0 if the command can not be found, the path of the command otherwise. The path should be free'd with free().
|
||||
*/
|
||||
|
||||
wchar_t *path_allocate_cdpath( const wchar_t *in );
|
||||
bool path_can_get_cdpath(const wcstring &in);
|
||||
bool path_get_cdpath_string(const wcstring &in, wcstring &out, const env_vars &vars);
|
||||
|
Loading…
x
Reference in New Issue
Block a user