diff --git a/doc_src/isatty.txt b/doc_src/isatty.txt new file mode 100644 index 000000000..5654c5a2b --- /dev/null +++ b/doc_src/isatty.txt @@ -0,0 +1,12 @@ +\section isatty isatty - Test if the specidied file descriptor is a tty + +\subsection isatty-synopsis Synopsis + isatty [FILE DESCRIPTOR] + +where FILE DESCRIPTOR may be either the number of a file descriptor, or one +of the strings stdin, stdout and stderr. + +If he specified file descriptor is a tty, the exit status of the +command is zero, otherwise, it is non-zero. + + diff --git a/share/functions/isatty.fish b/share/functions/isatty.fish new file mode 100644 index 000000000..3a54c6ab4 --- /dev/null +++ b/share/functions/isatty.fish @@ -0,0 +1,28 @@ + +function isatty -d "Tests if a file descriptor is a tty" + set -l fd 0 + if count $argv >/dev/null + switch $argv[1] + + case -h --h --he --hel --help + help isatty + + case stdin + set fd 0 + + case stdout + set fd 1 + + case stderr + set fd 2 + + case '*' + set fd $argv[1] + + end + end + + eval "tty 0>&$fd >/dev/null"; and return 0 + + return 1 +end diff --git a/share/functions/ls.fish b/share/functions/ls.fish index e03b33dd9..d98b19819 100644 --- a/share/functions/ls.fish +++ b/share/functions/ls.fish @@ -5,7 +5,11 @@ if command ls --version 1>/dev/null 2>/dev/null # This is GNU ls function ls -d (N_ "List contents of directory") - command ls --color=auto --indicator-style=classify $argv + set -l param --color=auto + if isatty 1 + set param $param --indicator-style=classify + end + command ls $argv end set -l color_document 35