summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xranger/data/scope.sh46
1 files changed, 28 insertions, 18 deletions
diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh
index 9ce35fd9..c99f715b 100755
--- a/ranger/data/scope.sh
+++ b/ranger/data/scope.sh
@@ -3,15 +3,9 @@
 # This script is called whenever you preview a file.
 # Its output is used as the preview.  ANSI color codes are supported.
 
-# NOTE: This is considered to be a configuration file.  If you upgrade
+# NOTES: This script is considered a configuration file.  If you upgrade
 # ranger, it will be left untouched. (You must update it yourself)
-
-# Meanings of arguments:
-# name | meaning
-# -----+--------------------------------------------------------
-# $1   | Full filename of the selected file
-# $2   | Width of the preview pane (number of fitting characters)
-# $3   | Height of the preview pane (number of fitting characters)
+# NEVER make this script interactive. (by starting mplayer or something)
 
 # Meanings of exit codes:
 # code | meaning    | action of ranger
@@ -19,31 +13,47 @@
 # 0    | success    | display stdout as preview
 # 1    | no preview | display no preview at all
 # 2    | plain text | display the plain content of the file
+# 3    | fix width  | success. Don't reload when width changes
+# 4    | fix height | success. Don't reload when height changes
+# 5    | fix both   | success. Don't ever reload
+
+# Meaningful aliases for arguments:
+path="$1"    # Full path of the selected file
+width="$2"   # Width of the preview pane (number of fitting characters)
+height="$3"  # Height of the preview pane (number of fitting characters)
+
+# Find out something about the file:
+mimetype=$(file --mime-type -Lb "$path")
+extension=$(echo "$path" | grep '\.' | grep -o '[^.]\+$')
 
-mimetype=$(file --mime-type -Lb "$1")
-extension=$(echo "$1" | grep '\.' | grep -o '[^.]\+$')
+# Other useful stuff
+maxln=200                                   # print up to $maxln lines
+function have { type -P "$1" > /dev/null; } # test if program is installed
 
 case "$extension" in
 	# Archive extensions:
 	7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|gz|jar|lha|lz|lzh|lzma|lzo\
 	|rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xz|Z|zip)
-		atool -l "$1" || exit 1
-		exit 0;;
+		atool -l "$path" | head -n $maxln && exit 3
+		exit 1;;
+	pdf)
+		pdftotext "$path" | head -n $maxln && exit 3
+		exit 1;;
 	# HTML Pages:
 	htm|html|xhtml)
-		lynx -dump "$1" || elinks -dump "$1" || exit 1
-		exit 0;;
+		have lynx && lynx -dump "$path" | head -n $maxln && exit 5
+		have elinks && elinks -dump "$path" | head -n $maxln && exit 5
+		;; # fall back to highlight/cat if theres no lynx/elinks
 esac
 
 case "$mimetype" in
 	# Syntax highlight for text files:
 	text/* | */xml)
-		highlight --ansi "$1" || cat "$1" || exit 1
-		exit 0;;
+		(highlight --ansi "$path" || cat "$path") | head -n $maxln
+		exit 5;;
 	# Ascii-previews of images:
 	image/*)
-		img2txt -W "$2" "$1" || exit 1
-		exit 0;;
+		img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;;
 esac
 
 exit 1
s/ranger/commit/ranger/defaults/apps.py?h=v1.9.0b1&id=732b40127db11e691a4b3fff50d13e0188c9f778'>732b4012 ^
8f50c004 ^
f1a454b0 ^
732b4012 ^
8f50c004 ^
732b4012 ^
8f50c004 ^
a35042fb ^
b4c2c703 ^
b6aff4c3 ^
bd0ede8d ^
cc952d63 ^
871c502d ^
23236d0c ^


cc952d63 ^
58c84bd6 ^
d012468d ^
58c84bd6 ^
845bd407 ^
13c70add ^
6d4dddc7 ^
0e2b3164 ^
035a39a8 ^
d012468d ^
f61767b1 ^
c3cdeb9c ^
f54d0ec7 ^

09449df0 ^
d012468d ^
845bd407 ^
d012468d ^
845bd407 ^
2052eb74 ^

d012468d ^
cc952d63 ^

0dc57267 ^
cc952d63 ^


23236d0c ^
d46a05a8 ^
ea87d005 ^
cc952d63 ^
d012468d ^
cc952d63 ^
4d9266ac ^
d012468d ^
cc952d63 ^
44a31d6c ^

4e0ca535 ^
44a31d6c ^
a44749f6 ^
23236d0c ^
bea16f4e ^
23236d0c ^
8b909983 ^
cc952d63 ^
d46a05a8 ^
1b0786f2 ^



d46a05a8 ^
1b0786f2 ^

bd0ede8d ^
1b0786f2 ^


d46a05a8 ^
845bd407 ^




d46a05a8 ^
23236d0c ^

a7772cc6 ^
cc952d63 ^
23236d0c ^
d46a05a8 ^
23236d0c ^


cc952d63 ^
23236d0c ^

871c502d ^
cc952d63 ^
a7772cc6 ^
23236d0c ^
d46a05a8 ^
23236d0c ^




d383965f ^
23236d0c ^
d383965f ^
f01238dc ^
db41bc89 ^
e3744f40 ^
23236d0c ^
d46a05a8 ^
23236d0c ^




ea87d005 ^
0dc57267 ^




d46a05a8 ^
845bd407 ^






ea87d005 ^
d46a05a8 ^
845bd407 ^






ea87d005 ^
d46a05a8 ^
845bd407 ^

845bd407 ^
a7772cc6 ^

748d0a6a ^
6eb85224 ^







a5e1ccdd ^

















748d0a6a ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217