mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 17:07:44 +00:00
60808a4820
Presently, `isatty` only works on a handful of keywords. Here it is rewritten to be able to take any path, device or fd number as an argument, and eliminates errors printed to stdout. Per discussion in #1228, using `builtin test -c` within a pipe to test special file descriptors is not viable, so this implementation specifcially uses `command test`. Additionally, a note has been added to the documentation of `test` regarding this potential aberration from the expected output of the test utility under the 'Standards' section.
27 lines
692 B
Fish
27 lines
692 B
Fish
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.
|
|
|
|
switch "$argv"
|
|
|
|
case '-h*' '--h*'
|
|
__fish_print_help isatty
|
|
|
|
case ''
|
|
command test -c /dev/stdin
|
|
|
|
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
|
|
|
|
else if test -e /dev/"$argv"
|
|
command test -c /dev/"$argv"; and tty 0>/dev/"$argv" >/dev/null
|
|
|
|
else if test -e /dev/fd/"$argv"
|
|
command test -c /dev/fd/"$argv"; and tty 0>/dev/fd/"$argv" >/dev/null
|
|
|
|
else
|
|
return 1
|
|
end
|
|
end
|
|
end
|