mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Make sure installation path is in PATH
darcs-hash:20051103162625-ac50b-e70d6bff6a83130cd905008e65da34984bf64a7b.gz
This commit is contained in:
parent
d50c051eec
commit
d748e05cb9
1 changed files with 37 additions and 23 deletions
42
env.c
42
env.c
|
@ -343,41 +343,55 @@ void env_init()
|
|||
if( !path )
|
||||
{
|
||||
env_set( L"PATH", L"/bin" ARRAY_SEP_STR L"/usr/bin", ENV_EXPORT | ENV_GLOBAL );
|
||||
path = env_get( L"PATH" );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
int i, j;
|
||||
array_list_t l;
|
||||
int has_bin=0, has_usr_bin=0;
|
||||
|
||||
al_init( &l );
|
||||
expand_variable_array( path, &l );
|
||||
|
||||
const wchar_t *path_el[] =
|
||||
{
|
||||
L"/bin",
|
||||
L"/usr/bin",
|
||||
PREFIX L"/bin",
|
||||
0
|
||||
}
|
||||
;
|
||||
|
||||
for( j=0; path_el[j]; j++ )
|
||||
{
|
||||
int has_el=0;
|
||||
|
||||
for( i=0; i<al_get_count( &l); i++ )
|
||||
{
|
||||
wchar_t * el = (wchar_t *)al_get( &l, i );
|
||||
if( contains_str( el, L"/bin", L"/bin/", (void *)0) )
|
||||
size_t len = wcslen( el );
|
||||
while( (len > 0) && (el[len-1]==L'/') )
|
||||
len--;
|
||||
if( (wcslen( path_el[j] ) == len) && (wcsncmp( el, path_el[j], len)==0) )
|
||||
{
|
||||
has_bin = 1;
|
||||
}
|
||||
if( contains_str( el, L"/usr/bin", L"/usr/bin/", (void *)0) )
|
||||
{
|
||||
has_bin = 1;
|
||||
has_el = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( !( has_bin && has_usr_bin ) )
|
||||
if( !has_el )
|
||||
{
|
||||
string_buffer_t b;
|
||||
sb_init( &b );
|
||||
sb_append( &b, path );
|
||||
if( !has_bin )
|
||||
sb_append( &b, ARRAY_SEP_STR L"/bin" );
|
||||
if( !has_usr_bin )
|
||||
sb_append( &b, ARRAY_SEP_STR L"/usr/bin" );
|
||||
sb_append2( &b, path,
|
||||
ARRAY_SEP_STR,
|
||||
path_el[j],
|
||||
(void *)0 );
|
||||
|
||||
env_set( L"PATH", (wchar_t *)b.buff, ENV_GLOBAL | ENV_EXPORT );
|
||||
sb_destroy( &b );
|
||||
path = env_get( L"PATH" );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
al_foreach( &l, (void (*)(const void *))&free );
|
||||
|
|
Loading…
Reference in a new issue