mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
replaced the functions '--rename' option with '--copy'.
Copying the function implementation was the main point. Actually removing the original isn't necessary, as that functionality already exists (functions -e).
This commit is contained in:
parent
208be0f4d4
commit
7914c92824
3 changed files with 17 additions and 45 deletions
23
builtin.c
23
builtin.c
|
@ -1252,7 +1252,7 @@ static int builtin_functions( wchar_t **argv )
|
|||
int show_hidden=0;
|
||||
int res = STATUS_BUILTIN_OK;
|
||||
int query = 0;
|
||||
int rename = 0;
|
||||
int copy = 0;
|
||||
|
||||
woptind=0;
|
||||
|
||||
|
@ -1284,7 +1284,7 @@ static int builtin_functions( wchar_t **argv )
|
|||
}
|
||||
,
|
||||
{
|
||||
L"rename", no_argument, 0, 'r'
|
||||
L"copy", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
|
@ -1299,7 +1299,7 @@ static int builtin_functions( wchar_t **argv )
|
|||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"ed:nahqr",
|
||||
L"ed:nahqc",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
|
@ -1343,8 +1343,8 @@ static int builtin_functions( wchar_t **argv )
|
|||
query = 1;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
rename = 1;
|
||||
case 'c':
|
||||
copy = 1;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
|
@ -1356,9 +1356,9 @@ static int builtin_functions( wchar_t **argv )
|
|||
}
|
||||
|
||||
/*
|
||||
Erase, desc, query, rename and list are mutually exclusive
|
||||
Erase, desc, query, copy and list are mutually exclusive
|
||||
*/
|
||||
if( (erase + (!!desc) + list + query + rename) > 1 )
|
||||
if( (erase + (!!desc) + list + query + copy) > 1 )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Invalid combination of options\n" ),
|
||||
|
@ -1443,7 +1443,7 @@ static int builtin_functions( wchar_t **argv )
|
|||
al_destroy( &names );
|
||||
return STATUS_BUILTIN_OK;
|
||||
}
|
||||
else if( rename )
|
||||
else if( copy )
|
||||
{
|
||||
wchar_t *current_func;
|
||||
wchar_t *new_func;
|
||||
|
@ -1471,11 +1471,11 @@ static int builtin_functions( wchar_t **argv )
|
|||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
// keep things simple: don't allow existing names to be rename targets.
|
||||
// keep things simple: don't allow existing names to be copy targets.
|
||||
if( function_exists( new_func ) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Function '%ls' already exists. Cannot rename '%ls'\n" ),
|
||||
_( L"%ls: Function '%ls' already exists. Cannot create copy '%ls'\n" ),
|
||||
argv[0],
|
||||
new_func,
|
||||
current_func );
|
||||
|
@ -1484,8 +1484,9 @@ static int builtin_functions( wchar_t **argv )
|
|||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
function_rename( current_func, new_func );
|
||||
if( function_copy( current_func, new_func ) )
|
||||
return STATUS_BUILTIN_OK;
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
for( i=woptind; i<argc; i++ )
|
||||
|
|
32
function.c
32
function.c
|
@ -222,8 +222,6 @@ int function_copy( const wchar_t *name, const wchar_t *new_name )
|
|||
{
|
||||
int i;
|
||||
function_internal_data_t *d, *orig_d;
|
||||
event_t ev, *orig_ev;
|
||||
array_list_t *fn_events;
|
||||
|
||||
CHECK( name, 0 );
|
||||
CHECK( new_name, 0 );
|
||||
|
@ -245,41 +243,19 @@ int function_copy( const wchar_t *name, const wchar_t *new_name )
|
|||
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( orig_d->named_arguments, i ) ) );
|
||||
}
|
||||
d->description = orig_d->description?halloc_wcsdup(d, orig_d->description):0;
|
||||
d->shadows = orig_d->shadows;
|
||||
|
||||
// This new instance of the function shouldn't be tied to the def
|
||||
// file of the original.
|
||||
d->definition_file = 0;
|
||||
d->is_autoload = 0;
|
||||
d->shadows = orig_d->shadows;
|
||||
}
|
||||
|
||||
hash_put( &function, intern(new_name), d );
|
||||
|
||||
// wire up the same events... if any.
|
||||
ev.type = EVENT_ANY;
|
||||
ev.function_name = name;
|
||||
event_get(&ev, fn_events);
|
||||
|
||||
if( fn_events )
|
||||
{
|
||||
ev.function_name = new_name;
|
||||
|
||||
for( i=0; i<al_get_count( fn_events ); i++ )
|
||||
{
|
||||
orig_ev = (event_t *)al_get( fn_events, i );
|
||||
|
||||
// event_add_handler will deep-copy ev, so we can reuse.
|
||||
ev.type = orig_ev->type;
|
||||
ev.param1 = orig_ev->param1;
|
||||
event_add_handler( &ev );
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void function_rename( const wchar_t *name, const wchar_t *new_name )
|
||||
{
|
||||
if( function_copy( name, new_name ) )
|
||||
function_remove( name );
|
||||
}
|
||||
|
||||
|
||||
int function_exists( const wchar_t *cmd )
|
||||
{
|
||||
|
|
|
@ -137,9 +137,4 @@ int function_get_shadows( const wchar_t *name );
|
|||
*/
|
||||
int function_copy( const wchar_t *name, const wchar_t *new_name );
|
||||
|
||||
/**
|
||||
Renames the specified function.
|
||||
*/
|
||||
void function_rename( const wchar_t *name, const wchar_t *new_name );
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue