2 # lesspipe.sh, a preprocessor for less (version 1.53)
3 #===============================================================================
4 ### THIS FILE IS GENERATED FROM lesspipe.sh.in, PLEASE GET THE TAR FILE
5 ### ftp://ftp.ifh.de/pub/unix/utility/lesspipe.tar.gz
6 ### AND RUN configure TO GENERATE A lesspipe.sh THAT WORKS IN YOUR ENVIRONMENT
7 #===============================================================================
9 # Usage: lesspipe.sh is called when the environment variable LESSOPEN is set:
10 # LESSOPEN="|lesspipe.sh %s"; export LESSOPEN (sh like shells)
11 # setenv LESSOPEN "|lesspipe.sh %s" (csh, tcsh)
12 # Use the fully qualified path if lesspipe.sh is not in the search path
13 # View files in multifile archives:
14 # less archive_file:contained_file
15 # This can be used to extract ASCII files from a multifile archive:
16 # less archive_file:contained_file>extracted_file
17 # As less is not good for extracting binary data use instead:
18 # lesspipe.sh archive_file:contained_file>extracted_file
19 # Even a file in a multifile archive that itself is contained in yet
20 # another archive can be viewed this way:
21 # less super_archive:archive_file:contained_file
22 # Display the last file in the file1:..:fileN chain in raw format:
23 # Suppress input filtering: less file1:..:fileN: (append a colon)
24 # Suppress decompression: less file1:..:fileN:: (append 2 colons)
26 # see the separate file README
28 # gzip, compress, bzip2, zip, rar, tar, nroff, ar archive, pdf, ps,
29 # dvi, shared library, executable, directory, RPM, Microsoft Word,
30 # Openoffice 1.x and OASIS (Opendocument) formats, Debian, mp3 files,
31 # image formats (png, gif, jpeg, tiff, ...), utf-16 text,
32 # iso images and filesystems on removable media via /dev/xxx
34 # License: GPL (see file LICENSE)
36 # History: see separate file ChangeLog or
37 # http://www.desy.de/zeuthen/~friebel/unix/lesspipe.html
39 # Author: Wolfgang Friebel DESY Zeuthen (Wolfgang.Friebel AT desy.de)
41 #===============================================================================
42 #setopt KSH_ARRAYS SH_WORD_SPLIT
44 if [[ `tar --version 2>&1` = *GNU* ]]; then
48 sep=: # file name separator
49 altsep== # alternate separator character
50 if [[ -f "$1" && "$1" = *$sep* || "$1" = *$altsep ]]; then
53 tmp=/tmp/.lesspipe.$$ # temp file name
54 trap 'rm -f $tmp $tmp.dvi $tmp. $tmp.. $tmp... $tmp.1' 0
58 # if [[ "$1" = *.pod || "$1" = *.pm ]]; then
63 while [[ "$rest1" = ::* ]]; do
64 if [[ "$rest1" = "::" ]]; then
67 rest1="${rest1#$sep$sep}"
68 file1="${rest1%%$sep*}"
69 rest1="${rest1#$file1}"
73 rest11="${rest1#$sep}"
74 file2="${rest11%%$sep*}"
75 rest2="${rest11#$file2}"
76 while [[ "$rest2" = ::* ]]; do
77 if [[ "$rest2" = "::" ]]; then
80 rest2="${rest2#$sep$sep}"
81 file2="${rest2%%$sep*}"
82 rest2="${rest2#$file2}"
83 file2="${rest11%$rest2}"
86 if [[ "$file2" != "" ]]; then
89 rest2="${rest11#$file2}"
91 if [[ "$cmd" = "" ]]; then
92 type=`$filecmd "$file1" | cut -d : -f 2-`
93 if [[ ! -f "$file1" ]]; then
94 if [[ "$type" = *directory* ]]; then
95 if [[ "$file1" = *.pkg ]]; then
96 if [[ -f "$file1/Contents/Archive.bom" ]]; then
97 type="bill of materials"
98 file1="$file1/Contents/Archive.bom"
99 echo "==> This is a Mac OS X archive directory, showing its contents (bom file)"
104 get_cmd "$type" "$file1" "$rest1"
105 if [[ "$cmd" != "" ]]; then
108 isfinal "$type" "$file1" "$rest11"
110 elif [[ "$c1" = "" ]]; then
111 c1[0]=${cmd[0]};c1[1]=${cmd[1]};c1[2]=${cmd[2]}
112 if [[ "${cmd[3]}" != "" ]]; then
115 type=`"${c1[@]}" | dd bs=40000 count=1 2>/dev/null | filepipe | cut -d : -f 2-`
116 get_cmd "$type" "$file1" "$rest1"
117 if [[ "$cmd" != "" ]]; then
120 "${c1[@]}" | isfinal "$type" - "$rest11"
122 elif [[ "$c2" = "" ]]; then
123 c2[0]=${cmd[0]};c2[1]=${cmd[1]};c2[2]=${cmd[2]}
124 if [[ "${cmd[3]}" != "" ]]; then
127 type=`"${c1[@]}" | "${c2[@]}" | dd bs=40000 count=1 2>/dev/null | filepipe | cut -d : -f 2-`
128 get_cmd "$type" "$file1" "$rest1"
129 if [[ "$cmd" != "" ]]; then
132 "${c1[@]}" | "${c2[@]}" | isfinal "$type" - "$rest11"
134 elif [[ "$c3" = "" ]]; then
135 c3[0]=${cmd[0]};c3[1]=${cmd[1]};c3[2]=${cmd[2]}
136 if [[ "${cmd[3]}" != "" ]]; then
139 type=`"${c1[@]}" | "${c2[@]}" | "${c3[@]}" | dd bs=40000 count=1 2>/dev/null | filepipe | cut -d : -f 2-`
140 get_cmd "$type" "$file1" "$rest1"
141 if [[ "$cmd" != "" ]]; then
144 "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | isfinal "$type" - "$rest11"
146 elif [[ "$c4" = "" ]]; then
147 c4[0]=${cmd[0]};c4[1]=${cmd[1]};c4[2]=${cmd[2]}
148 if [[ "${cmd[3]}" != "" ]]; then
151 type=`"${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | dd bs=40000 count=1 2>/dev/null | filepipe | cut -d : -f 2-`
152 get_cmd "$type" "$file1" "$rest1"
153 if [[ "$cmd" != "" ]]; then
156 "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | isfinal "$type" - "$rest11"
158 elif [[ "$c5" = "" ]]; then
159 c5[0]=${cmd[0]};c5[1]=${cmd[1]};c5[2]=${cmd[2]}
160 if [[ "${cmd[3]}" != "" ]]; then
163 type=`"${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | "${c5[@]}" | dd bs=40000 count=1 2>/dev/null | filepipe | cut -d : -f 2-`
164 get_cmd "$type" "$file1" "$rest1"
165 if [[ "$cmd" != "" ]]; then
166 echo "$0: Too many levels of encapsulation"
168 "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | "${c5[@]}" | isfinal "$type" - "$rest11"
175 if [[ "$2" = /*\ * ]]; then
178 elif [[ "$2" = *\ * ]]; then
179 ln -s "$PWD"/"$2" $tmp..
183 if [[ "$1" = *bzip*compress* || "$1" = *compress[\'e]d\ * || "$1" = *packed\ data* ]]; then
184 if [[ "$3" = $sep$sep ]]; then
186 elif [[ "$1" = *bzip*compress* ]]; then
195 if [[ "$file2" != "" ]]; then
196 if [[ "$1" = *\ tar* ]]; then
197 cmd=($tarcmd Oxf "$2" "$file2")
198 elif [[ "$1" = *Debian* ]]; then
199 istemp "ar p" "$2" data.tar.gz | gzip -dc - > $tmp.
200 cmd=($tarcmd Oxf $tmp. "$file2")
201 elif [[ "$1" = *RPM* ]]; then
202 cmd=(isrpm "$2" "$file2")
203 elif [[ "$1" = *Zip* ]]; then
204 cmd=(istemp "unzip -avp" "$2" "$file2")
205 elif [[ "$1" = *\ RAR\ archive* ]]; then
206 cmd=(istemp "unrar p -inul" "$2" "$file2")
207 elif [[ "$1" = *\ 7-zip\ archive* ]]; then
208 if [[ "$2" = - ]]; then
209 cmd=(iscmd2 "7za e -so" - "$file2")
211 cmd=(iscmd "7za e -so" "$2" "$file2")
213 elif [[ "$1" = *[Cc]abinet* ]]; then
214 cmd=(iscab "$2" "$file2")
215 elif [[ "$1" = *\ ar\ archive* ]]; then
216 cmd=(istemp "ar p" "$2" "$file2")
217 elif [[ "$1" = *x86\ boot\ sector* ]]; then
218 cmd=(isfloppy "$2" "$file2")
219 elif [[ "$1" = *ISO\ 9660* ]]; then
220 cmd=(isoinfo "-i$2" "-x$file2")
223 if [[ "$1" = *\ 7-zip\ archive* ]]; then
224 if [[ "$2" != - ]]; then
225 if [[ `7za l "$2" | tail -1` = *\ 1\ file ]]; then
226 cmd=("7za e -so" "$2")
240 if [[ "$1" = - ]]; then
245 cabextract -pF "$2" "$1"
249 if [[ "$1" = - ]]; then
252 if [[ "$1" != *.dvi ]]; then
261 $1 "$2" "$3" 2>/dev/null
266 $1 $tmp. "$3" 2>/dev/null
270 if [[ "$2" = - ]]; then
279 if [[ "$1" = - ]]; then
285 # GNU cpio has an undocumented but most useful --rename-batch-file switch
287 rpm2cpio "$1"|cpio -i --quiet --rename-batch-file $tmp. "${2##/}"
293 # get the device to drive mapping
297 if [[ "$i1" = *$1* ]]; then
298 if [[ "$2" = "" ]]; then
304 elif [[ "$i1" = drive ]]; then
313 if [[ "$3" = $sep$sep ]]; then
316 elif [[ "$3" = $sep* ]]; then
317 if [[ "$3" = $sep ]]; then
318 echo "==> append :. or :<filetype> to activate syntax highlighting"
324 dir=${dir%%lesspipe.sh*\%s}
325 ${dir}code2color $PPID ${in_file:+"$in_file"} $lang "$2"
326 if [[ $? = 0 ]]; then
332 elif [[ "$2" = - ]]; then
334 *RPM*|*\ ar\ archive*|*shared*|*Zip*|*\ RAR\ archive*)
339 if [[ "$1" = *No\ such* ]]; then
341 elif [[ "$1" = *directory* ]]; then
342 echo "==> This is a directory, showing the output of ls -lAL"
344 elif [[ "$1" = *\ tar* ]]; then
345 echo "==> use tar_file${sep}contained_file to view a file in the archive"
347 elif [[ "$1" = *RPM* ]]; then
348 echo "==> use RPM_file${sep}contained_file to view a file in the RPM"
350 echo "================================= Content ======================================"
351 rpm2cpio "$2"|cpio -i -tv --quiet
352 elif [[ "$1" = *roff* ]]; then
354 if [[ "$LANG" = ja* ]]; then
358 if [[ "$2" = *.me ]]; then
360 elif [[ "$2" = *.ms ]]; then
363 echo "==> append $sep to filename to view the nroff source"
364 groff -s -p -t -e -T$DEV -m$MACRO "$2"
365 elif [[ "$1" = *Debian* ]]; then
366 echo "==> use Deb_file${sep}contained_file to view a file in the Deb"
368 istemp "ar p" "$2" data.tar.gz | gzip -dc - | $tarcmd tvf -
369 # elif [[ "$1" = *perl\ *script\ text* || "$pod" = 1 ]]; then
370 # pod2text "$2" > $tmp.dvi
371 # if [[ -s $tmp.dvi ]]; then
372 # echo "==> append $sep to filename to view the Perl source"
375 elif [[ "$1" = *\ script* ]]; then
376 set "plain text" "$2"
377 elif [[ "$1" = *text\ executable* ]]; then
378 set "plain text" "$2"
379 elif [[ "$1" = *PostScript* ]]; then
380 echo "==> append $sep to filename to view the postscript file"
381 which pstotext >/dev/null 2>&1
382 if [[ $? = 0 ]]; then
387 elif [[ "$1" = *executable* ]]; then
388 echo "==> append $sep to filename to view the binary file"
389 if [[ "$2" = "-" ]]; then
394 elif [[ "$1" = *\ ar\ archive* ]]; then
395 echo "==> use library${sep}contained_file to view a file in the archive"
397 elif [[ "$1" = *shared* ]]; then
398 echo "==> This is a dynamic library, showing the output of nm"
400 elif [[ "$1" = *Zip* ]]; then
401 echo "==> use zip_file${sep}contained_file to view a file in the archive"
403 elif [[ "$1" = *\ RAR\ archive* ]]; then
404 echo "==> use rar_file${sep}contained_file to view a file in the archive"
406 elif [[ "$1" = *\ 7-zip\ archive* ]]; then
407 echo "==> use 7-zip_file${sep}contained_file to view a file in the archive"
408 if [[ "$2" = - ]]; then
413 elif [[ "$1" = *[Cc]abinet* ]]; then
414 echo "==> use cab_file${sep}contained_file to view a file in the cabinet"
416 elif [[ "$1" = *x86\ boot\ sector* ]]; then
417 echo "==> use $2${sep}contained_file to view a file on the floppy"
419 elif [[ "$1" = *\ DVI* ]]; then
420 echo "==> append $sep to filename to view the binary DVI file"
422 elif [[ "$1" = *HTML* ]]; then
423 echo "==> append $sep to filename to view the HTML source"
424 html2text -style pretty "$2"
425 elif [[ "$1" = *PDF* ]]; then
426 echo "==> append $sep to filename to view the PDF source"
427 istemp pdftotext "$2" -
428 elif [[ "$1" = *Microsoft\ Word* || "$1" = *Microsoft\ Office* ]]; then
430 elif [[ "$1" = *Rich\ Text\ Format* ]]; then
431 echo "==> append $sep to filename to view the RTF source"
432 unrtf --html "$2" 2>/dev/null | html2text -style pretty
433 elif [[ "$1" = *OpenDocument\ [CHMPST]* || "$1" = *OpenOffice\.org\ 1\.x\ [CIWdgpst]* ]]; then
435 if [[ "$LANG" = *UTF-8 ]]; then
438 echo "==> append $sep to filename to view the OpenOffice or OpenDocument source"
439 istemp "unzip -avp" "$2" content.xml | o3tohtml | $conv | html2text -style pretty
440 elif [[ "$1" = *ISO\ 9660* ]]; then
441 if [[ "$2" != - ]]; then
443 joliet=`isoinfo -d -i "$2" | egrep '^Joliet'|cut -c1`
444 echo "================================= Content ======================================"
445 isoinfo -lR$joliet -i "$2"
447 elif [[ "$1" = *image\ data* || "$1" = *image\ text* || "$1" = *JPEG\ file* || "$1" = *JPG\ file* ]]; then
448 identify -verbose "$2"
449 ##ifdef jpeg2ascii,convert
450 ## get jpeg2ascii (CVS) from http://dyne.org/cgi-bin/cvsweb.cgi/jpeg2ascii/
451 # very experimental attempt to display images using ASCII art (do not use)
452 # elif [[ "$1" = *image\ data* || "$1" = *image\ text* || "$1" = *JPEG\ file* || "$1" = *JPG\ file* ]]; then
453 # convert -colorspace gray -geometry 100%x50% -contrast -geometry 320x1024 "$2" /tmp/.lesspipe1$$.jpg
454 # jpeg2ascii < /tmp/.lesspipe$$.jpg 2> /dev/null
455 # rm /tmp/.lesspipe$$.jpg /tmp/.lesspipe1$$.jpg
456 ##elif pbmtoascii,convert
457 # ASCII Art conversion using netbpm
458 # elif [[ "$1" = *image\ data* || "$1" = *image\ text* || "$1" = *JPEG\ file* || "$1" = *JPG\ file* ]]; then
459 # convert -contrast -geometry 80x2048 "$2" /tmp/.lesspipe$$.pbm
460 # pbmtoascii /tmp/.lesspipe$$.pbm 2> /dev/null
461 # rm /tmp/.lesspipe$$.pbm
464 # elif [[ "$1" = *MPEG\ system\ stream* || "$1" = *RIFF* || "$1" = *AVI* ]]; then
465 # mplayer -vo aa -aadriver slang -aanodim -aanobold -aacontrast 50 -aabright 1 "$2" 2> /dev/null
467 elif [[ "$1" = *MPEG\ *layer\ 3\ audio* || "$1" = *mp3\ file* || "$1" = *MP3* ]]; then
469 elif [[ "$1" = *bill\ of\ materials* ]]; then
471 elif [[ "$1" = *perl\ Storable* ]]; then
472 perl -MStorable=retrieve -MData::Dumper -e '$Data::Dumper::Indent=1;print Dumper retrieve shift' "$2"
473 elif [[ "$1" = *UTF-16* ]]; then
475 elif [[ "$1" = *data* ]]; then
476 echo "==> append $sep to filename to view the $1 source"
477 if [[ "$2" = "-" ]]; then
483 set "plain text" "$2"
485 if [[ "$1" = *plain\ text* ]]; then
487 dir=${dir%%lesspipe.sh*\%s}
488 ${dir}code2color $PPID ${in_file:+"$in_file"} "$2"
489 if [[ $? = 0 ]]; then
493 if [[ "$2" = - ]]; then
498 # calling show with arg1 arg2 ... is equivalent to calling with arg1:arg2:...
501 if [[ "$a" = "" ]]; then
502 if [[ "$SHELL" = *csh ]]; then
503 echo "setenv LESSOPEN \"|$0 %s\""
505 echo "LESSOPEN=\"|$0 %s\""
506 echo "export LESSOPEN"