summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xranger/data/scope.sh23
1 files changed, 16 insertions, 7 deletions
diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh
index 998476dc..ad14f5e5 100755
--- a/ranger/data/scope.sh
+++ b/ranger/data/scope.sh
@@ -1,21 +1,30 @@
 #!/bin/bash
-# This script is responsible to generate the previews for ranger.
+
+# This script is called whenever you preview a file.
+# Its output is used as the preview.  ANSI color codes are supported.
+
+# Meaning of exit codes:
+# code | meaning    | action of ranger
+# -----+------------+-------------------------------------------
+# 0    | success    | display stdout as preview
+# 1    | no preview | display no preview at all
+
+
 mimetype=$(file --mime-type -Lb "$1")
-basetype=$(echo "$mimetype" | grep -o '^[^/]\+')
 extension=$(echo "$1" | grep '\.' | grep -o '[^.]\+$')
 
-case "$basetype" in
-	text)
-		highlight --ansi "$1" || cat "$1"
+case "$mimetype" in
+	text/*)
+		highlight --ansi "$1" || cat "$1" || exit 1
 		exit 0;;
-	image)
+	image/*)
 		img2txt "$1" || exit 1
 		exit 0;;
 esac
 
 case "$extension" in
 	zip|gz)
-		atool -l "$1"
+		atool -l "$1" || exit 1
 		exit 0;;
 esac