1# lesspipe.sh, a preprocessor for less (version 1.83) 2#=============================================================================== 3### THIS FILE IS GENERATED FROM lesspipe.sh.in, PLEASE GET THE ZIP FILE 4### from https://github.com/wofr06/lesspipe/archive/lesspipe.zip 5### AND RUN configure TO GENERATE A lesspipe.sh THAT WORKS IN YOUR ENVIRONMENT 6#=============================================================================== 7# 8# Usage: lesspipe.sh is called when the environment variable LESSOPEN is set: 9# LESSOPEN="|lesspipe.sh %s"; export LESSOPEN (sh like shells) 10# setenv LESSOPEN "|lesspipe.sh %s" (csh, tcsh) 11# Use the fully qualified path if lesspipe.sh is not in the search path 12# View files in multifile archives: 13# less archive_file:contained_file 14# This can be used to extract ASCII files from a multifile archive: 15# less archive_file:contained_file>extracted_file 16# As less is not good for extracting raw data use instead: 17# lesspipe.sh archive_file:contained_file>extracted_file 18# Even a file in a multifile archive that itself is contained in yet 19# another archive can be viewed this way: 20# less super_archive:archive_file:contained_file 21# Display the last file in the file1:..:fileN chain in raw format: 22# Suppress input filtering: less file1:..:fileN: (append a colon) 23# Suppress decompression: less file1:..:fileN:: (append 2 colons) 24# 25# Required programs and supported formats: see the separate file README 26# License: GPL (see file LICENSE) 27# History: see the separate file ChangeLog 28# Author: Wolfgang Friebel, DESY (Wolfgang.Friebel AT desy.de) 29# 30#=============================================================================== 31setopt KSH_ARRAYS SH_WORD_SPLIT 2>/dev/null 32set +o noclobber 33#ifdef tar 34tarcmd='tar' 35#endif 36 37dir=${LESSOPEN#\|} 38dir=${dir%%lesspipe.sh*\%s} 39dir=${dir%%/} 40# look for commands also where lesspipe.sh is stored 41PATH=$PATH:$dir 42 43cmd_exist () { 44 command -v "$1" > /dev/null 2>&1 && return 0 || return 1 45} 46if [[ "$LESS_ADVANCED_PREPROCESSOR" = '' ]]; then 47 NOL_A_P=_NO_L_A_P 48fi 49 50filecmd() { 51 file -L -s "$@" 52 file -L -s -i "$@" 2> /dev/null | sed -n 's/.*charset=/;/p' | tr a-z A-Z 53} 54 55sep=: # file name separator 56altsep== # alternate separator character 57# if the alternate separator char is used it is repeated at the end of the line 58if [[ -e "$1" && "$1" = *$sep* || "$1" = *$altsep ]]; then 59 sep=$altsep 60 xxx="${1%=}" 61 set "$xxx" 62fi 63if cmd_exist mktemp; then 64 tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/lesspipe.XXXXXXXXXX") 65 66 nexttmp () { 67 # nexttmp -d returns a directory 68 mktemp $1 "${tmpdir}/XXXXXXXX" 69 } 70else 71 tmpdir=${TMPDIR:-/tmp}/lesspipe.$RANDOM 72 mkdir $tmpdir 73 74 nexttmp () { 75 new="$tmpdir/lesspipe.$RANDOM" 76 [[ "$1" = -d ]] && mkdir $new 77 echo $new 78 } 79fi 80[[ -d "$tmpdir" ]] || exit 1 81trap "rm -rf '$tmpdir'" 0 82trap - PIPE 83 84unset iconv 85iconv() { 86 if [[ -z "$iconv" ]]; then 87 arg=$(printf "%s$(command iconv --help 2>/dev/null | \ 88 sed -n 's/.*\(--.*-subst=\)\(FORMATSTRING\).*/\1\\033[7m?\\033[m/p' | \ 89 tr \\n ' ')") 90 if [[ -n "$arg" ]]; then 91 iconv="command iconv -c $arg -t //TRANSLIT" 92 else 93 iconv="command iconv -c" 94 fi 95 fi 96 if $iconv "$@" > /dev/null 2>&1; then 97 msg "append $sep to filename to view the $2 encoded data" 98 $iconv "$@" 99 fi 100} 101 102msg () { 103 if [[ -n "$LESSQUIET" ]]; then 104 return 105 fi 106 echo "==> $@" 107} 108 109filetype () { 110 # wrapper for 'file' command 111 typeset name 112 name="$1" 113 if [[ "$1" = - ]]; then 114 dd bs=40000 count=1 > "$tmpdir/file" 2>/dev/null 115 set "$tmpdir/file" "$2" 116 name="$filen" 117 fi 118 typeset type 119 # type=" $(filecmd -b "$1")" # not supported by all versions of 'file' 120 type=$(filecmd "$1" | cut -d : -f 2-) 121 if [[ "$type" = " empty" ]]; then 122 # exit if file returns "empty" (e.g., with "less archive:nonexisting_file") 123 exit 1 124 elif [[ "$type" = *XML* && "$name" = *html ]]; then 125 type=" HTML document text" 126 elif [[ ("$type" = *HTML* || "$type" = *ASCII*) && "$name" = *xml ]]; then 127 type=" XML document text" 128 elif [[ "$type" != *lzip\ compressed* && ("$name" = *.lzma || "$name" = *.tlz) ]]; then 129 type=" LZMA compressed data" 130 elif [[ ("$type" = *Zip* || "$type" = *ZIP*) && ("$name" = *.jar || "$name" = *.xpi) ]]; then 131 type=" Zip compressed Jar archive" 132 elif [[ "$type" = *Microsoft\ Office\ Document* && ("$name" = *.ppt) ]]; then 133 type=" PowerPoint document" 134 elif [[ "$type" = *Microsoft\ Office\ Document* && ("$name" = *.xls) ]]; then 135 type=" Excel document" 136 elif [[ "$type" = *Hierarchical\ Data\ Format* && ("$name" = *.nc4) ]]; then 137 type=" NetCDF Data Format data" 138 fi 139 echo "$type" 140} 141 142show () { 143 file1="${1%%$sep*}" 144 rest1="${1#$file1}" 145 while [[ "$rest1" = ::* ]]; do 146 if [[ "$rest1" = "::" ]]; then 147 break 148 else 149 rest1="${rest1#$sep$sep}" 150 file1="${rest1%%$sep*}" 151 rest1="${rest1#$file1}" 152 file1="${1%$rest1}" 153 fi 154 done 155 if [[ ! -e $file1 && "$file1" != '-' ]]; then 156 return 157 fi 158 rest11="${rest1#$sep}" 159 file2="${rest11%%$sep*}" 160 rest2="${rest11#$file2}" 161 while [[ "$rest2" = ::* ]]; do 162 if [[ "$rest2" = "::" ]]; then 163 break 164 else 165 rest2="${rest2#$sep$sep}" 166 file2="${rest2%%$sep*}" 167 rest2="${rest2#$file2}" 168 file2="${rest11%$rest2}" 169 fi 170 done 171 if [[ "$file2" != "" ]]; then 172 in_file="-i$file2" 173 fi 174 rest2="${rest11#$file2}" 175 rest11="$rest1" 176 177 if cmd_exist html2text || cmd_exist elinks || cmd_exist links || cmd_exist lynx || cmd_exist w3m; then 178 PARSEHTML=yes 179 else 180 PARSEHTML=no 181 fi 182 183 if [[ "$cmd" = "" ]]; then 184 type=$(filetype "$file1") || exit 1 185#ifdef lsbom 186 if cmd_exist lsbom; then 187 if [[ ! -f "$file1" ]]; then 188 if [[ "$type" = *directory* ]]; then 189 if [[ "$file1" = *.pkg ]]; then 190 if [[ -f "$file1/Contents/Archive.bom" ]]; then 191 type="bill of materials" 192 file1="$file1/Contents/Archive.bom" 193 msg "This is a Mac OS X archive directory, showing its contents (bom file)" 194 fi 195 fi 196 fi 197 fi 198 fi 199#endif 200 get_cmd "$type" "$file1" "$rest1" 201 if [[ "$cmd" != "" ]]; then 202 show "-$rest1" 203 else 204 isfinal "$type" "$file1" "$rest11" 205 fi 206 elif [[ "$c1" = "" ]]; then 207 set -A c1 "${cmd[@]}" 208 type=$("${c1[@]}" | filetype -) || exit 1 209 get_cmd "$type" "$file1" "$rest1" 210 if [[ "$cmd" != "" ]]; then 211 show "-$rest1" 212 else 213 "${c1[@]}" | isfinal "$type" - "$rest11" 214 fi 215 elif [[ "$c2" = "" ]]; then 216 set -A c2 "${cmd[@]}" 217 type=$("${c1[@]}" | "${c2[@]}" | filetype -) || exit 1 218 get_cmd "$type" "$file1" "$rest1" 219 if [[ "$cmd" != "" ]]; then 220 show "-$rest1" 221 else 222 "${c1[@]}" | "${c2[@]}" | isfinal "$type" - "$rest11" 223 fi 224 elif [[ "$c3" = "" ]]; then 225 set -A c3 "${cmd[@]}" 226 type=$("${c1[@]}" | "${c2[@]}" | "${c3[@]}" | filetype -) || exit 1 227 get_cmd "$type" "$file1" "$rest1" 228 if [[ "$cmd" != "" ]]; then 229 show "-$rest1" 230 else 231 "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | isfinal "$type" - "$rest11" 232 fi 233 elif [[ "$c4" = "" ]]; then 234 set -A c4 "${cmd[@]}" 235 type=$("${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | filetype -) || exit 1 236 get_cmd "$type" "$file1" "$rest1" 237 if [[ "$cmd" != "" ]]; then 238 show "-$rest1" 239 else 240 "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | isfinal "$type" - "$rest11" 241 fi 242 elif [[ "$c5" = "" ]]; then 243 set -A c5 "${cmd[@]}" 244 type=$("${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | "${c5[@]}" | filetype -) || exit 1 245 get_cmd "$type" "$file1" "$rest1" 246 if [[ "$cmd" != "" ]]; then 247 echo "$0: Too many levels of encapsulation" 248 else 249 "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | "${c5[@]}" | isfinal "$type" - "$rest11" 250 fi 251 fi 252} 253 254get_cmd () { 255 cmd= 256 typeset t 257 if [[ "$1" = *[bg]zip*compress* || "$1" = *compress\'d\ * || "$1" = *packed\ data* || "$1" = *LZMA\ compressed* || "$1" = *lzip\ compressed* || "$1" = *[Xx][Zz]\ compressed* ]]; then ## added '#..then' to fix vim's syntax parsing 258 if [[ "$3" = $sep$sep ]]; then 259 return 260#ifdef bzip2 261 elif [[ "$1" = *bzip*compress* ]] && cmd_exist bzip2; then 262 set -A cmd bzip2 -cd "$2" 263 if [[ "$2" != - ]]; then filen="$2"; fi 264 case "$filen" in 265 *.bz2) filen="${filen%.bz2}";; 266 *.tbz) filen="${filen%.tbz}.tar";; 267 esac 268 return 269#endif 270#ifdef lzip 271 elif [[ "$1" = *lzip\ compressed* ]] && cmd_exist lzip; then 272 set -A cmd lzip -cd "$2" 273 if [[ "$2" != - ]]; then filen="$2"; fi 274 case "$filen" in 275 *.lz) filen="${filen%.lz}";; 276 *.tlz) filen="${filen%.tlz}.tar";; 277 esac 278#endif 279#ifdef lzma 280# preliminary minimal support for lzma (not in magic file yet) 281 elif [[ "$1" = *LZMA\ compressed* ]] && cmd_exist lzma; then 282 set -A cmd lzma -cd "$2" 283 if [[ "$2" != - ]]; then filen="$2"; fi 284 case "$filen" in 285 *.lzma) filen="${filen%.lzma}";; 286 *.tlz) filen="${filen%.tlz}.tar";; 287 esac 288#endif 289 elif [[ "$1" = *gzip\ compress* || "$1" = *compress\'d\ * || "$1" = *packed\ data* ]]; then ## added '#..then' to fix vim's syntax parsing 290 set -A cmd gzip -cd "$2" 291 if [[ "$2" != - ]]; then filen="$2"; fi 292 case "$filen" in 293 *.gz) filen="${filen%.gz}";; 294 *.tgz) filen="${filen%.tgz}.tar";; 295 esac 296#ifdef xz 297 elif [[ "$1" = *[Xx][Zz]\ compressed* ]] && cmd_exist xz; then 298 set -A cmd xz -cd "$2" 299 if [[ "$2" != - ]]; then filen="$2"; fi 300 case "$filen" in 301 *.xz) filen="${filen%.xz}";; 302 *.txz) filen="${filen%.txz}.tar";; 303 esac 304#endif 305 fi 306 return 307 fi 308 309 rsave="$rest1" 310 rest1="$rest2" 311 if [[ "$file2" != "" ]]; then 312 if [[ "$1" = *\ tar* || "$1" = *\ tar* ]]; then 313 set -A cmd istar "$2" "$file2" 314 elif [[ "$1" = *Debian* ]]; then 315 data=`ar t "$2"|grep data.tar` 316 set -A cmd2 "unpack_cmd" "$data" 317 t=$(nexttmp) 318 if [[ "$file2" = control/* ]]; then 319 istemp "ar p" "$2" control.tar.gz | gzip -dc - > "$t" 320 file2=".${file2:7}" 321 else 322 istemp "ar p" "$2" $data | $("${cmd2[@]}") > "$t" 323 fi 324 set -A cmd istar "$t" "$file2" 325#ifdef rpm2cpio,cpio 326 elif [[ "$1" = *RPM* ]] && cmd_exist cpio && ( cmd_exist rpm2cpio || cmd_exist rpmunpack ); then 327 set -A cmd isrpm "$2" "$file2" 328#elif rpmunpack,cpio 329 elif [[ "$1" = *RPM* ]] && cmd_exist cpio && cmd_exist rpmunpack; then 330 set -A cmd isrpm "$2" "$file2" 331#endif 332#ifdef fastjar 333 elif [[ "$1" = *Jar\ archive* ]] && cmd_exist fastjar; then 334 set -A cmd isjar "$2" "$file2" 335#endif 336#ifdef unzip 337 elif [[ "$1" = *Zip* || "$1" = *ZIP* ]] && cmd_exist unzip; then 338 set -A cmd istemp "unzip -avp" "$2" "$file2" 339#endif 340#ifdef unrar 341 elif [[ "$1" = *RAR\ archive* ]]; then 342 if cmd_exist unrar; then 343 set -A cmd istemp "unrar p -inul" "$2" "$file2" 344 elif cmd_exist rar; then 345 set -A cmd istemp "rar p -inul" "$2" "$file2" 346 elif cmd_exist bsdtar; then 347 set -A cmd istemp "bsdtar Oxf" "$2" "$file2" 348 fi 349#elif rar 350 elif [[ "$1" = *RAR\ archive* ]] && cmd_exist rar; then 351 set -A cmd istemp "rar p -inul" "$2" "$file2" 352#elif bsdtar 353 elif [[ "$1" = *RAR\ archive* ]] && cmd_exist bsdtar; then 354 set -A cmd istemp "bsdtar Oxf" "$2" "$file2" 355#endif 356#ifdef 7za 357 elif [[ "$1" = *7-zip\ archive* || "$1" = *7z\ archive* ]] && cmd_exist 7za; then 358 set -A cmd istemp "7za e -so" "$2" "$file2" 359 elif [[ "$1" = *7-zip\ archive* || "$1" = *7z\ archive* ]] && cmd_exist 7zr; then 360 set -A cmd istemp "7zr e -so" "$2" "$file2" 361#elif 7zr 362 elif [[ "$1" = *7-zip\ archive* || "$1" = *7z\ archive* ]] && cmd_exist 7zr; then 363 set -A cmd istemp "7zr e -so" "$2" "$file2" 364#endif 365#ifdef cabextract 366 elif [[ "$1" = *[Cc]abinet* ]] && cmd_exist cabextract; then 367 set -A cmd iscab "$2" "$file2" 368#endif 369 elif [[ "$1" = *\ ar\ archive* ]]; then 370 set -A cmd istemp "ar p" "$2" "$file2" 371#ifdef isoinfo 372 elif [[ "$1" = *ISO\ 9660* ]] && cmd_exist isoinfo; then 373 set -A cmd isoinfo "-i$2" "-x$file2" 374#endif 375 fi 376 if [[ "$cmd" != "" ]]; then 377 filen="$file2" 378 fi 379 fi 380} 381 382#ifdef cabextract 383iscab () { 384 typeset t 385 if [[ "$1" = - ]]; then 386 t=$(nexttmp) 387 cat > "$t" 388 set "$t" "$2" 389 fi 390 cabextract -pF "$2" "$1" 391} 392#endif 393 394istar () { 395 $tarcmd Oxf "$1" "$2" 2>/dev/null 396} 397 398#ifdef dvi2tty 399isdvi () { 400 typeset t 401 if [[ "$1" != *.dvi ]]; then 402 t="$tmpdir/tmp.dvi" 403 cat "$1" > "$t" 404 set "$t" 405 fi 406 dvi2tty -q "$1" 407} 408#endif 409 410# istemp wrapper for helpers that cannot read from stdin 411istemp () { 412 typeset prog 413 typeset t 414 prog="$1" 415 t="$2" 416 shift 417 shift 418 if [[ "$t" = - ]]; then 419 t=$(nexttmp) 420 cat > "$t" 421 fi 422 if [[ $# -gt 0 ]]; then 423 $prog "$t" "$@" 2>/dev/null 424 else 425 $prog "$t" 2>/dev/null 426 fi 427} 428 429# nodash wrapper for helpers who don't understand '-' but can deal with stdin 430nodash () { 431 typeset prog 432 prog="$1" 433 shift 434 if [[ "$1" = - ]]; then 435 shift 436 if [[ $# -gt 0 ]]; then 437 $prog "$@" 2>/dev/null 438 else 439 $prog 2>/dev/null 440 fi 441 else 442 $prog "$@" 2>/dev/null 443 fi 444} 445 446isrpm () { 447 if cmd_exist rpm2cpio && cmd_exist cpio; then 448 typeset t 449 if [[ "$1" = - ]]; then 450 t=$(nexttmp) 451 cat > "$t" 452 set "$t" "$2" 453 fi 454 # setup $b as a batch file containing "$b.out" 455 typeset b 456# nasty hack to make rpm inspection work on MacOSX (and other BSD based systems) 457#ifdef bsd_cpio 458 b=$(nexttmp -d) 459 rpm2cpio "$1" 2>/dev/null|(cd $b; pax -r "$2" 2>/dev/null) 460 cat "$b/$2" 461#else 462 b=$(nexttmp) 463 echo "$b.out" > "$b" 464 # to support older versions of cpio the --to-stdout option is not used here 465 rpm2cpio "$1" 2>/dev/null|cpio -i --quiet --rename-batch-file "$b" "$2" 466 cat "$b.out" 467#endif 468 elif cmd_exist rpmunpack && cmd_exist cpio; then 469#ifdef bsd_cpio 470 b=$(nexttmp -d) 471 cat "$1" | rpmunpack | gzip -cd |(cd $b; pax -r "$2" 2>/dev/null) 472 cat "$b/$2" 473#else 474 # rpmunpack will write to stdout if it gets file from stdin 475 # extract file $2 from archive $1, assume that cpio is sufficiently new 476 # (option --to-stdout existing) if rpmunpack is installed 477 cat "$1" | rpmunpack | gzip -cd | cpio -i --quiet --to-stdout "$2" 478#endif 479 fi 480} 481 482#ifdef fastjar 483isjar () { 484 case "$2" in 485 /*) echo "lesspipe can't unjar files with absolute paths" >&2 486 exit 1 487 ;; 488 ../*) echo "lesspipe can't unjar files with ../ paths" >&2 489 exit 1 490 ;; 491 esac 492 typeset d 493 d=$(nexttmp -d) 494 [[ -d "$d" ]] || exit 1 495 cat "$1" | ( 496 cd "$d" 497 fastjar -x "$2" 498 if [[ -f "$2" ]]; then 499 cat "$2" 500 fi 501 ) 502} 503#endif 504 505# TODO 506#parsexml () { nodash "elinks -dump -default-mime-type text/xml" "$1"; } 507parsehtml () { 508 if [[ "$PARSEHTML" = no ]]; then 509 msg "No suitable tool for HTML parsing found, install one of html2text, elinks, links, lynx or w3m" 510 return 511#ifdef html2text 512 elif cmd_exist html2text; then 513 if [[ "$1" = - ]]; then html2text; else html2text "$1"; fi 514#ifdef lynx 515 elif cmd_exist lynx; then 516 if [[ "$1" = - ]]; then set - -stdin; fi 517 lynx -dump -force_html "$1" && return 518#endif 519#ifdef w3m 520 elif cmd_exist w3m; then 521 nodash "w3m -dump -T text/html" "$1" 522#endif 523#ifdef elinks 524 elif cmd_exist elinks; then 525 nodash "elinks -dump -force-html" "$1" 526#endif 527#ifdef links 528 elif cmd_exist links; then 529 if [[ "$1" = - ]]; then set - -stdin; fi 530 links -dump -force_html "$1" 531#endif 532 fi 533} 534 535unpack_cmd() { 536 cmd_string="cat" 537 if [[ "$1" == *xz ]]; then 538 cmd_string="xz -dc -" 539 elif [[ "$1" == *gz ]]; then 540 cmd_string="gzip -dc -" 541 elif [[ "$1" == *bz2 ]]; then 542 cmd_string="bzip2 -dc -" 543 elif [[ "$1" == *lzma ]]; then 544 cmd_string="lzma -dc -" 545 fi 546 echo "$cmd_string" 547} 548 549isfinal() { 550 typeset t 551 if [[ "$3" = $sep$sep ]]; then 552 cat "$2" 553 return 554 elif [[ "$3" = $sep* ]]; then 555# the next conditional is only there to conditionally remove syntax highlighting code 556#ifdef perl 557 if [[ "$3" = $sep ]]; then 558 msg "append :. or :<filetype> to activate syntax highlighting" 559 else 560 lang=${3#$sep} 561 lang="-l ${lang#.}" 562 lang=${lang%%-l } 563 if cmd_exist code2color; then 564 code2color $PPID ${in_file:+"$in_file"} $lang "$2" 565 if [[ $? = 0 ]]; then 566 return 567 fi 568 fi 569 fi 570#endif 571 cat "$2" 572 return 573 fi 574 575 # color requires -r or -R when calling less 576 typeset COLOR 577 if [[ $(tput colors) -ge 8 && ("$LESS" = *-*r* || "$LESS" = *-*R*) ]]; then 578 COLOR="--color=always" 579 fi 580 581 if [[ "$1" = *No\ such* ]]; then 582 exit 1 583 elif [[ "$1" = *directory* ]]; then 584 set -A cmd ls -lA $COLOR "$2" 585 if ! ls $COLOR > /dev/null 2>&1; then 586 set -A cmd ls -lA -G "$2" 587 if ! ls -lA -G > /dev/null 2>&1; then 588 set -A cmd ls -lA "$2" 589 fi 590 fi 591 msg "This is a directory, showing the output of ${cmd[@]}" 592 if [[ ${cmd[2]} = '-G' ]]; then 593 CLICOLOR_FORCE=1 "${cmd[@]}" 594 else 595 "${cmd[@]}" 596 fi 597 elif [[ "$1" = *\ tar* || "$1" = *\ tar* ]]; then 598 msg "use tar_file${sep}contained_file to view a file in the archive" 599#ifdef tarcolor 600 if [[ -n $COLOR ]] && cmd_exist tarcolor; then 601 $tarcmd tvf "$2" | tarcolor 602 else 603 $tarcmd tvf "$2" 604 fi 605#else 606 $tarcmd tvf "$2" 607#endif 608#ifdef rpm,rpm2cpio,cpio 609 elif [[ "$1" = *RPM* ]]; then 610 header="use RPM_file${sep}contained_file to view a file in the RPM" 611 if cmd_exist rpm; then 612 echo $header 613 istemp "rpm -qivp" "$2" 614 header=""; 615 fi 616 if cmd_exist cpio && cmd_exist rpm2cpio; then 617 echo $header 618 echo "================================= Content ======================================" 619 istemp rpm2cpio "$2" 2>/dev/null|cpio -i -tv 2>/dev/null 620 elif cmd_exist cpio && cmd_exist rpmunpack; then 621 echo $header 622 echo "================================= Content ======================================" 623 cat "$2" | rpmunpack | gzip -cd | cpio -i -tv 2>/dev/null 624 else 625 msg "please install rpm2cpio or rpmunpack to see the contents of RPM files" 626 fi 627#elif rpm2cpio,cpio 628 elif [[ "$1" = *RPM* ]]; then 629 if cmd_exist cpio && cmd_exist rpm2cpio; then 630 msg "use RPM_file${sep}contained_file to view a file in the RPM" 631 echo "================================= Content ======================================" 632 istemp rpm2cpio "$2" 2>/dev/null|cpio -i -tv --quiet 633 elif cmd_exist cpio && cmd_exist rpmunpack; then 634 msg "use RPM_file${sep}contained_file to view a file in the RPM" 635 echo "================================= Content ======================================" 636 cat "$2" | rpmunpack | gzip -cd | cpio -i -tv --quiet 637 else 638 msg "please install rpm2cpio or rpmunpack to see the contents of RPM files" 639 fi 640#elif rpmunpack,cpio 641 elif [[ "$1" = *RPM* ]]; then 642 if cmd_exist cpio && cmd_exist rpmunpack; then 643 msg "use RPM_file${sep}contained_file to view a file in the RPM" 644 echo "================================= Content ======================================" 645 cat "$2" | rpmunpack | gzip -cd | cpio -i -tv --quiet 646 else 647 msg "please install rpm2cpio or rpmunpack to see the contents of RPM files" 648 fi 649#endif 650#ifdef groff 651 elif [[ "$1" = *roff* ]] && cmd_exist groff; then 652 DEV=utf8 653 if [[ $LANG != *UTF*8* && $LANG != *utf*8* ]]; then 654 if [[ "$LANG" = ja* ]]; then 655 DEV=nippon 656 else 657 DEV=latin1 658 fi 659 fi 660 MACRO=andoc 661 if [[ "$2" = *.me ]]; then 662 MACRO=e 663 elif [[ "$2" = *.ms ]]; then 664 MACRO=s 665 fi 666 msg "append $sep to filename to view the nroff source" 667 groff -s -p -t -e -T$DEV -m$MACRO "$2" 668#endif 669 elif [[ "$1" = *Debian* ]]; then 670 msg "use Deb_file${sep}contained_file to view a file in the Deb" 671#ifdef dpkg 672 if cmd_exist dpkg; then 673 nodash "dpkg -I" "$2" 674 else 675 echo 676 istemp "ar p" "$2" control.tar.gz | gzip -dc - | $tarcmd tvf - | sed -r 's/(.{48})\./\1control/' 677 fi 678#else 679 echo 680 istemp "ar p" "$2" control.tar.gz | gzip -dc - | $tarcmd tvf - | sed -r 's/(.{48})\./\1control/' 681#endif 682 data=`ar t "$2"|grep data.tar` 683 set -A cmd2 "unpack_cmd" "$data" 684 echo 685 istemp "ar p" "$2" $data | $("${cmd2[@]}") | $tarcmd tvf - 686#ifdef perldoc 687 # do not display all perl text containing pod using perldoc 688 #elif [[ "$1" = *Perl\ POD\ document\ text* || "$1" = *Perl5\ module\ source\ text* ]]; then 689 elif [[ "$1" = *Perl\ POD\ document\ text$NOL_A_P* ]] && cmd_exist perldoc; then 690 msg "append $sep to filename to view the perl source" 691 istemp perldoc "$2" 692#endif 693 elif [[ "$1" = *\ script* ]]; then 694 set "plain text" "$2" 695 elif [[ "$1" = *text\ executable* ]]; then 696 set "plain text" "$2" 697#ifdef pstotext 698 elif [[ "$1" = *PostScript$NOL_A_P* ]]; then 699 if cmd_exist pstotext; then 700 msg "append $sep to filename to view the postscript file" 701 nodash pstotext "$2" 702 elif cmd_exist ps2ascii; then 703 msg "append $sep to filename to view the postscript file" 704 istemp ps2ascii "$2" 705 else 706 msg "install pstotext or ps2ascii to view a textual representation of the file contents" 707 fi 708#elif ps2ascii 709 elif [[ "$1" = *PostScript$NOL_A_P* ]]; then 710 if cmd_exist ps2ascii; then 711 msg "append $sep to filename to view the postscript file" 712 istemp ps2ascii "$2" 713 else 714 msg "install pstotext or ps2ascii to view a textual representation of the file contents" 715 fi 716#endif 717 elif [[ "$1" = *executable* ]]; then 718 msg "append $sep to filename to view the raw file" 719 nodash strings "$2" 720 elif [[ "$1" = *\ ar\ archive* ]]; then 721 msg "use library${sep}contained_file to view a file in the archive" 722 istemp "ar vt" "$2" 723#ifdef nm 724 elif [[ "$1" = *shared* ]] && cmd_exist nm; then 725 msg "This is a dynamic library, showing the output of nm" 726 istemp nm "$2" 727#endif 728#ifdef fastjar 729 elif [[ "$1" = *Jar\ archive* ]] && cmd_exist fastjar; then 730 msg "use jar_file${sep}contained_file to view a file in the archive" 731 nodash "fastjar -tf" "$2" 732#endif 733#ifdef unzip 734 elif [[ "$1" = *Zip* || "$1" = *ZIP* ]] && cmd_exist unzip; then 735 msg "use zip_file${sep}contained_file to view a file in the archive" 736 istemp "unzip -lv" "$2" 737#endif 738#ifdef unrar 739 elif [[ "$1" = *RAR\ archive* ]]; then 740 if cmd_exist unrar; then 741 msg "use rar_file${sep}contained_file to view a file in the archive" 742 istemp "unrar v" "$2" 743 elif cmd_exist rar; then 744 msg "use rar_file${sep}contained_file to view a file in the archive" 745 istemp "rar v" "$2" 746 elif cmd_exist bsdtar; then 747 msg "use rar_file${sep}contained_file to view a file in the archive" 748 istemp "bsdtar tvf" "$2" 749 fi 750#elif rar 751 elif [[ "$1" = *RAR\ archive* ]] && cmd_exist rar; then 752 msg "use rar_file${sep}contained_file to view a file in the archive" 753 istemp "rar v" "$2" 754#elif bsdtar 755 elif [[ "$1" = *RAR\ archive* ]] && cmd_exist bsdtar; then 756 msg "use rar_file${sep}contained_file to view a file in the archive" 757 istemp "bsdtar tvf" "$2" 758#endif 759#ifdef 7za 760 elif [[ "$1" = *7-zip\ archive* || "$1" = *7z\ archive* ]] && cmd_exist 7za; then 761 typeset res 762 res=$(istemp "7za l" "$2") 763 if [[ "$res" = *\ 1\ file* ]]; then 764 msg "a 7za archive containing one file was silently unpacked" 765 if [[ "$2" != - ]]; then 766 7za e -so "$2" 2>/dev/null 767 else 768 # extract name of temporary file containing the 7za archive 769 t=${res#*Listing\ archive:\ } 770 t2=" 771" 772 t=${t%%$t2*} 773 7za e -so $t 2>/dev/null 774 fi 775 else 776 msg "use 7za_file${sep}contained_file to view a file in the archive" 777 echo "$res" 778 fi 779 elif [[ "$1" = *7-zip\ archive* || "$1" = *7z\ archive* ]] && cmd_exist 7zr; then 780 typeset res 781 res=$(istemp "7zr l" "$2") 782 if [[ "$res" = *\ 1\ file* ]]; then 783 msg "a 7za archive containing one file was silently unpacked" 784 if [[ "$2" != - ]]; then 785 7zr e -so "$2" 2>/dev/null 786 else 787 # extract name of temporary file containing the 7za archive 788 t=${res#*Listing\ archive:\ } 789 t2=" 790" 791 t=${t%%$t2*} 792 7zr e -so $t 2>/dev/null 793 fi 794 else 795 msg "use 7za_file${sep}contained_file to view a file in the archive" 796 echo "$res" 797 fi 798#elif 7zr 799 elif [[ "$1" = *7-zip\ archive* || "$1" = *7z\ archive* ]] && cmd_exist 7zr; then 800 typeset res 801 res=$(istemp "7zr l" "$2") 802 if [[ "$res" = *\ 1\ file* ]]; then 803 msg "a 7za archive containing one file was silently unpacked" 804 if [[ "$2" != - ]]; then 805 7zr e -so "$2" 2>/dev/null 806 else 807 # extract name of temporary file containing the 7za archive 808 t=${res#*Listing\ archive:\ } 809 t2=" 810" 811 t=${t%%$t2*} 812 7zr e -so $t 2>/dev/null 813 fi 814 else 815 msg "use 7za_file${sep}contained_file to view a file in the archive" 816 echo "$res" 817 fi 818#endif 819#ifdef cabextract 820 elif [[ "$1" = *[Cc]abinet* ]] && cmd_exist cabextract; then 821 msg "use cab_file${sep}contained_file to view a file in the cabinet" 822 istemp "cabextract -l" "$2" 823#endif 824#ifdef dvi2tty 825 elif [[ "$1" = *\ DVI* ]] && cmd_exist dvi2tty; then 826 msg "append $sep to filename to view the raw DVI file" 827 isdvi "$2" 828#endif 829 elif [[ "$PARSEHTML" = yes && "$1" = *HTML$NOL_A_P* ]]; then 830 msg "append $sep to filename to view the HTML source" 831 parsehtml "$2" 832#ifdef pdftotext 833 elif [[ "$1" = *PDF* ]] && cmd_exist pdftotext; then 834 msg "append $sep to filename to view the PDF source" 835 istemp pdftotext "$2" - 836#endif 837#ifdef pdftohtml 838 elif [[ "$PARSEHTML" = yes && "$1" = *PDF* ]] && cmd_exist pdftohtml; then 839 msg "append $sep to filename to view the PDF source" 840 t=$(nexttmp) 841 cat "$2" > "$t"; pdftohtml -stdout "$t" | parsehtml - 842#endif 843#ifdef h5dump 844 elif [[ "$1" = *Hierarchical\ Data\ Format* ]] && cmd_exist h5dump; then 845 istemp h5dump "$2" 846#endif 847#ifdef ncdump 848 elif [[ "$1" = *NetCDF* || "$1" = *Hierarchical\ Data\ Format* ]] && cmd_exist ncdump; then 849 istemp ncdump "$2" 850#endif 851#ifdef djvutxt 852 elif [[ "$1" = *DjVu* ]] && cmd_exist djvutxt; then 853 msg "append $sep to filename to view the DjVu source" 854 djvutxt "$2" 855#endif 856#ifdef antiword 857 elif [[ "$1" = *Microsoft\ Word* || "$1" = *Microsoft\ Office* ]]; then 858 if cmd_exist antiword; then 859 msg "append $sep to filename to view the raw word document" 860 antiword "$2" 861 elif cmd_exist catdoc; then 862 msg "append $sep to filename to view the raw word document" 863 catdoc "$2" 864 else 865 msg "install antiword or catdoc to view human readable text" 866 cat "$2" 867 fi 868#elif catdoc 869 # repeat same code as for antiword as both programs are equally suited 870 elif [[ "$1" = *Microsoft\ Word* || "$1" = *Microsoft\ Office* ]]; then 871 if cmd_exist antiword; then 872 msg "append $sep to filename to view the raw word document" 873 antiword "$2" 874 elif cmd_exist catdoc; then 875 msg "append $sep to filename to view the raw word document" 876 catdoc "$2" 877 else 878 msg "install antiword or catdoc to view human readable text" 879 cat "$2" 880 fi 881#endif 882#ifdef unrtf 883 elif [[ "$1" = *Rich\ Text\ Format$NOL_A_P* ]] && cmd_exist unrtf; then 884 if [[ "$PARSEHTML" = yes ]]; then 885 msg "append $sep to filename to view the RTF source" 886 istemp "unrtf --html" "$2" | parsehtml - 887 else 888 msg "append $sep to filename to view the RTF source" 889 istemp "unrtf --text" "$2" | sed -e "s/^### .*//" | fmt -s 890 fi 891#endif 892#ifdef xlhtml 893 elif [[ "$PARSEHTML" = yes && "$1" = *Excel\ document* ]] && cmd_exist xlhtml; then 894 msg "append $sep to filename to view the spreadsheet source" 895 xlhtml -te "$2" | parsehtml - 896#endif 897#ifdef ppthtml 898 elif [[ "$PARSEHTML" = yes && "$1" = *PowerPoint\ document* ]] && cmd_exist ppthtml; then 899 msg "append $sep to filename to view the PowerPoint source" 900 ppthtml "$2" | parsehtml - 901#endif 902#ifdef o3tohtml,unzip 903 elif [[ "$PARSEHTML" = yes && ("$1" = *OpenDocument\ [CHMPST]* || "$1" = *OpenOffice\.org\ 1\.x\ [CIWdgpst]*) ]] && cmd_exist unzip; then 904 if cmd_exist o3tohtml; then 905 msg "append $sep to filename to view the OpenOffice or OpenDocument source" 906 istemp "unzip -avp" "$2" content.xml | o3tohtml | parsehtml - 907 elif cmd_exist sxw2txt; then 908 msg "append $sep to filename to view the OpenOffice or OpenDocument source" 909 istemp sxw2txt "$2" 910 else 911 msg "install at least sxw2txt from the lesspipe package to see plain text in openoffice documents" 912 fi 913#elif unzip 914 elif [[ "$PARSEHTML" = yes && ("$1" = *OpenDocument\ [CHMPST]* || "$1" = *OpenOffice\.org\ 1\.x\ [CIWdgpst]*) ]] && cmd_exist unzip; then 915 if cmd_exist sxw2txt; then 916 msg "append $sep to filename to view the OpenOffice or OpenDocument source" 917 istemp sxw2txt "$2" 918 else 919 msg "install at least sxw2txt from the lesspipe package to see plain text in openoffice documents" 920 fi 921#endif 922#ifdef isoinfo 923 elif [[ "$1" = *ISO\ 9660* ]] && cmd_exist isoinfo; then 924 if [[ "$2" != - ]]; then 925 msg "append $sep to filename to view the raw data" 926 isoinfo -d -i "$2" 927 joliet=`isoinfo -d -i "$2" | egrep '^Joliet'|cut -c1` 928 echo "================================= Content ======================================" 929 isoinfo -lR$joliet -i "$2" 930 fi 931#endif 932#ifdef identify 933 elif [[ "$1" = *image\ data* || "$1" = *JPEG\ file* || "$1" = *JPG\ file* ]] && cmd_exist identify; then 934 msg "append $sep to filename to view the raw data" 935 identify -verbose "$2" 936#endif 937#ifdef id3v2 938 elif [[ "$1" = *MPEG\ *layer\ 3\ audio* || "$1" = *MPEG\ *layer\ III* || "$1" = *mp3\ file* || "$1" = *MP3* ]]; then 939 if cmd_exist id3v2; then 940 msg "append $sep to filename to view the raw data" 941 istemp "id3v2 -l" "$2" 942 elif cmd_exist mp3info2; then 943 msg "append $sep to filename to view the raw data" 944 mp3info2 "$2" 945 elif cmd_exist mp3info; then 946 msg "append $sep to filename to view the raw data" 947 mp3info "$2" 948 fi 949#elif mp3info2 950 elif [[ "$1" = *MPEG\ *layer\ 3\ audio* || "$1" = *MPEG\ *layer\ III* || "$1" = *mp3\ file* || "$1" = *MP3* ]] && cmd_exist mp3info2; then 951 msg "append $sep to filename to view the raw data" 952 mp3info2 "$2" 953#elif mp3info 954 elif [[ "$1" = *MPEG\ *layer\ 3\ audio* || "$1" = *MPEG\ *layer\ III* || "$1" = *mp3\ file* || "$1" = *MP3* ]] && cmd_exist mp3info; then 955 msg "append $sep to filename to view the raw data" 956 mp3info "$2" 957#endif 958#ifdef lsbom 959 elif [[ "$1" = *bill\ of\ materials* ]] && cmd_exist lsbom; then 960 msg "append $sep to filename to view the raw data" 961 lsbom -p MUGsf "$2" 962#endif 963 elif [[ "$1" = *perl\ Storable$NOL_A_P* ]]; then 964 msg "append $sep to filename to view the raw data" 965 perl -MStorable=retrieve -MData::Dumper -e '$Data::Dumper::Indent=1;print Dumper retrieve shift' "$2" 966#ifdef iconv 967 elif [[ "$1" = *UTF-8$NOL_A_P* && $LANG != *UTF-8 ]] && cmd_exist iconv; then 968 iconv -f UTF-8 "$2" 969 elif [[ "$1" = *ISO-8859$NOL_A_P* && $LANG != *ISO-8859-1 ]] && cmd_exist iconv; then 970 iconv -f ISO-8859-1 "$2" 971 elif [[ "$1" = *UTF-16$NOL_A_P* && $LANG != *UTF-16 ]] && cmd_exist iconv; then 972 iconv -f UTF-16 "$2" 973#endif 974#ifdef gpg 975 elif [[ "$1" = *GPG\ encrypted\ data* ]] && cmd_exist gpg; then 976 msg "append $sep to filename to view the encrypted file" 977 gpg -d "$2" 978#endif 979#ifdef plutil 980 elif [[ "$1" = *Apple\ binary\ property\ list* ]] && cmd_exist plutil; then 981 msg "append $sep to filename to view the raw data" 982 plutil -convert xml1 -o - "$2" 983#endif 984 elif [[ "$1" = *data$NOL_A_P* ]]; then 985 msg "append $sep to filename to view the raw data" 986 nodash strings "$2" 987 else 988 set "plain text" "$2" 989 fi 990# the next conditional is only there to remove syntax highlighting code 991#ifdef perl 992 if [[ "$1" = *plain\ text* ]]; then 993 if cmd_exist code2color; then 994 code2color $PPID ${in_file:+"$in_file"} "$2" 995 if [[ $? = 0 ]]; then 996 return 997 fi 998 fi 999 fi 1000#endif 1001 if [[ "$2" = - ]]; then 1002 cat 1003 fi 1004} 1005 1006# calling show with arg1 arg2 ... is equivalent to calling with arg1:arg2:... 1007IFS=$sep a="$@" 1008IFS=' ' 1009if [[ "$a" = "" ]]; then 1010 if [[ "$0" != /* ]]; then 1011 pat=`pwd`/ 1012 fi 1013 if [[ "$SHELL" = *csh ]]; then 1014 echo "setenv LESSOPEN \"|$pat$0 %s\"" 1015 if [[ "$LESS_ADVANCED_PREPROCESSOR" = '' ]]; then 1016 echo "setenv LESS_ADVANCED_PREPROCESSOR 1" 1017 fi 1018 else 1019 echo "LESSOPEN=\"|$pat$0 %s\"" 1020 echo "export LESSOPEN" 1021 if [[ "$LESS_ADVANCED_PREPROCESSOR" = '' ]]; then 1022 echo "LESS_ADVANCED_PREPROCESSOR=1; export LESS_ADVANCED_PREPROCESSOR" 1023 fi 1024 fi 1025else 1026 # check for pipes so that "less -f ... <(cmd) ..." works properly 1027 [[ -p "$1" ]] && exit 1 1028 show "$a" 1029fi 1030