diff --git a/builtin.c b/builtin.c index 26daaa7bf..005c87340 100644 --- a/builtin.c +++ b/builtin.c @@ -241,7 +241,8 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b ) { const wchar_t *h; - + int is_short = 0; + if( b == sb_err ) { sb_append( sb_err, @@ -257,7 +258,7 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b ) if( str ) { - if( is_interactive && !builtin_out_redirect && b==sb_err) + if( b==sb_err ) { /* @@ -269,12 +270,14 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b ) screen_height = common_get_height(); lines = count_char( str, L'\n' ); - if( lines > 2*screen_height/3 ) + if( !is_interactive || (lines > 2*screen_height/3) ) { wchar_t *pos; int cut=0; int i; - + + is_short = 1; + /* First move down 4 lines */ @@ -338,6 +341,11 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b ) } sb_append( b, str ); + if( is_short ) + { + sb_printf( b, _(L"%ls: Type 'help %ls' for related documentation\n\n"), cmd, cmd ); + } + free( str ); } } @@ -351,8 +359,6 @@ static void builtin_unknown_option( const wchar_t *cmd, const wchar_t *opt ) BUILTIN_ERR_UNKNOWN, cmd, opt ); - sb_append( sb_err, - parser_current_line() ); builtin_print_help( cmd, sb_err ); } @@ -1646,8 +1652,7 @@ static int builtin_read( wchar_t **argv ) { sb_printf( sb_err, BUILTIN_ERR_EXPUNEXP, - argv[0], - parser_current_line() ); + argv[0] ); builtin_print_help( argv[0], sb_err ); @@ -1658,8 +1663,7 @@ static int builtin_read( wchar_t **argv ) { sb_printf( sb_err, BUILTIN_ERR_GLOCAL, - argv[0], - parser_current_line() ); + argv[0] ); builtin_print_help( argv[0], sb_err ); return STATUS_BUILTIN_ERROR; @@ -1683,7 +1687,7 @@ static int builtin_read( wchar_t **argv ) if( (!iswalnum(*src)) && (*src != L'_' ) ) { sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *src ); - sb_append2(sb_err, parser_current_line(), L"\n", (void *)0 ); + builtin_print_help( argv[0], sb_err ); return STATUS_BUILTIN_ERROR; } } diff --git a/builtin.h b/builtin.h index 9629c7adb..722b31ed8 100644 --- a/builtin.h +++ b/builtin.h @@ -35,12 +35,12 @@ enum /** Error message on multiple scope levels for variables */ -#define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n%ls\n" ) +#define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n" ) /** Error message for specifying both export and unexport to set/read */ -#define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n%ls\n" ) +#define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n" ) /** Error message for unknown switch diff --git a/builtin_complete.c b/builtin_complete.c index 9912e2f1f..8ea38a3aa 100644 --- a/builtin_complete.c +++ b/builtin_complete.c @@ -408,9 +408,6 @@ static int builtin_complete( wchar_t **argv ) BUILTIN_ERR_UNKNOWN, argv[0], long_options[opt_index].name ); - sb_append( sb_err, - parser_current_line() ); - builtin_print_help( argv[0], sb_err ); @@ -574,8 +571,6 @@ static int builtin_complete( wchar_t **argv ) 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 ); res = 1; diff --git a/builtin_jobs.c b/builtin_jobs.c index c4593400c..d53d43e99 100644 --- a/builtin_jobs.c +++ b/builtin_jobs.c @@ -222,8 +222,6 @@ static int builtin_jobs( wchar_t **argv ) argv[0], long_options[opt_index].name ); - sb_append( sb_err, - parser_current_line() ); builtin_print_help( argv[0], sb_err ); diff --git a/builtin_set.c b/builtin_set.c index 2bf1ef3ac..0477757f4 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -560,9 +560,8 @@ static int builtin_set( wchar_t **argv ) if( query && (erase || list || global || local || universal || export || unexport ) ) { sb_printf(sb_err, - BUILTIN_ERR_COMBO2, - argv[0], - parser_current_line() ); + BUILTIN_ERR_COMBO, + argv[0] ); builtin_print_help( argv[0], sb_err ); return 1; @@ -573,9 +572,8 @@ static int builtin_set( wchar_t **argv ) if( erase && list ) { sb_printf(sb_err, - BUILTIN_ERR_COMBO2, - argv[0], - parser_current_line() ); + BUILTIN_ERR_COMBO, + argv[0] ); builtin_print_help( argv[0], sb_err ); return 1; @@ -588,8 +586,7 @@ static int builtin_set( wchar_t **argv ) { sb_printf( sb_err, BUILTIN_ERR_GLOCAL, - argv[0], - parser_current_line() ); + argv[0] ); builtin_print_help( argv[0], sb_err ); return 1; } @@ -601,8 +598,7 @@ static int builtin_set( wchar_t **argv ) { sb_printf( sb_err, BUILTIN_ERR_EXPUNEXP, - argv[0], - parser_current_line() ); + argv[0] ); builtin_print_help( argv[0], sb_err ); return 1; } @@ -692,8 +688,7 @@ static int builtin_set( wchar_t **argv ) { sb_printf( sb_err, _(L"%ls: Erase needs a variable name\n%ls\n"), - argv[0], - parser_current_line() ); + argv[0] ); builtin_print_help( argv[0], sb_err ); retcode = 1; @@ -850,9 +845,8 @@ static int builtin_set( wchar_t **argv ) if( woptind != argc ) { sb_printf( sb_err, - _(L"%ls: Values cannot be specfied with erase\n%ls\n"), - argv[0], - parser_current_line() ); + _(L"%ls: Values cannot be specfied with erase\n"), + argv[0] ); builtin_print_help( argv[0], sb_err ); retcode=1; }