mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
isatty: revert to previous behaviour
This partially reverts commit 60808a4820
.
This commit is contained in:
parent
793784c087
commit
66acd17bc0
2 changed files with 27 additions and 24 deletions
|
@ -1,15 +1,17 @@
|
||||||
\section isatty isatty - test if a file or file descriptor is a tty.
|
\section isatty isatty - test if a file descriptor is a tty.
|
||||||
|
|
||||||
\subsection isatty-synopsis Synopsis
|
\subsection isatty-synopsis Synopsis
|
||||||
\fish{synopsis}
|
\fish{synopsis}
|
||||||
isatty [FILE | DEVICE | FILE DESCRIPTOR NUMBER]
|
isatty [FILE DESCRIPTOR]
|
||||||
\endfish
|
\endfish
|
||||||
|
|
||||||
\subsection isatty-description Description
|
\subsection isatty-description Description
|
||||||
|
|
||||||
`isatty` tests if a file or file descriptor is a tty. The argument may be in the form of a file path, device, or file descriptor number. Without an argument, `standard input` is implied.
|
`isatty` tests if a file descriptor is a tty.
|
||||||
|
|
||||||
If the resolved file descriptor is a tty, the command returns zero. Otherwise, the command exits one. No messages are printed to standard error.
|
`FILE DESCRIPTOR` may be either the number of a file descriptor, or one of the strings `stdin`, `stdout`, or `stderr`.
|
||||||
|
|
||||||
|
If the specified file descriptor is a tty, the exit status of the command is zero. Otherwise, the exit status is non-zero. No messages are printed to standard error.
|
||||||
|
|
||||||
|
|
||||||
\subsection isatty-examples Examples
|
\subsection isatty-examples Examples
|
||||||
|
@ -20,14 +22,14 @@ From an interactive shell, the commands below exit with a return value of zero:
|
||||||
isatty
|
isatty
|
||||||
isatty stdout
|
isatty stdout
|
||||||
isatty 2
|
isatty 2
|
||||||
echo | isatty /dev/fd/1
|
echo | isatty 1
|
||||||
\endfish
|
\endfish
|
||||||
|
|
||||||
And these will exit non-zero:
|
And these will exit non-zero:
|
||||||
|
|
||||||
\fish
|
\fish
|
||||||
echo | isatty
|
echo | isatty
|
||||||
isatty /dev/fd/9
|
isatty 9
|
||||||
isatty stdout > file
|
isatty stdout > file
|
||||||
isatty 2 2> file
|
isatty 2 2> file
|
||||||
\endfish
|
\endfish
|
||||||
|
|
|
@ -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*'
|
case stdin
|
||||||
__fish_print_help isatty
|
set fd 0
|
||||||
|
|
||||||
case ''
|
case stdout
|
||||||
command test -c /dev/stdin
|
set fd 1
|
||||||
|
|
||||||
case '*'
|
case stderr
|
||||||
if test -e "$argv" # The eval here is needed for symlinks. Unsure why.
|
set fd 2
|
||||||
command test -c "$argv"; and eval tty 0>"$argv" >/dev/null
|
|
||||||
|
|
||||||
else if test -e /dev/"$argv"
|
case '*'
|
||||||
command test -c /dev/"$argv"; and tty 0>/dev/"$argv" >/dev/null
|
set fd $argv[1]
|
||||||
|
|
||||||
else if test -e /dev/fd/"$argv"
|
end
|
||||||
command test -c /dev/fd/"$argv"; and tty 0>/dev/fd/"$argv" >/dev/null
|
end
|
||||||
|
|
||||||
|
eval "tty 0>&$fd >/dev/null"
|
||||||
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue