Update soundtest
[grml-scripts.git] / usr_bin / qma
1 #!/bin/zsh
2 # Filename:      qma
3 # Purpose:       "quick manual access"
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>, Matthias Kopfermann <maddi@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Don Sep 20 21:56:52 CEST 2007 [mika]
8 ################################################################################
9
10 . /etc/grml/lsb-functions
11 . /etc/grml/script-functions
12
13 check4progs man lzop vim || exit 1
14
15 VERSION='0.1'
16
17 MANDIR=${MANDIR:-$HOME/man}
18 if ! [ -d "$MANDIR" ] ; then
19    einfo "Creating $MANDIR."
20    mkdir $MANDIR ; eend $?
21 fi
22
23 usage() {
24    eerror "Usage: qma [section] manpage" ; eend 1
25    exit 1
26 }
27
28 case $1 in
29   -h*|--h*)
30     usage
31     ;;
32   -v*|--v*)
33     einfo "qma - version $VERSION" ; eend 0
34     exit 0
35     ;;
36   [0-9])
37     SECTION="${1}"
38     SECTIONFILE=".${1}"
39     MANPAGE="$2"
40     SEARCH="$3"
41     ;;
42   *)
43     SECTION=''
44     MANPAGE="$1"
45     SEARCH="$2"
46     ;;
47 esac
48
49
50 if [ -z "$MANPAGE" ] ; then
51    usage
52 fi
53
54 QUICKMAN="${MANDIR}/${MANPAGE}${SECTIONFILE}.txt.lzo"
55
56 if ! [ -f "$QUICKMAN" ] ; then
57    einfo "Writing manpage to $QUICKMAN"
58    if man $SECTION $MANPAGE 1>/dev/null ; then
59       man $SECTION $MANPAGE | col -b | lzop -U >$QUICKMAN ; eend $?
60       einfo "Compressing manpage with lzop"
61       eend $?
62    else
63       exit 1
64       eend 1
65    fi
66 fi
67
68 vimconfig='
69          set filetype=man
70          "set hlsearch can be annoying so use <C-L> to dehighlight"
71         "shut up hlsearch when it confuses more than it helps and"
72          nn <silent> <C-L> :nohlsearch<cr>|redraw
73         "q should really end our document-reading like less does"
74          nn q :qa!<cr>
75         "different than q in that it quits only the current window when multiple windows "
76          nn Q :q!<cr>
77         "honor midnight-commander addicts :) "
78          nn <F10> :qa!<cr>
79         "use one wonderful vim feature to show all matches of the word in the document in ex-mode"
80          nn a ]I
81         "the other way round"
82          nn A [I
83          nn b <C-b>
84          nn <backspace> <C-f>
85          "nn f <C-f>
86          nn p }zz
87         "scroll the page down one line"
88          nn j <C-E>
89         "scroll the page up one line"
90          nn k <C-Y>
91         "the expectation of getting the next search via 'n' can not be ignored"
92          nn -n <ESC> :set invnumber<cr>
93          nn h :set invhlsearch<cr>
94         "Make toggling case-sensitive accessable via the letter i"
95          nn i :set invignorecase<cr>
96         "Make toggling case-sensitive accessable via the less convention via -i"
97          nn -i :set invignorecase<cr>
98          nn <space> <C-f>
99          nn <backspace> <C-b>
100          nn <enter> gg
101          nn S :split<cr>
102          nn V :vsplit<cr>
103         set filetype=man
104         set ignorecase
105         "Really not modify a document here"
106         set nomodifiable
107         set readonly
108         "We have a more modern approach to searching in vim!"
109         set incsearch
110 '
111
112 if [ -n "$SEARCH" ] ; then
113   vim -S  =( echo $vimconfig  ) +/"$SEARCH" =( lzop -cd ${QUICKMAN} )
114 else
115   vim -S =( echo $vimconfig  ) =( lzop -cd $QUICKMAN )
116 fi
117
118 einfo "Thanks for flying qma using vim and lzop." ; eend 0
119
120 ## END OF FILE #################################################################