diff options
author | David Adam <zanchey@ucc.gu.uwa.edu.au> | 2015-02-01 17:11:44 +0800 |
---|---|---|
committer | David Adam <zanchey@ucc.gu.uwa.edu.au> | 2015-02-01 18:18:34 +0800 |
commit | 66acd17bc02a8b3ff6292f1fc499b2712edf91f3 (patch) | |
tree | 6232dd3b3f54bdf2ce3d639fa9046bf8e7ebae45 /share/functions/isatty.fish | |
parent | 793784c08778e8b3fb9d8a2a5621bd968db1dfbe (diff) |
isatty: revert to previous behaviour
This partially reverts commit 60808a4820b1714.
Diffstat (limited to 'share/functions/isatty.fish')
-rw-r--r-- | share/functions/isatty.fish | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/share/functions/isatty.fish b/share/functions/isatty.fish index f49b3aa4..d4f2c43e 100644 --- a/share/functions/isatty.fish +++ b/share/functions/isatty.fish @@ -1,27 +1,28 @@ -function isatty -d "Test if a file or file descriptor is a tty." -# Use `command test` because `builtin test` doesn't open the regular fd's. +function isatty -d "Tests if a file descriptor is a tty" + set -l fd 0 + if count $argv >/dev/null + switch $argv[1] - switch "$argv" + case -h --h --he --hel --help + __fish_print_help isatty + return 0 - case '-h*' '--h*' - __fish_print_help isatty + case stdin + set fd 0 - case '' - command test -c /dev/stdin + case stdout + set fd 1 - case '*' - if test -e "$argv" # The eval here is needed for symlinks. Unsure why. - command test -c "$argv"; and eval tty 0>"$argv" >/dev/null + case stderr + set fd 2 - else if test -e /dev/"$argv" - command test -c /dev/"$argv"; and tty 0>/dev/"$argv" >/dev/null + case '*' + set fd $argv[1] - else if test -e /dev/fd/"$argv" - command test -c /dev/fd/"$argv"; and tty 0>/dev/fd/"$argv" >/dev/null + end + end + + eval "tty 0>&$fd >/dev/null" - else - return 1 - end - end end |