From 4a87c9895dd35426d872466b8313bc45e7e2867e Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 13 Jul 2006 03:46:55 +1000 Subject: [PATCH] Add -q/--query switch to the functions builtin. Works just like the same switch to set does. Useful for checking for the existance of functions in a script darcs-hash:20060712174655-ac50b-14a98a15751bb5ddddf4ffb41521b616bef5e40c.gz --- builtin.c | 43 +++++++++++++++++++++----------- doc_src/functions.txt | 15 +++++++---- share/completions/functions.fish | 2 +- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/builtin.c b/builtin.c index 4b30dce07..a46fa6383 100644 --- a/builtin.c +++ b/builtin.c @@ -774,6 +774,7 @@ static int builtin_functions( wchar_t **argv ) int list=0; int show_hidden=0; int res = 0; + int query = 0; woptind=0; @@ -800,6 +801,10 @@ static int builtin_functions( wchar_t **argv ) L"help", no_argument, 0, 'h' } , + { + L"query", no_argument, 0, 'q' + } + , { 0, 0, 0, 0 } @@ -812,7 +817,7 @@ static int builtin_functions( wchar_t **argv ) int opt = wgetopt_long( argc, argv, - L"ed:nah", + L"ed:nahq", long_options, &opt_index ); if( opt == -1 ) @@ -852,6 +857,10 @@ static int builtin_functions( wchar_t **argv ) builtin_print_help( argv[0], sb_out ); return 0; + case 'q': + query = 1; + break; + case '?': builtin_print_help( argv[0], sb_err ); @@ -862,9 +871,9 @@ static int builtin_functions( wchar_t **argv ) } /* - Erase, desc and list are mutually exclusive + Erase, desc, query and list are mutually exclusive */ - if( (erase + (desc!=0) + list) > 1 ) + if( (erase + (desc!=0) + list + query) > 1 ) { sb_printf( sb_err, _( L"%ls: Invalid combination of options\n" ), @@ -951,22 +960,25 @@ static int builtin_functions( wchar_t **argv ) return 0; } - switch( argc - woptind ) { case 0: { - sb_append( sb_out, _( L"Current function definitions are:\n\n" ) ); - al_init( &names ); - function_get_names( &names, show_hidden ); - sort_list( &names ); - - for( i=0; i-e or --erase causes the specified functions to be erased. - -h or --help display a help message and exit - -n or --names list only the names of all defined functions +- -q or --query test if the specified functions exist. Does not output anything, but the builtins exit status is the number of functions specified that were not defined. -If \c functions is called with no arguments, the names and definition -of all functions are printed, otherwise, the specified function -definitions will be printed. +The default behavior of \c functions when called with no arguments, +is to print the names and definitions of all defined functions. If any +non-switch parameters are given, only the definition of the specified +functions are printed. -If a function is automatically loaded, using functions -e -to erase it will not remove the function. +Automatically loaded functions can not be removed using functions +-e. Either remove the definition file or change the +$fish_function_path variable to remove autoloaded functions. +The exit status of the functions builtin is the number functions +specified in the argument list that do not exist. diff --git a/share/completions/functions.fish b/share/completions/functions.fish index 8f5442026..e614ed39f 100644 --- a/share/completions/functions.fish +++ b/share/completions/functions.fish @@ -3,4 +3,4 @@ complete -c functions -xa "(functions -na)" -d (N_ "Function") complete -c functions -s a -l all -d (N_ "Show hidden functions") complete -c functions -s h -l help -d (N_ "Display help and exit") complete -c functions -s d -l description -d (N_ "Set function description") -x - +complete -c functions -s q -l query -d (N_ "Test if function is defined")