2 # pacsearch - Adds color and install information to a 'pacman -Ss' search
4 # Copyright (C) 2006-2007 Dan McGee <dpmcgee@gmail.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #TODO: colors flag on commandline
21 readonly progname
="pacsearch"
22 readonly version
="1.0"
24 readonly CLR1
='\\\e[0;34m'
25 readonly CLR2
='\\\e[0;32m'
26 readonly CLR3
='\\\e[0;35m'
27 readonly CLR4
='\\\e[0;36m'
28 readonly CLR5
='\\\e[0;31m'
29 readonly CLR6
='\\\e[0;33m'
30 readonly CLR7
='\\\e[1;36m'
31 readonly INST
='\\\e[1;31m'
32 readonly BASE
='\\\e[0m'
34 if [ "$1" = "--help" -o "$1" = "-h" ]; then
35 echo "Usage: $progname <pattern>"
36 echo "Ex: $progname ^gnome"
40 if [ "$1" = "--version" -o "$1" = "-v" ]; then
41 echo "$progname version $version"
42 echo "Copyright (C) 2006-2007 Dan McGee"
46 if [ -z "$1" -o "${1:0:1}" = "-" ]; then
47 echo "Usage: $progname <pattern>"
48 echo "Ex: $progname ^gnome"
52 # Make two temp files and send output of commands to these files
54 pacman
-Qs $1 > $querydump
56 pacman
-Ss $1 > $syncdump
58 # Strip descriptions and 'local/' from -Qs query
60 egrep '^[^ ]' $querydump |
sed -e 's@^local/@@' > $instpkg
62 # Add pkgs not in sync db, mark pkgs that are installed
63 cat $instpkg |
while read -r pkg
; do
64 if [ -z "$(grep "$pkg" $syncdump)" ]; then
65 # grep package name; pipe to another grep that prints at most one
66 # line starting with 'local/', allows for comments >1 line
67 grep -A10 "$pkg" $querydump |
grep -A10 -m1 "local/" >> $syncdump
69 sed -i "s@^\(.\+/$pkg\)@\***\1@" $syncdump
72 # Print colorized package list and descriptions to screen
74 -e "s@core
/.
*@
$CLR1&$BASE@
" \
75 -e "s@extra
/.
*@
$CLR2&$BASE@
" \
76 -e "s@community
/.
*@
$CLR3&$BASE@
" \
77 -e "s@testing
/.
*@
$CLR4&$BASE@
" \
78 -e "s@unstable
/.
*@
$CLR5&$BASE@
" \
79 -e "s@custom
/.
*@
$CLR6&$BASE@
" \
80 -e "s@local
/.
*@
$CLR7&$BASE@
" \
81 -e "s@
(^|\
*\
*\
*)([[:alnum
:]]*/.
* .
*)@\
1$CLR6\
2$BASE@
" \
82 -e "s@\
*\
*\
*@
$INST&@
" \