Misc updates to header-symbol-search and handy_funcs
[pkgusr] / etc / pkgusr / handy_funcs
1 # -*- shell-script -*-
2 # Copyright (C) 2007 - 2021 Steve Youngs <steve@sxemacs.org>
3
4 # What lies here is a collection of handy bash shell functions and
5 # aliases that make life a little easier for pkgusr.
6
7 verr()
8 {
9     local arg=$1
10     if [ -z "$arg" ]; then
11         arg=all
12     fi
13     case $arg in
14         (conf)    less ${HOME}/configure.err ;;
15         (install) less ${HOME}/install.err ;;
16         (check)   less ${HOME}/check.err ;;
17         (make)    less ${HOME}/make.err ;;
18         (upd)     less ${HOME}/upd.err ;;
19         (ver)     less ${HOME}/verupd.err ;;
20         (all)     less ${HOME}/*.err ;;
21     esac
22 }
23
24 vlog()
25 {
26     local arg=$1
27     if [ -z "$arg" ]; then
28         arg=all
29     fi
30     case $arg in
31         (conf)    less ${HOME}/configure.log ;;
32         (install) less ${HOME}/install.log ;;
33         (check)   less ${HOME}/check.log ;;
34         (make)    less ${HOME}/make.log ;;
35         (upd)     less ${HOME}/upd.log ;;
36         (ver)     less ${HOME}/verupd.log ;;
37         (all)     less ${HOME}/*.log ;;
38     esac
39 }
40
41 verrlog()
42 {
43     local arg=$1
44     if [ -z "$arg" ]; then
45         arg=all
46     fi
47     case $arg in
48         (conf)    less ${HOME}/configure.{err,log} ;;
49         (install) less ${HOME}/install.{err,log} ;;
50         (check)   less ${HOME}/check.{err,log} ;;
51         (make)    less ${HOME}/make.{err,log} ;;
52         (upd)     less ${HOME}/upd.{err,log} ;;
53         (ver)     less ${HOME}/verupd.{err,log} ;;
54         (all)     less ${HOME}/*.{err,log} ;;
55     esac
56 }
57
58 instg()
59 {
60     local arg=$1
61     if [ -z "$arg" ]; then
62         arg=err
63     fi
64     grep --colour=always '^\*\*\*' ${HOME}/install.${arg}|less
65 }
66
67 chkg()
68 {
69     local arg=$1
70     if [ -z "$arg" ]; then
71         arg=err
72     fi
73     grep --colour=always '^\*\*\*' ${HOME}/check.${arg}|less
74 }
75
76 makeg()
77 {
78     local arg=$1
79     if [ -z "$arg" ]; then
80         arg=err
81     fi
82     grep --colour=always '^\*\*\*' ${HOME}/make.${arg}|less
83 }
84
85 dlog()
86 {
87     for log in configure make check install upd verupd; do
88         [[ -f ${HOME}/${log}.err ]] && rm -v ${HOME}/${log}.err
89         [[ -f ${HOME}/${log}.log ]] && rm -v ${HOME}/${log}.log
90     done
91 }
92
93 updver()
94 {
95     local arg=${1}
96     sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
97     echo -n "Version updated... "
98     grep --colour Version:.*$ ${HOME}/.project
99 }
100
101 ipkg()
102 {
103     local top=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1)
104     local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
105     sed -n ${top},${bot}p ${HOME}/.project|less
106 }
107
108 gpkg()
109 {
110     local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
111     local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1)
112     sed -n ${top},${bot}p ${HOME}/.project|less
113 }
114
115 ## Check if there is a newer build script, maybe update.
116 #  NOTE: Updating needs SXEmacs.  It'll work in XEmacs and Emacs too,
117 #  but you'll need to change build-update() accordingly.
118 build-update()
119 {
120     if [ -x $(type -p sxemacs) ]; then
121         sxemacs -l /etc/pkgusr/bld-update.el
122     else
123         echo *** Sorry, you do not have SXEmacs installed.
124         echo *** Copying the new build script to ~/build-$(date +%Y%m%d)
125         cp -v /etc/pkgusr/skel-package/build \
126             ${HOME}/build-$(date +%Y%m%d)
127     fi
128 }
129
130 checkupdates()
131 {
132     local sysb=/etc/pkgusr/skel-package/build
133     local pkgb=${HOME}/build
134     local sysbv=$(${sysb} -V|awk '/build:/ {print $2;}')
135     local pkgbv=$(${pkgb} -V|awk '/build:/ {print $2;}')
136     
137     if [ ${sysb} -nt ${pkgb} ]; then
138         echo '*****************************************'
139         echo '*                                       *'
140         echo '*  B u i l d  S c r i p t  U p d a t e  *'
141         echo '*          A v a i l a b l e            *'
142         echo '*                                       *'
143         echo '*****************************************'
144         echo '       Your version:' ${pkgbv}
145         echo '  Available Version:' ${sysbv}
146         echo
147         echo 'For a SXEmacs based interactive update, run: "build-update"'
148         echo 'To turn this notice off, set $CHECKUPDATES to: "0"'
149         echo
150         echo -n 'Press [RETURN] to continue...'
151         read junk
152     fi
153 }
154
155 ## Convenience to allow existing pkgusrs to update their git
156 #  config
157 prep_git()
158 {
159     install -vdm755 ${HOME}/.config/git &&
160     ln -svf /etc/pkgusr/gitconfig ${HOME}/.config/git/config &&
161     # Nuke the old ~/.gitconfig
162     rm -v ${HOME}/.gitconfig 2>/dev/null || true
163 }
164
165 ## Aliases
166 # Repos/Websites
167 alias srepo='grep --colour Repo_Location:.*$ ${HOME}/.project'
168 alias rawrepo='srepo|cut -d" " -f2|tr -d "<>"'
169 alias trepo='grep --colour Repo_Type:.*$ ${HOME}/.project'
170 alias web='grep --colour Web_Site:.*$ ${HOME}/.project'
171 alias rawweb='web|tr -s " "|cut -d" " -f3|tr -d "<>"'
172 # Logs
173 alias alogs='ls -l ${HOME}/*.{err,log}'
174 alias lerr='ls -l ${HOME}/*.err'
175 alias llog='ls -l ${HOME}/*.log'
176 # Util
177 ## As of 2021-01-18 nano (v5.5) seems FUBAR'd
178 alias ebld='vi ${HOME}/build'
179 alias epro='vi ${HOME}/.project'
180 alias ebp='vi -a ${HOME}/{build,.project}'
181 # alias ebld='nano -w ${HOME}/build'
182 # alias epro='nano -w ${HOME}/.project'
183 # alias ebp='nano -w ${HOME}/{build,.project}'
184 alias deps='grep --colour "Deps: " ${HOME}/.project'
185 alias listp='pinky -l $(whoami)|less'
186 alias patches='find ${SLACKPKG}/**/$(whoami)|grep -E "(diff|patch)"'
187 alias vtar=less
188 alias xtar='tar xf'
189
190 H-pkg()
191 {
192         cat<<EOF|less
193
194 Logs:
195
196         alogs           List of build logs (showing size)
197         lerr            List just the error logs
198         llog            List just the .log logs
199         verr [LOG]      Display LOG, which can be:
200                                \`conf' -- configure.err
201                               \`check' -- check.err
202                             \`install' -- install.err
203                                \`make' -- make.err
204                                 \`upd' -- upd.err
205                                 \`ver' -- verupd.err
206                                 \`all' -- all error logs (default)
207         vlog [LOG]      Same as for \`verr', but for the .log files.
208         verrlog [LOG]   Same as for \`verr', but displays both the .err,
209                         and the .log files.
210         dlog            Removes all build logs
211         instg {err|log} Greps install.err (default) or install.log for
212                         pkgusr notifications ("*** some message")
213         chkg {err|log}  Greps check.err (default) or check.log for
214                         pkgusr notifications ("*** some message")
215         makeg {err|log} Greps make.err (default) or make.log for
216                         pkgusr notifications ("*** some message")
217
218 Package Notes/Content:
219
220         ipkg            Displays the \`Install Notes'.
221         gpkg            Displays the \`General Notes'.
222         listp           Displays the entire package info (piped through less(1))
223         srepo           Display the package's source repo location.
224         rawrepo         Output just the repo URL (to use with lynx, curl, etc)
225         trepo           Display the type of repo (git, svn, mercurial, tla etc)
226         web             Display the package's homepage URL.
227         rawweb          Output just the web URL (to use with lynx etc)
228         deps            Display the package's dependencies
229
230 Tarball Handling:
231
232         xtar [TARBALL]  Extract TARBALL
233         vtar [TARBALL]  List the contents of TARBALL
234
235 Build Scripts:
236
237         ebld            Edit the build script.
238         epro            Edit the .project file.
239         ebp             Edit the build script and the .project file.
240         updver [NEWVER] Updates the version in the .project.  It MUST be
241                         quoted to protect it from shell expansion.
242
243 Miscellaneous Bobs & Bits:
244
245         prep_git        Sets up ~/.config/git/config
246                         In the normal course of events you shouldn't need to
247                         use this as it happens during login if it is needed.
248         patches         Check for any Slackware patches. (see SLACKPKG var in
249                         bash_profile)
250
251
252 EOF
253 }
254
255 # Local variables:
256 # sh-basic-offset: 4
257 # End: