1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-17 23:05:00 -05:00
pacman/contrib/pacsearch
Dan McGee 9781d0d637 Update GNU GPL boilerplate and copyright dates
Update the GPL boilerplate to direct people to the GNU website for a copy of
the license, as well as bump all of Judd's copyrights to 2007.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-10 22:55:39 -06:00

90 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# pacsearch - Adds color and install information to a 'pacman -Ss' search
#
# Copyright (C) 2006-2007 Dan McGee <dpmcgee@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#TODO: colors flag on commandline
readonly progname="pacsearch"
readonly version="1.0"
readonly CLR1='\\\e[0;34m'
readonly CLR2='\\\e[0;32m'
readonly CLR3='\\\e[0;35m'
readonly CLR4='\\\e[0;36m'
readonly CLR5='\\\e[0;31m'
readonly CLR6='\\\e[0;33m'
readonly CLR7='\\\e[1;36m'
readonly INST='\\\e[1;31m'
readonly BASE='\\\e[0m'
if [ "$1" = "--help" -o "$1" = "-h" ]; then
echo "Usage: $progname <pattern>"
echo "Ex: $progname ^gnome"
exit 0
fi
if [ "$1" = "--version" -o "$1" = "-v" ]; then
echo "$progname version $version"
echo "Copyright (C) 2006-2007 Dan McGee"
exit 0
fi
if [ -z "$1" -o "${1:0:1}" = "-" ]; then
echo "Usage: $progname <pattern>"
echo "Ex: $progname ^gnome"
exit 1
fi
# Make two temp files and send output of commands to these files
querydump=$(mktemp)
pacman -Qs $1 > $querydump
syncdump=$(mktemp)
pacman -Ss $1 > $syncdump
# Strip descriptions and 'local/' from -Qs query
instpkg=$(mktemp)
egrep '^[^ ]' $querydump | sed -e 's@^local/@@' > $instpkg
# Add pkgs not in sync db, mark pkgs that are installed
cat $instpkg | while read -r pkg; do
if [ -z "$(grep "$pkg" $syncdump)" ]; then
# grep package name; pipe to another grep that prints at most one
# line starting with 'local/', allows for comments >1 line
grep -A10 "$pkg" $querydump | grep -A10 -m1 "local/" >> $syncdump
fi
sed -i "s@^\(.\+/$pkg\)@\***\1@" $syncdump
done
# Print colorized package list and descriptions to screen
echo -e "$(sed -r \
-e "s@core/.*@$CLR1&$BASE@" \
-e "s@extra/.*@$CLR2&$BASE@" \
-e "s@community/.*@$CLR3&$BASE@" \
-e "s@testing/.*@$CLR4&$BASE@" \
-e "s@unstable/.*@$CLR5&$BASE@" \
-e "s@custom/.*@$CLR6&$BASE@" \
-e "s@local/.*@$CLR7&$BASE@" \
-e "s@(^|\*\*\*)([[:alnum:]]*/.* .*)@\1$CLR6\2$BASE@" \
-e "s@\*\*\*@$INST&@" \
< $syncdump )"
echo -en "\e[0m"
rm $querydump
rm $syncdump
rm $instpkg