aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_indent.c
diff options
context:
space:
mode:
Diffstat (limited to 'fish_indent.c')
-rw-r--r--fish_indent.c77
1 files changed, 52 insertions, 25 deletions
diff --git a/fish_indent.c b/fish_indent.c
index 5e709f2b..14cf5a6c 100644
--- a/fish_indent.c
+++ b/fish_indent.c
@@ -125,6 +125,11 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
{
indent--;
}
+ /* case should have the same indent level as switch*/
+ else if( wcscmp( unesc, L"case" ) == 0 )
+ {
+ indent--;
+ }
else if( wcscmp( unesc, L"end" ) == 0 )
{
indent--;
@@ -132,7 +137,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
}
- if( do_indent && flags)
+ if( do_indent && flags && prev_type != TOK_PIPE )
{
insert_tabs( out, indent );
}
@@ -144,7 +149,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 +168,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 +231,6 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
break;
}
-
case TOK_COMMENT:
{
if( do_indent && flags)