-
Notifications
You must be signed in to change notification settings - Fork 13
/
lesspipe.sh
executable file
·89 lines (87 loc) · 1.94 KB
/
lesspipe.sh
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
#!/bin/sh -
#
# To use this filter with less, define LESSOPEN:
# export LESSOPEN="|~/bin/lesspipe.sh %s"
lesspipe() {
case "$1" in
*.[1-9n]|*.man|*.[1-9n].bz2|*.man.bz2|*.[1-9].gz|*.[1-9]x.gz|*.[1-9].man.gz)
case "$1" in
*.gz) DECOMPRESSOR="gunzip -c" ;;
*.bz2) DECOMPRESSOR="bunzip2 -c" ;;
*) DECOMPRESSOR="cat" ;;
esac
if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
if echo "$1" | grep -q ^/; then #absolute path
man -- "$1" | cat -s
else
man -- "./$1" | cat -s
fi
else
$DECOMPRESSOR -- "$1"
fi
;;
*.tar|*.gem)
tar tvvf "$1"
;;
*.tgz|*.tar.gz|*.tar.[zZ]|*.box)
tar tzvvf "$1"
;;
*.tar.bz2|*.tbz|*.tbz2)
tar jtvvf "$1"
;;
*.tar.xz|*.txz)
tar Jtvvf "$1"
;;
*initrd*.gz)
gunzip -c "$1" | cpio -tv
;;
*.[zZ]|*.gz|*.svgz)
gzip -dc -- "$1"
;;
*.bz2)
bzip2 -dc -- "$1"
;;
*.7z)
7z l "$1"
;;
*.xz)
xz -dc -- "$1"
;;
*.zip|*.Zip|*.ZIP|*.jar|*.war|*.sar|*.xpi|*.job|*.pylib|*.apk|*.egg)
zipinfo -- "$1"
;;
*.rar)
unrar v "$1"
;;
*.[rs]pm)
rq "$1"
;;
*.cpi|*.cpio|*.obscpio)
cpio -itv < "$1"
;;
*.htm|*.html)
exec w3m -T text/html "$1"
;;
*.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
if [ -x "`which identify`" ]; then
identify "$1"
else
echo "No identify available"
echo "Install ImageMagick to browse images"
fi
;;
*)
case "$1" in
*.gz) DECOMPRESSOR="gunzip -c" ;;
*.bz2) DECOMPRESSOR="bunzip2 -c" ;;
esac
if [ ! -z $DECOMPRESSOR ] ; then
$DECOMPRESSOR -- "$1" ;
fi
;;
# Can't remember why I wanted to allow use as a filter but it breaks
# hitting 'v' from less to edit.
# *) cat "$1" ;;
esac
}
lesspipe "$1" 2>/dev/null