Skip to content

Instantly share code, notes, and snippets.

@msabramo
Created January 27, 2011 07:20
Show Gist options
  • Save msabramo/798194 to your computer and use it in GitHub Desktop.
Save msabramo/798194 to your computer and use it in GitHub Desktop.
This patch allows lesspipe.sh's color directory viewing to work with the ls in BSDs, including OS X
diff --git a/lesspipe.sh.in b/lesspipe.sh.in
index 00b40fc..2e620f4 100755
--- a/lesspipe.sh.in
+++ b/lesspipe.sh.in
@@ -506,13 +506,20 @@ isfinal() {
exit 1
elif [[ "$1" = *directory* ]]; then
echo "==> This is a directory, showing the output of"
- echo "ls -lA $2"
# color requires -r or -R when calling less, not recommended
typeset COLOR
if [[ $(tput colors) -ge 8 && ("$LESS" = *-*r* || "$LESS" = *-*R*) ]]; then
COLOR="--color=always"
+ if ! ls $COLOR > /dev/null 2>&1; then
+ COLOR="-G"
+ if ! ls $COLOR > /dev/null 2>&1; then
+ COLOR=""
+ fi
+ fi
fi
- ls -lA $COLOR "$2"
+ cmd="CLICOLOR_FORCE=1 ls -lA $COLOR $2"
+ echo $cmd
+ eval $cmd
elif [[ "$1" = *\ tar* || "$1" = *\ tar* ]]; then
echo "==> use tar_file${sep}contained_file to view a file in the archive"
$tarcmd tvf "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment