From 10c6801ccd422b7e2830eae24d37eaafaa203547 Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 6 Sep 2022 18:08:44 -0700 Subject: [PATCH] sane-which: only `cat` text-based files --- pkgs/sane-scripts/src/sane-which | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkgs/sane-scripts/src/sane-which b/pkgs/sane-scripts/src/sane-which index fee58f15..2f7279af 100755 --- a/pkgs/sane-scripts/src/sane-which +++ b/pkgs/sane-scripts/src/sane-which @@ -7,11 +7,18 @@ v=$(which $1) # this probably doesn't handle paths with spaces while [ "$(readlink $v || echo $v)" != "$v" ] do - echo '->' "$v" - v=$(readlink "$v") + # TODO: this doesn't handle relative symlinks + echo '->' "$v" + v=$(readlink "$v") done echo '->' "$v" echo '' -# TODO: it'd be nice if we checked file type and only cat'd it if it's text -cat "$v" +case $(file --brief --mime "$v") in + (*text*) + cat "$v" + ;; + (*) + echo $(file "$v") + ;; +esac