Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -
- def:
- function testfunc
- if isatty 1
- set_color red
- echo "yup, i think i'm outputting to a tty (so this is color red) (argv is $argv)"
- set_color normal
- else
- echo "no, i think i'm *not* outputting to a tty (no color) (argv is $argv)"
- end
- end
- tests:
- > testfunc some args with spaces
- #=> yup, i think i'm outputting to a tty (so this is color red) (argv is some args with spaces)
- > testfunc some args with spaces|xargs -0 echo
- #=> no, i think i'm *not* outputting to a tty (no color) (argv is some args with spaces)
- > pty testfunc some args with spaces|xargs -0 echo
- #=> yup, i think i'm outputting to a tty (so this is color red) (argv is some args with spaces)
- ... wait, you mean problems like *this*, right?:
- def:
- function testfunc
- if isatty 1
- set_color red
- echo "yup, i think i'm outputting to a tty (so this is color red) (args are: " (for i in (seq (count $argv)); echo -n "argv[$i]:$argv[$i] " ;end) ")"
- set_color normal
- else
- echo "no, i think i'm *not* outputting to a tty (no color) (args are: " (for i in (seq (count $argv)); echo -n "argv[$i]:$argv[$i] " ;end) ")"
- end
- end
- tests:
- > testfunc "args with" 'spaces in them'
- #=> yup, i think i'm outputting to a tty (so this is color red) (args are: argv[1]:args with argv[2]:spaces in them )
- > pty testfunc "args with" 'spaces in them'|xargs -0 echo
- #=> yup, i think i'm outputting to a tty (so this is color red) (args are: argv[1]:args argv[2]:with argv[3]:spaces argv[4]:in argv[5]:them )
Advertisement
Add Comment
Please, Sign In to add comment