mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
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
This commit is contained in:
parent
036cc4e0fa
commit
4a87c9895d
3 changed files with 40 additions and 20 deletions
43
builtin.c
43
builtin.c
|
@ -774,6 +774,7 @@ static int builtin_functions( wchar_t **argv )
|
||||||
int list=0;
|
int list=0;
|
||||||
int show_hidden=0;
|
int show_hidden=0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
int query = 0;
|
||||||
|
|
||||||
woptind=0;
|
woptind=0;
|
||||||
|
|
||||||
|
@ -800,6 +801,10 @@ static int builtin_functions( wchar_t **argv )
|
||||||
L"help", no_argument, 0, 'h'
|
L"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
|
{
|
||||||
|
L"query", no_argument, 0, 'q'
|
||||||
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
|
@ -812,7 +817,7 @@ static int builtin_functions( wchar_t **argv )
|
||||||
|
|
||||||
int opt = wgetopt_long( argc,
|
int opt = wgetopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
L"ed:nah",
|
L"ed:nahq",
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
|
@ -852,6 +857,10 @@ static int builtin_functions( wchar_t **argv )
|
||||||
builtin_print_help( argv[0], sb_out );
|
builtin_print_help( argv[0], sb_out );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case 'q':
|
||||||
|
query = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
builtin_print_help( argv[0], sb_err );
|
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,
|
sb_printf( sb_err,
|
||||||
_( L"%ls: Invalid combination of options\n" ),
|
_( L"%ls: Invalid combination of options\n" ),
|
||||||
|
@ -951,22 +960,25 @@ static int builtin_functions( wchar_t **argv )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch( argc - woptind )
|
switch( argc - woptind )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
sb_append( sb_out, _( L"Current function definitions are:\n\n" ) );
|
if( !query )
|
||||||
al_init( &names );
|
|
||||||
function_get_names( &names, show_hidden );
|
|
||||||
sort_list( &names );
|
|
||||||
|
|
||||||
for( i=0; i<al_get_count( &names ); i++ )
|
|
||||||
{
|
{
|
||||||
functions_def( (wchar_t *)al_get( &names, i ) );
|
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<al_get_count( &names ); i++ )
|
||||||
|
{
|
||||||
|
functions_def( (wchar_t *)al_get( &names, i ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
al_destroy( &names );
|
||||||
}
|
}
|
||||||
|
|
||||||
al_destroy( &names );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -978,8 +990,11 @@ static int builtin_functions( wchar_t **argv )
|
||||||
res++;
|
res++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
functions_def( argv[i] );
|
if( !query )
|
||||||
}
|
{
|
||||||
|
functions_def( argv[i] );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -12,11 +12,16 @@ This builtin command is used to print or erase functions.
|
||||||
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
|
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
|
||||||
- <code>-h</code> or <code>--help</code> display a help message and exit
|
- <code>-h</code> or <code>--help</code> display a help message and exit
|
||||||
- <code>-n</code> or <code>--names</code> list only the names of all defined functions
|
- <code>-n</code> or <code>--names</code> list only the names of all defined functions
|
||||||
|
- <code>-q</code> or <code>--query</code> 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
|
The default behavior of \c functions when called with no arguments,
|
||||||
of all functions are printed, otherwise, the specified function
|
is to print the names and definitions of all defined functions. If any
|
||||||
definitions will be printed.
|
non-switch parameters are given, only the definition of the specified
|
||||||
|
functions are printed.
|
||||||
|
|
||||||
If a function is automatically loaded, using <code>functions -e</code>
|
Automatically loaded functions can not be removed using functions
|
||||||
to erase it will not remove the function.
|
-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.
|
||||||
|
|
|
@ -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 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 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 d -l description -d (N_ "Set function description") -x
|
||||||
|
complete -c functions -s q -l query -d (N_ "Test if function is defined")
|
||||||
|
|
Loading…
Reference in a new issue