From d33229324517aff751901d83aa66c6f24eba0bdc Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 25 Oct 2005 19:39:45 +1000 Subject: [PATCH] Make sure PATH contains vital directories during init darcs-hash:20051025093945-ac50b-8939b844e472caf43a206e2a0dbfa0d48ffdd45c.gz --- common.h | 1 + env.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++--- init/fish.in | 7 ++----- main.c | 2 +- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/common.h b/common.h index 09e478a8b..60690ba4d 100644 --- a/common.h +++ b/common.h @@ -67,6 +67,7 @@ extern char *profile; debug function. */ extern wchar_t *program_name; + /** Take an array_list_t containing wide strings and converts them to a wchar_t **. */ diff --git a/env.c b/env.c index b60208d63..e4688cfb2 100644 --- a/env.c +++ b/env.c @@ -258,7 +258,7 @@ void env_init() { char **p; struct passwd *pw; - wchar_t *uname; + wchar_t *uname, *path; sb_init( &dyn_var ); @@ -312,12 +312,13 @@ void env_init() wchar_t *pos; key = str2wcs(*p); - + if( !key ) continue; val = wcschr( key, L'=' ); + if( val == 0 ) env_set( key, L"", ENV_EXPORT ); else @@ -332,11 +333,59 @@ void env_init() *pos = ARRAY_SEP; pos++; } - + env_set( key, val, ENV_EXPORT | ENV_GLOBAL ); } free(key); } + + path = env_get( L"PATH" ); + if( !path ) + { + env_set( L"PATH", L"/bin" ARRAY_SEP_STR L"/usr/bin", ENV_EXPORT | ENV_GLOBAL ); + } + else + { + int i; + array_list_t l; + int has_bin=0, has_usr_bin=0; + + al_init( &l ); + expand_variable_array( path, &l ); + + for( i=0; ipw_name ); diff --git a/init/fish.in b/init/fish.in index 573b1aaac..c4014d5c0 100644 --- a/init/fish.in +++ b/init/fish.in @@ -7,8 +7,7 @@ # Set default field separators # -set IFS \ \t\n - +set -g IFS \ \t\n # # Add a few common directories to path, if they exists. Note that pure @@ -18,14 +17,12 @@ set IFS \ \t\n for i in /bin /usr/bin /usr/X11R6/bin @PREFIX@/bin if test -d $i - if echo $PATH|grep $i >/dev/null - else + if not echo $PATH|grep $i >/dev/null set PATH $PATH $i end end end - # # Set some value for LANG if nothing was set before # diff --git a/main.c b/main.c index a5f657154..a2ebb9b58 100644 --- a/main.c +++ b/main.c @@ -217,7 +217,7 @@ int main( int argc, char **argv ) function_init(); env_init(); complete_init(); - reader_init(); + reader_init(); reader_push_current_filename( L"(internal)" );