I tested fish_indent with the following test cases:

for x in (seq 0 3)
  echo "cmd arg $x> outfile" | fish_indent
  echo "cmd arg $x^ outfile" | fish_indent
  echo "cmd arg $x< infile" | fish_indent
  echo "cmd arg $x>> appendfile" | fish_indent
  echo "cmd arg $x^^ appendfile" | fish_indent
  echo "cmd arg $x>| cmd" | fish_indent
  echo "cmd arg $x>&4" | fish_indent
end
---
 # Output
cmd arg 0> outfile
cmd arg 0> outfile
cmd arg < infile
cmd arg 0>> appendfile
cmd arg 0>> appendfile
fish_indent: Unknown token 'Can not use fd 0 as pipe output'
cmd arg 0>&4
cmd arg > outfile
cmd arg > outfile
cmd arg 1< infile
cmd arg >> appendfile
cmd arg >> appendfile
cmd arg | cmd
cmd arg 1>&4
cmd arg ^ outfile
cmd arg ^ outfile
cmd arg 2< infile
cmd arg ^^ appendfile
cmd arg ^^ appendfile
cmd arg ^| cmd
cmd arg 2>&4
cmd arg 3> outfile
cmd arg 3> outfile
cmd arg 3< infile
cmd arg 3>> appendfile
cmd arg 3>> appendfile
cmd arg 3>| cmd
cmd arg 3>&4


 fish_indent.c |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/fish_indent.c b/fish_indent.c
index 5e709f2..f3471ba 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_printf( out, L" " );
+                                       sb_printf( out, L"%ls", last );
                                }
 
                                break;
@@ -161,7 +163,13 @@ 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;
                        }
@@ -171,23 +179,37 @@ static int indent( string_buffer_t *out, wchar_t *in, int 
flags )
                        case TOK_REDIRECT_IN:
                        case TOK_REDIRECT_FD:
                        {
-                               sb_append( out, last );
+                               sb_append( out, L" " );
                                switch( type )
                                {
                                        case TOK_REDIRECT_OUT:
-                                               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">& " );
+                                               sb_append( out, last, L">&" );
                                                break;
 
                                }
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to