Add support for -s switch to read builtin, enables shell syntax highlighting in the read builtin

darcs-hash:20070129162624-ac50b-dff9d9ebf16ce3247b83d917efbffd4942cda83f.gz
This commit is contained in:
axel 2007-01-30 02:26:24 +10:00
parent c02e2b1320
commit ba932b6590
5 changed files with 29 additions and 9 deletions

View file

@ -61,6 +61,7 @@
#include "event.h"
#include "signal.h"
#include "exec.h"
#include "highlight.h"
#include "halloc.h"
#include "halloc_util.h"
@ -1516,6 +1517,7 @@ static int builtin_read( wchar_t **argv )
wchar_t *commandline = L"";
int exit_res=STATUS_BUILTIN_OK;
wchar_t *mode_name = READ_MODE_NAME;
int shell = 0;
woptind=0;
@ -1556,6 +1558,10 @@ static int builtin_read( wchar_t **argv )
L"mode-name", required_argument, 0, 'm'
}
,
{
L"shell", required_argument, 0, 's'
}
,
{
L"help", no_argument, 0, 'h'
}
@ -1570,7 +1576,7 @@ static int builtin_read( wchar_t **argv )
int opt = wgetopt_long( argc,
argv,
L"xglUup:c:hm:",
L"xglUup:c:hm:s",
long_options,
&opt_index );
if( opt == -1 )
@ -1621,6 +1627,10 @@ static int builtin_read( wchar_t **argv )
mode_name = woptarg;
break;
case 's':
shell = 1;
break;
case 'h':
builtin_print_help( argv[0], sb_out );
return STATUS_BUILTIN_OK;
@ -1694,7 +1704,13 @@ static int builtin_read( wchar_t **argv )
reader_push( mode_name );
reader_set_prompt( prompt );
if( shell )
{
reader_set_complete_function( &complete );
reader_set_highlight_function( &highlight_shell );
reader_set_test_function( &reader_shell_test );
}
reader_set_buffer( commandline, wcslen( commandline ) );
line = reader_readline( );
if( line )

View file

@ -13,6 +13,7 @@ input and store the result in one or more environment variables.
- <tt>-g</tt> or <tt>--global</tt> specifies that the variables will be made global.
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the hiustory file. If NAME is fish, the regular fish history will be available.
- <tt>-p PROMPT_CMD</tt> or <tt>--prompt=PROMPT_CMD</tt> specifies that the output of the shell command PROMPT_CMD should be used as the prompt for the interactive mode prompt. The default prompt command is <tt>set_color green; echo read; set_color normal; echo "> "</tt>.
- <code>-s</code> or <code>--shell</code> Use syntax highlighting, tab completions and command termination suitable for entering shellscript code
- <code>-u</code> or <code>--unexport</code> causes the specified environment not to be exported to child processes
- <code>-U</code> or <code>--universal</code> causes the specified environment variable to be made universal. If this option is supplied, the variable will be shared between all the current users fish instances on the current computer, and will be preserved across restarts of the shell.
- <code>-x</code> or <code>--export</code> causes the specified environment variable to be exported to child processes

View file

@ -1719,12 +1719,7 @@ void reader_run_command( const wchar_t *cmd )
}
/**
Test if the given shell command contains errors. Uses parser_test
for testing.
*/
static int shell_test( wchar_t *b )
int reader_shell_test( wchar_t *b )
{
int res = parser_test( b, 0, 0, 0 );
@ -1904,7 +1899,7 @@ static int read_i()
reader_push(L"fish");
reader_set_complete_function( &complete );
reader_set_highlight_function( &highlight_shell );
reader_set_test_function( &shell_test );
reader_set_test_function( &reader_shell_test );
data->prev_end_loop=0;

View file

@ -167,4 +167,10 @@ void reader_handle_int( int signal );
*/
int reader_exit_forced();
/**
Test if the given shell command contains errors. Uses parser_test
for testing. Suitable for reader_set_test_function().
*/
int reader_shell_test( wchar_t *b );
#endif

View file

@ -6,3 +6,5 @@ complete -c read -s l -l local --description "Make variable scope local"
complete -c read -s U -l universal --description "Make variable scope universal, i.e. share variable with all the users fish processes on this computer"
complete -c read -s u -l unexport --description "Do not export variable to subprocess"
complete -c read -s m -l mode-name --description "Name to load/save history under" -r -a "read fish"
complete -c read -s c -l command --description "Initial contents of read buffwhen reading interactively"
complete -c read -s s -l shell --description "Use syntax highlighting, tab completions and command termination suitable for entering shellscript code"