mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Move the complete builtin to it's own file, and make it accept multiple -c, -p, -s, -o and -l switches
darcs-hash:20060122211055-ac50b-6ef8cff7fb02e974d6a8096bf83bcbed429d7322.gz
This commit is contained in:
parent
3e3541a05a
commit
0dadd83fdd
8 changed files with 574 additions and 353 deletions
|
@ -64,7 +64,7 @@ COMMON_OBJS := function.o builtin.o common.o complete.o env.o exec.o \
|
|||
COMMON_OBJS_WITH_HEADER := builtin_help.o
|
||||
|
||||
# main.c exists, but main.h does not, etc.
|
||||
COMMON_OBJS_WITH_CODE := builtin_set.o builtin_commandline.o builtin_ulimit.c
|
||||
COMMON_OBJS_WITH_CODE := builtin_set.o builtin_commandline.o builtin_ulimit.c builtin_complete.o
|
||||
|
||||
# All objects that the system needs to build fish
|
||||
FISH_OBJS := $(COMMON_OBJS) $(COMMON_OBJS_WITH_CODE) $(COMMON_OBJS_WITH_HEADER) main.o
|
||||
|
|
254
builtin.c
254
builtin.c
|
@ -1960,258 +1960,7 @@ static int builtin_cd( wchar_t **argv )
|
|||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
The complete builtin. Used for specifying programmable
|
||||
tab-completions. Calls the functions in complete.c for any heavy
|
||||
lifting.
|
||||
*/
|
||||
static int builtin_complete( wchar_t **argv )
|
||||
{
|
||||
|
||||
int argc=0;
|
||||
int result_mode=SHARED, long_mode=0;
|
||||
int cmd_type=-1;
|
||||
int remove = 0;
|
||||
int authorative = 1;
|
||||
|
||||
wchar_t *cmd=0, short_opt=L'\0', *long_opt=L"", *comp=L"", *desc=L"", *condition=L"", *load=0;
|
||||
|
||||
argc = builtin_count_args( argv );
|
||||
|
||||
woptind=0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
const static struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"exclusive", no_argument, 0, 'x'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"no-files", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"require-parameter", no_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"path", required_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"command", required_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"short-option", required_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"long-option", required_argument, 0, 'l' }
|
||||
,
|
||||
{
|
||||
L"old-option", required_argument, 0, 'o'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"description", required_argument, 0, 'd'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"arguments", required_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"erase", no_argument, 0, 'e'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unauthorative", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"condition", required_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"load", required_argument, 0, 'y'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"a:c:p:s:l:o:d:frxeun:y:",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
if(long_options[opt_index].flag != 0)
|
||||
break;
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
case 'x':
|
||||
result_mode |= EXCLUSIVE;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
result_mode |= NO_FILES;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
result_mode |= NO_COMMON;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
cmd_type = PATH;
|
||||
cmd = expand_unescape( woptarg, 1);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
cmd_type = COMMAND;
|
||||
cmd = expand_unescape( woptarg, 1);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
desc = woptarg;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
authorative=0;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if( wcslen( woptarg ) > 1 )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Parameter '%ls' is too long\n" ),
|
||||
argv[0],
|
||||
woptarg );
|
||||
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
short_opt = woptarg[0];
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
long_opt = woptarg;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
long_mode=1;
|
||||
long_opt = woptarg;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
comp = woptarg;
|
||||
break;
|
||||
|
||||
|
||||
case 'e':
|
||||
remove = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
condition = woptarg;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
load = woptarg;
|
||||
break;
|
||||
|
||||
|
||||
case '?':
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( woptind != argc )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Too many arguments\n" ),
|
||||
argv[0] );
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( load )
|
||||
{
|
||||
complete_load( load, 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if( cmd == 0 )
|
||||
{
|
||||
/* No arguments specified, meaning we print the definitions of
|
||||
* all specified completions to stdout.*/
|
||||
complete_print( sb_out );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( remove )
|
||||
{
|
||||
/* Remove the specified completion */
|
||||
complete_remove( cmd,
|
||||
cmd_type,
|
||||
short_opt,
|
||||
long_opt );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add the specified completion */
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
short_opt,
|
||||
long_opt,
|
||||
long_mode,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
free( cmd );
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
The . (dot) builtin, sometimes called source. Evaluates the contents of a file.
|
||||
|
@ -2321,8 +2070,7 @@ static int builtin_fg( wchar_t **argv )
|
|||
if( argv[1] == 0 )
|
||||
{
|
||||
/*
|
||||
Select last constructed job (I.e. first job in the job que)
|
||||
that is possible to put in the foreground
|
||||
Select last constructed job (I.e. first job in the job que) that is possible to put in the foreground
|
||||
*/
|
||||
for( j=first_job; j; j=j->next )
|
||||
{
|
||||
|
|
|
@ -146,6 +146,13 @@ int builtin_commandline(wchar_t **argv);
|
|||
*/
|
||||
int builtin_ulimit(wchar_t **argv);
|
||||
|
||||
/**
|
||||
The complete builtin. Used for specifying programmable
|
||||
tab-completions. Calls the functions in complete.c for any heavy
|
||||
lifting.
|
||||
*/
|
||||
int builtin_complete(wchar_t **argv);
|
||||
|
||||
/**
|
||||
This function works like wperror, but it prints its result into
|
||||
the sb_err string_buffer_t instead of to stderr. Used by the builtin
|
||||
|
|
466
builtin_complete.c
Normal file
466
builtin_complete.c
Normal file
|
@ -0,0 +1,466 @@
|
|||
/** \file builtin_commandline.c Functions defining the complete builtin
|
||||
|
||||
Functions used for implementing the complete builtin.
|
||||
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "complete.h"
|
||||
#include "wgetopt.h"
|
||||
#include "parser.h"
|
||||
#include "translate.h"
|
||||
|
||||
|
||||
static void builtin_complete_add2( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt,
|
||||
int result_mode,
|
||||
int authorative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc )
|
||||
{
|
||||
int i;
|
||||
const wchar_t *s;
|
||||
|
||||
for( s=short_opt; *s; s++ )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( gnu_opt ); i++ )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
(wchar_t *)al_get(gnu_opt, i ),
|
||||
0,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( old_opt ); i++ )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
(wchar_t *)al_get(old_opt, i ),
|
||||
1,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
}
|
||||
|
||||
static void builtin_complete_add( array_list_t *cmd,
|
||||
array_list_t *path,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt,
|
||||
int result_mode,
|
||||
int authorative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; i<al_get_count( cmd ); i++ )
|
||||
{
|
||||
builtin_complete_add2( al_get( cmd, i ),
|
||||
COMMAND,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( path ); i++ )
|
||||
{
|
||||
builtin_complete_add2( al_get( path, i ),
|
||||
PATH,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void builtin_complete_remove3( wchar_t *cmd,
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
array_list_t *long_opt )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; i<al_get_count( long_opt ); i++ )
|
||||
{
|
||||
complete_remove( cmd,
|
||||
cmd_type,
|
||||
short_opt,
|
||||
(wchar_t *)al_get( long_opt, i ) );
|
||||
}
|
||||
}
|
||||
|
||||
static void builtin_complete_remove2( wchar_t *cmd,
|
||||
int cmd_type,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt )
|
||||
{
|
||||
const wchar_t *s = (wchar_t *)short_opt;
|
||||
if( *s )
|
||||
{
|
||||
for( ; *s; s++ )
|
||||
{
|
||||
if( al_get_count( old_opt) + al_get_count( gnu_opt ) == 0 )
|
||||
{
|
||||
complete_remove(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0 );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
gnu_opt );
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
old_opt );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
gnu_opt );
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
old_opt );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void builtin_complete_remove( array_list_t *cmd,
|
||||
array_list_t *path,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt )
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for( i=0; i<al_get_count( cmd ); i++ )
|
||||
{
|
||||
builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
|
||||
COMMAND,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( path ); i++ )
|
||||
{
|
||||
builtin_complete_remove2( (wchar_t *)al_get( path, i ),
|
||||
PATH,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int builtin_complete( wchar_t **argv )
|
||||
{
|
||||
|
||||
int argc=0;
|
||||
int result_mode=SHARED;
|
||||
int remove = 0;
|
||||
int authorative = 1;
|
||||
|
||||
string_buffer_t short_opt;
|
||||
array_list_t gnu_opt, old_opt;
|
||||
wchar_t *comp=L"", *desc=L"", *condition=L"", *load=0;
|
||||
|
||||
array_list_t cmd;
|
||||
array_list_t path;
|
||||
|
||||
al_init( &cmd );
|
||||
al_init( &path );
|
||||
sb_init( &short_opt );
|
||||
al_init( &gnu_opt );
|
||||
al_init( &old_opt );
|
||||
|
||||
argc = builtin_count_args( argv );
|
||||
|
||||
woptind=0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
const static struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"exclusive", no_argument, 0, 'x'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"no-files", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"require-parameter", no_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"path", required_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"command", required_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"short-option", required_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"long-option", required_argument, 0, 'l' }
|
||||
,
|
||||
{
|
||||
L"old-option", required_argument, 0, 'o'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"description", required_argument, 0, 'd'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"arguments", required_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"erase", no_argument, 0, 'e'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unauthorative", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"condition", required_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"load", required_argument, 0, 'y'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"a:c:p:s:l:o:d:frxeun:y:",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
if(long_options[opt_index].flag != 0)
|
||||
break;
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
case 'x':
|
||||
result_mode |= EXCLUSIVE;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
result_mode |= NO_FILES;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
result_mode |= NO_COMMON;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
al_push( &cmd, unescape( woptarg, 1));
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
al_push( &cmd, unescape( woptarg, 1) );
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
desc = woptarg;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
authorative=0;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sb_append( &short_opt, woptarg );
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
al_push( &gnu_opt, woptarg );
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
al_push( &old_opt, woptarg );
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
comp = woptarg;
|
||||
break;
|
||||
|
||||
|
||||
case 'e':
|
||||
remove = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
condition = woptarg;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
load = woptarg;
|
||||
break;
|
||||
|
||||
|
||||
case '?':
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( woptind != argc )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Too many arguments\n" ),
|
||||
argv[0] );
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( load )
|
||||
{
|
||||
complete_load( load, 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) )
|
||||
{
|
||||
/* No arguments specified, meaning we print the definitions of
|
||||
* all specified completions to stdout.*/
|
||||
complete_print( sb_out );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( remove )
|
||||
{
|
||||
builtin_complete_remove( &cmd,
|
||||
&path,
|
||||
(wchar_t *)short_opt.buff,
|
||||
&gnu_opt,
|
||||
&old_opt );
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_add( &cmd,
|
||||
&path,
|
||||
(wchar_t *)short_opt.buff,
|
||||
&gnu_opt,
|
||||
&old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
|
||||
}
|
||||
al_foreach( &cmd, (void (*)(const void *))&free );
|
||||
al_foreach( &path, (void (*)(const void *))&free );
|
||||
|
||||
al_destroy( &cmd );
|
||||
al_destroy( &path );
|
||||
sb_destroy( &short_opt );
|
||||
al_destroy( &gnu_opt );
|
||||
al_destroy( &old_opt );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -435,9 +435,9 @@ void complete_add( const wchar_t *cmd,
|
|||
opt->result_mode = result_mode;
|
||||
opt->old_mode=old_mode;
|
||||
|
||||
opt->comp = intern(comp);
|
||||
opt->condition = intern(condition);
|
||||
opt->long_opt = intern( long_opt );
|
||||
opt->comp = intern(comp?comp:L"");
|
||||
opt->condition = intern(condition?condition:L"");
|
||||
opt->long_opt = intern( long_opt?long_opt:L"" );
|
||||
|
||||
if( desc && wcslen( desc ) )
|
||||
{
|
||||
|
|
|
@ -34,9 +34,10 @@ library. These styles are:
|
|||
- Old style long options, like '-Wall'. Old style long options are more than one character long, are preceeded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('-ao null').
|
||||
- GNU style long options, like '--colors'. GNU style long options are more than one character long, are preceeded by two hyphens, and may not be grouped together. Option arguments may be specified in the following parameter ('--quoting-style shell') or by appending the option with a '=' and the value ('--quoting-style=shell'). GNU style long options may be abbrevated so long as the abbrevation is unique ('--h' is equivalent to '--help' if help is the only long option beginning with an 'h').
|
||||
|
||||
\c complete only allows one of old style long options and GNU style
|
||||
long options to be used on a specific command, but short options can
|
||||
always be specified.
|
||||
The options for specifying command name, command path, or command
|
||||
switches may all be used multiple times to specify multiple commands
|
||||
which have the same completion or multiple switches accepted by a
|
||||
command.
|
||||
|
||||
When erasing completions, it is possible to either erase all
|
||||
completions for a specific command by specifying <tt>complete -e -c
|
||||
|
|
|
@ -7,100 +7,99 @@
|
|||
set -l is_gnu
|
||||
ls --version >/dev/null ^/dev/null; and set is_gnu --is-gnu
|
||||
|
||||
for i in ls ll la
|
||||
set -l cmds -c ls -c ll -c la
|
||||
|
||||
# Shared ls switches
|
||||
# Shared ls switches
|
||||
|
||||
__fish_gnu_complete -c $i -s a -l all -d (_ "Show hidden") $is_gnu
|
||||
__fish_gnu_complete -c $i -s A -l almost-all -d (_ "Show hidden except . and ..") $is_gnu
|
||||
__fish_gnu_complete -c $i -s F -l classify -d (_ "Append filetype indicator") $is_gnu
|
||||
__fish_gnu_complete -c $i -s H -l dereference-command-line -d (_ "Follow symlinks") $is_gnu
|
||||
__fish_gnu_complete -c $i -s L -l dereference -d (_ "Follow symlinks") $is_gnu
|
||||
__fish_gnu_complete -c $i -s R -l recursive -d (_ "List subdirectory recursively") $is_gnu
|
||||
__fish_gnu_complete -c $i -s b -l escape -d (_ "Octal escapes for non graphic characters") $is_gnu
|
||||
__fish_gnu_complete -c $i -s d -l directory -d (_ "List directories, not their content") $is_gnu
|
||||
__fish_gnu_complete -c $i -s h -l human-readable -d (_ "Human readable sizes") $is_gnu
|
||||
__fish_gnu_complete -c $i -s i -l inode -d (_ "Print inode number of files") $is_gnu
|
||||
__fish_gnu_complete -c $i -s n -l numeric-uid-gid -d (_ "Long format, numeric IDs") $is_gnu
|
||||
__fish_gnu_complete -c $i -s p -l file-type -d (_ "Append filetype indicator") $is_gnu
|
||||
__fish_gnu_complete -c $i -s q -l hide-control-chars -d (_ "Replace non-graphic characters with '?'") $is_gnu
|
||||
__fish_gnu_complete -c $i -s r -l reverse -d (_ "Reverse sort order") $is_gnu
|
||||
__fish_gnu_complete -c $i -s s -l size -d (_ "Print size of files") $is_gnu
|
||||
__fish_gnu_complete $cmds -s a -l all -d (_ "Show hidden") $is_gnu
|
||||
__fish_gnu_complete $cmds -s A -l almost-all -d (_ "Show hidden except . and ..") $is_gnu
|
||||
__fish_gnu_complete $cmds -s F -l classify -d (_ "Append filetype indicator") $is_gnu
|
||||
__fish_gnu_complete $cmds -s H -l dereference-command-line -d (_ "Follow symlinks") $is_gnu
|
||||
__fish_gnu_complete $cmds -s L -l dereference -d (_ "Follow symlinks") $is_gnu
|
||||
__fish_gnu_complete $cmds -s R -l recursive -d (_ "List subdirectory recursively") $is_gnu
|
||||
__fish_gnu_complete $cmds -s b -l escape -d (_ "Octal escapes for non graphic characters") $is_gnu
|
||||
__fish_gnu_complete $cmds -s d -l directory -d (_ "List directories, not their content") $is_gnu
|
||||
__fish_gnu_complete $cmds -s h -l human-readable -d (_ "Human readable sizes") $is_gnu
|
||||
__fish_gnu_complete $cmds -s i -l inode -d (_ "Print inode number of files") $is_gnu
|
||||
__fish_gnu_complete $cmds -s n -l numeric-uid-gid -d (_ "Long format, numeric IDs") $is_gnu
|
||||
__fish_gnu_complete $cmds -s p -l file-type -d (_ "Append filetype indicator") $is_gnu
|
||||
__fish_gnu_complete $cmds -s q -l hide-control-chars -d (_ "Replace non-graphic characters with '?'") $is_gnu
|
||||
__fish_gnu_complete $cmds -s r -l reverse -d (_ "Reverse sort order") $is_gnu
|
||||
__fish_gnu_complete $cmds -s s -l size -d (_ "Print size of files") $is_gnu
|
||||
|
||||
complete -c $i -s C -d (_ "List by columns")
|
||||
complete -c $i -s S -d (_ "Sort by size")
|
||||
complete -c $i -s c -d (_ "Show and sort by ctime")
|
||||
complete -c $i -s f -d (_ "Don't sort")
|
||||
complete -c $i -s g -d (_ "Long format without owner")
|
||||
complete -c $i -s k -d (_ "Set blocksize to 1kB")
|
||||
complete -c $i -s l -d (_ "Long format")
|
||||
complete -c $i -s m -d (_ "Comma separated format")
|
||||
complete -c $i -s t -d (_ "Sort by modification time")
|
||||
complete -c $i -s u -d (_ "Show access time")
|
||||
complete -c $i -s x -d (_ "List entries by lines")
|
||||
complete -c $i -s 1 -d (_ "List one file per line")
|
||||
complete $cmds -s C -d (_ "List by columns")
|
||||
complete $cmds -s S -d (_ "Sort by size")
|
||||
complete $cmds -s c -d (_ "Show and sort by ctime")
|
||||
complete $cmds -s f -d (_ "Don't sort")
|
||||
complete $cmds -s g -d (_ "Long format without owner")
|
||||
complete $cmds -s k -d (_ "Set blocksize to 1kB")
|
||||
complete $cmds -s l -d (_ "Long format")
|
||||
complete $cmds -s m -d (_ "Comma separated format")
|
||||
complete $cmds -s t -d (_ "Sort by modification time")
|
||||
complete $cmds -s u -d (_ "Show access time")
|
||||
complete $cmds -s x -d (_ "List entries by lines")
|
||||
complete $cmds -s 1 -d (_ "List one file per line")
|
||||
|
||||
if test -n "$is_gnu"
|
||||
if test -n "$is_gnu"
|
||||
|
||||
# GNU specific features
|
||||
# GNU specific features
|
||||
|
||||
complete -c $i -l author -d (_ "Print author")
|
||||
complete -c $i -l blocksize -x -d (_ "Set block size")
|
||||
complete -c $i -s B -l ignore-backups -d (_ "Ignore files ending with ~")
|
||||
complete -c $i -l color -f -a "never always auto" -d (_ "Use colors")
|
||||
complete -c $i -s D -l dired -d (_ "Generate dired output")
|
||||
complete -c $i -l format -x -a "across commas horizontal long single-column verbose vertical" -d (_ "List format")
|
||||
complete -c $i -l full-time -d (_ "Long format, full-iso time")
|
||||
complete -c $i -s G -l no-group -d (_ "Don't print group information")
|
||||
complete -c $i -l si -d (_ "Human readable sizes, powers of 1000")
|
||||
complete -c $i -l dereference-command-line-symlink-to-dir #-d (_ "Follow directory symlinks from command line")
|
||||
complete -c $i -l indicator-style -x -a "none classify file-type" -d (_ "Append filetype indicator")
|
||||
complete -c $i -s I -l ignore -r -d (_ "Skip entries matching pattern")
|
||||
complete -c $i -s N -l literal -d (_ "Print raw entry names")
|
||||
complete -c $i -s o -d (_ "Long format without groups")
|
||||
complete -c $i -l show-control-chars -d (_ "Non graphic as-is")
|
||||
complete -c $i -s Q -l quote-name -d (_ "Enclose entry in quotes")
|
||||
complete -c $i -l quoting-style -x -a "literal locale shell shell-always c escape" -d (_ "Select quoting style")
|
||||
complete -c $i -l sort -x -d (_ "Sort criteria") -a "
|
||||
extension\t'Sort by file extension'
|
||||
none\tDon't\ sort
|
||||
size\t'Sort by size'
|
||||
time\t'Sort by modification time'
|
||||
version\t'Sort by version'
|
||||
status\t'Sort by file status modification time'
|
||||
atime\t'Sort by access time'
|
||||
access\t'Sort by access time'
|
||||
use\t'Sort by access time'
|
||||
"
|
||||
complete -c $i -l time -x -d (_ "Show time type") -a "
|
||||
time\t'Sort by modification time'
|
||||
access\t'Sort by access time'
|
||||
use\t'Sort by use time'
|
||||
ctime\t'Sort by file status modification time'
|
||||
status\t'Sort by status time'
|
||||
"
|
||||
complete -c $i -l time-style -x -a "full-iso long-iso iso locale" -d (_ "Select time style")
|
||||
complete -c $i -s T -l tabsize -x -a "1 2 3 4 5 6 7 8 9 10 11 12" -d (_ "Assume tab stops at each COLS")
|
||||
complete -c $i -s U -d (_ "Do not sort")
|
||||
complete -c $i -s v -d (_ "Sort by version")
|
||||
complete -c $i -s w -l width -x -d (_ "Assume screen width")
|
||||
complete -c $i -s X -d (_ "Sort by extension")
|
||||
complete -c $i -l help -d (_ "Display help and exit")
|
||||
complete -c $i -l version -d (_ "Display version and exit")
|
||||
complete $cmds -l author -d (_ "Print author")
|
||||
complete $cmds -l blocksize -x -d (_ "Set block size")
|
||||
complete $cmds -s B -l ignore-backups -d (_ "Ignore files ending with ~")
|
||||
complete $cmds -l color -f -a "never always auto" -d (_ "Use colors")
|
||||
complete $cmds -s D -l dired -d (_ "Generate dired output")
|
||||
complete $cmds -l format -x -a "across commas horizontal long single-column verbose vertical" -d (_ "List format")
|
||||
complete $cmds -l full-time -d (_ "Long format, full-iso time")
|
||||
complete $cmds -s G -l no-group -d (_ "Don't print group information")
|
||||
complete $cmds -l si -d (_ "Human readable sizes, powers of 1000")
|
||||
complete $cmds -l dereference-command-line-symlink-to-dir #-d (_ "Follow directory symlinks from command line")
|
||||
complete $cmds -l indicator-style -x -a "none classify file-type" -d (_ "Append filetype indicator")
|
||||
complete $cmds -s I -l ignore -r -d (_ "Skip entries matching pattern")
|
||||
complete $cmds -s N -l literal -d (_ "Print raw entry names")
|
||||
complete $cmds -s o -d (_ "Long format without groups")
|
||||
complete $cmds -l show-control-chars -d (_ "Non graphic as-is")
|
||||
complete $cmds -s Q -l quote-name -d (_ "Enclose entry in quotes")
|
||||
complete $cmds -l quoting-style -x -a "literal locale shell shell-always c escape" -d (_ "Select quoting style")
|
||||
complete $cmds -l sort -x -d (_ "Sort criteria") -a "
|
||||
extension\t'Sort by file extension'
|
||||
none\tDon't\ sort
|
||||
size\t'Sort by size'
|
||||
time\t'Sort by modification time'
|
||||
version\t'Sort by version'
|
||||
status\t'Sort by file status modification time'
|
||||
atime\t'Sort by access time'
|
||||
access\t'Sort by access time'
|
||||
use\t'Sort by access time'
|
||||
"
|
||||
complete $cmds -l time -x -d (_ "Show time type") -a "
|
||||
time\t'Sort by modification time'
|
||||
access\t'Sort by access time'
|
||||
use\t'Sort by use time'
|
||||
ctime\t'Sort by file status modification time'
|
||||
status\t'Sort by status time'
|
||||
"
|
||||
complete $cmds -l time-style -x -a "full-iso long-iso iso locale" -d (_ "Select time style")
|
||||
complete $cmds -s T -l tabsize -x -a "1 2 3 4 5 6 7 8 9 10 11 12" -d (_ "Assume tab stops at each COLS")
|
||||
complete $cmds -s U -d (_ "Do not sort")
|
||||
complete $cmds -s v -d (_ "Sort by version")
|
||||
complete $cmds -s w -l width -x -d (_ "Assume screen width")
|
||||
complete $cmds -s X -d (_ "Sort by extension")
|
||||
complete $cmds -l help -d (_ "Display help and exit")
|
||||
complete $cmds -l version -d (_ "Display version and exit")
|
||||
|
||||
else
|
||||
else
|
||||
|
||||
# If not a GNU system, assume we have standard BSD ls features instead
|
||||
# If not a GNU system, assume we have standard BSD ls features instead
|
||||
|
||||
complete -c $i -s B -d (_ "Octal escapes for non graphic characters")
|
||||
complete -c $i -s G -d (_ "Use colors")
|
||||
complete -c $i -s I -d (_ "Prevent -A from being automatically set for root")
|
||||
complete -c $i -s P -d (_ "Don't follow symlinks")
|
||||
complete -c $i -s T -d (_ "Show modification time")
|
||||
complete -c $i -s W -d (_ "Show whiteouts when scanning directories")
|
||||
complete -c $i -s Z -d (_ "Display each file's MAC label")
|
||||
complete -c $i -s o -d (_ "Include the file flags in a long (-l) output")
|
||||
complete -c $i -s w -d (_ "Print raw entry names")
|
||||
complete $cmds -s B -d (_ "Octal escapes for non graphic characters")
|
||||
complete $cmds -s G -d (_ "Use colors")
|
||||
complete $cmds -s I -d (_ "Prevent -A from being automatically set for root")
|
||||
complete $cmds -s P -d (_ "Don't follow symlinks")
|
||||
complete $cmds -s T -d (_ "Show modification time")
|
||||
complete $cmds -s W -d (_ "Show whiteouts when scanning directories")
|
||||
complete $cmds -s Z -d (_ "Display each file's MAC label")
|
||||
complete $cmds -s o -d (_ "Include the file flags in a long (-l) output")
|
||||
complete $cmds -s w -d (_ "Print raw entry names")
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
for i in {,e}tex {,e}latex pdf{,e}latex pdf{,e}tex omega
|
||||
complete -c $i -o help -d (_ "Display help and exit")
|
||||
complete -c $i -o version -d (_ "Display version and exit")
|
||||
complete -c $i -x -a "(
|
||||
__fish_complete_suffix (commandline -ct) .tex '(La)TeX file'
|
||||
)"
|
||||
end
|
||||
set -l cmds -c etex -c tex -c elatex -c latex -c pdflatex -c pdfelatex -c pdftex -c pdfetex -c omega
|
||||
complete $cmds -o help -d (_ "Display help and exit")
|
||||
complete $cmds -o version -d (_ "Display version and exit")
|
||||
complete $cmds -x -a "(
|
||||
__fish_complete_suffix (commandline -ct) .tex '(La)TeX file'
|
||||
)"
|
||||
|
||||
|
|
Loading…
Reference in a new issue