Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 128 lines (107 sloc) 4.073 kb
#!/bin/bash
#
# pachist - A tool to show a more readable package history in Arch Linux
#
# Copyright (C) 2013-2014 Daniel Sandman <revoltism@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 3 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/>.
#
## What type of packages to list
fltr_1="starting"
fltr_2="upgraded"
fltr_3="downgraded"
fltr_4="\[ALPM\].installed"
fltr_5="\[ALPM\].reinstalled"
fltr_6="\[ALPM\].removed"
fltr_7="BAJS"
init_script() {
## Create default conf if it doesn't exist
[ ! -e "$HOME/.config/pachist.conf" ] && {
touch $HOME/.config/pachist.conf
printf '# This configuration file is created automatically with\n' >> $HOME/.config/pachist.conf
printf '# default settings upon removal.\n\n' >> $HOME/.config/pachist.conf
printf '[Lines]\nlines="20"\n\n' >> $HOME/.config/pachist.conf
printf '[Colors]\ncolor1="black"\ncolor2="white"\ncolor3="blue"\n\n' >> $HOME/.config/pachist.conf
}
}
usage() {
printf "$(gettext "pachist version 0.0.9")\n\n" "$(basename $0)"
printf "$(gettext "usage: %s [options] <number of lines>")\n\n" "$(basename $0)"
printf "$(gettext "options:")\n"
printf "$(gettext " -h, --help Show this help")\n"
printf "$(gettext " -v, --verbose Show messages")\n"
printf "$(gettext " --err Not as verbose, just warning messages")\n"
printf "$(gettext " <number> Number of lines to show")\n\n"
printf "$(gettext "examples:")\n"
printf "$(gettext " %s -v 50")\n" "$(basename $0)"
printf "$(gettext " yaourt -Syua --devel --noconfirm && %s -v 50")\n\n" "$(basename $0)"
printf "$(gettext "configuration:")\n"
printf "$(gettext " The configuration file can be found at")\n" "$(basename $0)"
printf "$(gettext " $HOME/.config/pachist.conf")\n\n" "$(basename $0)"
exit 0
}
get_colors() {
## fetch colors from config
col_1="$(awk -F'"' '/color1/{print $2}' $HOME/.config/pachist.conf)"
col_2="$(awk -F'"' '/color2/{print $2}' $HOME/.config/pachist.conf)"
col_3="$(awk -F'"' '/color3/{print $2}' $HOME/.config/pachist.conf)"
}
check_args() {
## Add options
while [ "$#" -ne "0" ]; do
case $1 in
-h|--help) usage ;;
-v|--verbose) fltr_7="\[ALPM-SCRIPTLET\]|[Ww]arning" ;;
--err) fltr_7="[Ww]arning" ;;
*[0-9]*) lines=$(echo $* | grep -o "[0-9]*");;
*) args[${#args[@]}]=$1 ;;
esac
shift
done
}
## The command that makes it happen.
filter() {
awk -F' ' /\($fltr_1\|$fltr_2\|$fltr_3\|$fltr_4\|$fltr_5\|$fltr_6\|$fltr_7\|starting\)/'{if ($4!="" && $5!="full") print $1,$2,substr($0, index($0,$3)+length($3)+1); else if ($5="full") print "";}' /var/log/pacman.log
}
## Insert last reboot.. (thanks to ymonad @ stackoverflow for this one)
insert_reboot() {
fg="\e[0;;31m" # red color
BOOT_TIME=$(date +"%F %H:%M" -d "$(cut -f1 -d. /proc/uptime) seconds ago")
REBOOT_FLAG=""
while read line; do
TMP1=${line%]*}
TMP2=${TMP1#[}
if [ -z "$REBOOT_FLAG" ] && [ "$TMP2" \> "$BOOT_TIME" ]; then
echo
echo -e "[$BOOT_TIME] "$fg"SYSTEM REBOOT (last)"
echo
REBOOT_FLAG="true"
fi
echo "$line"
done
}
## Add some formatting and reboot message
formatting() {
insert_reboot < <(filter | cat -s)
}
## execute and show the endresult
run_pachist() {
init_script
## Default number of lines to show
lines="$(awk -F'"' '/lines/{print $2}' $HOME/.config/pachist.conf)"
check_args $@
get_colors
formatting | colout '(\[.*\]) (starting.*|upgraded.*|downgraded.*|installed.*|reinstalled.*|removed.*) (\(.*\))' $col_1,$col_2,$col_3 | tail -n$lines
}
run_pachist $@
Jump to Line
Something went wrong with that request. Please try again.