diff --git a/builtin.c b/builtin.c index caf9e3a64..26daaa7bf 100644 --- a/builtin.c +++ b/builtin.c @@ -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 ) diff --git a/doc_src/read.txt b/doc_src/read.txt index 13e4d658d..69566e190 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -13,6 +13,7 @@ input and store the result in one or more environment variables. - -g or --global specifies that the variables will be made global. - -m NAME or --mode-name=NAME 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. - -p PROMPT_CMD or --prompt=PROMPT_CMD 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 set_color green; echo read; set_color normal; echo "> ". +- -s or --shell Use syntax highlighting, tab completions and command termination suitable for entering shellscript code - -u or --unexport causes the specified environment not to be exported to child processes - -U or --universal 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. - -x or --export causes the specified environment variable to be exported to child processes diff --git a/reader.c b/reader.c index 4ad6e2ed7..add5e2dc0 100644 --- a/reader.c +++ b/reader.c @@ -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; diff --git a/reader.h b/reader.h index f20c2aeb2..36f22726f 100644 --- a/reader.h +++ b/reader.h @@ -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 diff --git a/share/completions/read.fish b/share/completions/read.fish index 5130993d5..fb43d253d 100644 --- a/share/completions/read.fish +++ b/share/completions/read.fish @@ -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"