From df23913bb8c38f2286497dde5cc65798ce9d4473 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Wed, 1 Dec 2010 13:05:10 +0800 Subject: [PATCH] fish_indent: only output fd number when have to The original patch is own by Dylan. I just did some cleaning and reformating. --- fish_indent.c | 72 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/fish_indent.c b/fish_indent.c index 5e709f2b8..31807e816 100644 --- a/fish_indent.c +++ b/fish_indent.c @@ -144,7 +144,9 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) } else { - sb_printf( out, L" %ls", last ); + if ( prev_type != TOK_REDIRECT_FD ) + sb_append( out, L" " ); + sb_append( out, last ); } break; @@ -161,39 +163,60 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) case TOK_PIPE: { - sb_append( out, L" | " ); + sb_append( out, L" " ); + if ( last[0] == '2' && !last[1] ) { + sb_append( out, L"^" ); + } else if ( last[0] != '1' || last[1] ) { + sb_append( out, last, L">" ); + } + sb_append( out, L"| " ); is_command = 1; break; } case TOK_REDIRECT_OUT: - case TOK_REDIRECT_APPEND: - case TOK_REDIRECT_IN: - case TOK_REDIRECT_FD: { - sb_append( out, last ); - switch( type ) - { - case TOK_REDIRECT_OUT: - sb_append( out, L"> " ); - break; - - case TOK_REDIRECT_APPEND: - sb_append( out, L">> " ); - break; - - case TOK_REDIRECT_IN: - sb_append( out, L"< " ); - break; - - case TOK_REDIRECT_FD: - sb_append( out, L">& " ); - break; - + sb_append( out, L" " ); + if ( wcscmp( last, L"2" ) == 0 ) { + sb_append( out, L"^" ); + } else { + if ( wcscmp( last, L"1" ) != 0 ) + sb_append( out, last ); + sb_append( out, L">" ); } break; } + case TOK_REDIRECT_APPEND: + { + sb_append( out, L" " ); + if ( wcscmp( last, L"2" ) == 0 ) { + sb_append( out, L"^^" ); + } else { + if ( wcscmp( last, L"1" ) != 0 ) + sb_append( out, last ); + sb_append( out, L">>" ); + } + break; + } + + case TOK_REDIRECT_IN: + { + sb_append( out, L" " ); + if ( wcscmp( last, L"0" ) != 0 ) + sb_append( out, last ); + sb_append( out, L"<" ); + break; + } + + case TOK_REDIRECT_FD: + { + sb_append( out, L" " ); + if ( wcscmp( last, L"1" ) != 0 ) + sb_append( out, last ); + sb_append( out, L">&" ); + break; + } case TOK_BACKGROUND: { @@ -203,7 +226,6 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) break; } - case TOK_COMMENT: { if( do_indent && flags)