summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-06-22 01:44:48 +0200
committerhut <hut@lavabit.com>2010-06-22 01:44:48 +0200
commit356726c41d5f7a95fdf60ed867f05d2d10bff70a (patch)
treefa08619994199f2c0321b95b9130aa041e128e87
parent48a13dcdb31313d74e71028a32e19041f3a7f76c (diff)
downloadranger-356726c41d5f7a95fdf60ed867f05d2d10bff70a.tar.gz
data/scope.sh: improved, commented
-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