You are not logged in.

#1 2009-11-07 12:22:28

rwd
Member
Registered: 2009-02-08
Posts: 671

pacman suggestion: add own comment to a package that survives upgrades

I install and uninstall lots of packages, and once every few months I  clear out all unused explicitly installed stuff. The problem is that for quite a number of packages I forget why I installed it. Usually it is because some script of mine needs it, or to try out something, and the package comment isn't descriptive enough. So I wonder if it would be idea to somehow add one's own comment when installing something, so that a 'pacman -Qi packagename' for example would show it.  The most obvious solution would be editing a pkgbuilds from the repository, but they get overwritten with the next upgrade. And to recompile using ABS only to add a comment doesn't seem right. Has anyone else thought about this?

Last edited by rwd (2009-11-07 13:54:03)

Offline

#2 2009-11-07 13:15:50

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: pacman suggestion: add own comment to a package that survives upgrades

I think it's a good idea really. So I quickly wrote a script called pkgnote:

#pkgnote -v $pkgname shows comment
#pkgnote -e $pkgname edits comment

pkgnote_db="pkgnote.db" #i may want it at ~/.pkgnote.db

[ -f "${pkgnote_db}" ] || { echo "db file "${pkgnote_db}" does not exist" ; exit 1 ; }

view_pkgnote () {
    local pkg="$1"
    grep "^${pkg}: " "${pkgnote_db}" || echo "no comment for package \`${pkg}'"
}

edit_pkgnote () {
    local pkg="$1" note
    echo "comments for package \`${pkg}':"
    read note
    grep "^${pkg}: " "${pkgnote_db}" &>/dev/null &&
    sed -i "s/\(^${pkg}: \).*/\1${note}/" "${pkgnote_db}" ||
    echo "${pkg}: ${note}" >> "${pkgnote_db}"
}

until [ -z "$1" ] ; do
    case "$1" in
        -v|--view) view_pkgnote "$2" ; shift 2 ;;
        -e|--edit) edit_pkgnote "$2" ; shift 2 ;;
        *) echo "invalid option: $1" ; shift ;;
    esac
done

To improve this, i think maybe add some better regexp support and make use of `pacman -Q` and introduce a --delete switch and such.
Well... it's basically a script for comments about anything...
What do you think?

Last edited by lolilolicon (2009-11-07 13:21:51)


This silver ladybug at line 28...

Offline

#3 2009-11-07 13:48:33

rwd
Member
Registered: 2009-02-08
Posts: 671

Re: pacman suggestion: add own comment to a package that survives upgrades

Thanks! I'll give it a try. Some kind of integration/wrapper for pacman would be ideal though. In that case comments can be deleted as soon as a package gets removed. Also tags instead of a single comment field may be useful, so you can tag all packages for a certain project (or would this be the same as a custom 'group'?).

Last edited by rwd (2009-11-07 13:59:23)

Offline

#4 2009-11-07 15:25:52

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: pacman suggestion: add own comment to a package that survives upgrades

tags! that's a good idea too! so i added some basic tag actions:

#!/bin/bash

pkgnote_db="pkgnote.db"

[ -f "${pkgnote_db}" ] || touch "${pkgnote_db}" || exit 1

view_pkgnote () {
    local pkg="$1"
    grep "^${pkg}: " "${pkgnote_db}"
}

kill_pkgnote () {
    local pkg="$1"
    sed -i "/^${pkg}: /d" "${pkgnote_db}"
}

edit_pkgnote () {
    local pkg="$1" note
    echo "comments for package \`${pkg}':"
    read note
    grep "^${pkg}: " "${pkgnote_db}" &>/dev/null &&
    sed -i "s/\(^${pkg}: \).*/\1${note}/" "${pkgnote_db}" ||
    echo "${pkg}: ${note}" >> "${pkgnote_db}"
}

taga_pkgnote () {
    local tag="$1" pkgs=($2) pkg
    for pkg in "${pkgs[@]}" ; do
        grep "^${pkg}: .*\[\[${tag}\]\]" "${pkgnote_db}" &>/dev/null && continue
        grep "^${pkg}: " "${pkgnote_db}" &>/dev/null &&
        sed -i "s/^${pkg}: .*/& [[${tag}]]/" "${pkgnote_db}" ||
        echo "${pkg}: [[${tag}]]" >> "${pkgnote_db}"
    done
}

tagd_pkgnote () {
    local tag="$1"
    sed -i "/^[^[[]*\[\[${tag}\]\][^[[]*$/d;s/ \[\[${tag}\]\]//" "${pkgnote_db}"
}

tagl_pkgnote () {
    local tag="$1"
    echo "packages with tag [[$1]]:"
    sed "/\([^:]*\): .*\[\[${tag}\]\].*/!d;s//\1/" "${pkgnote_db}"
}

until [ -z "$1" ] ; do
    case "$1" in
        -v|--view)   view_pkgnote "$2" ; shift 2 ;;
        -e|--edit)   edit_pkgnote "$2" ; shift 2 ;;
        -d|--delete) kill_pkgnote "$2" ; shift 2 ;;
        -t|--tag)
            case "$2" in
                a|add)    taga_pkgnote "$3" "$4" ; shift 4 ;;
                d|delete) tagd_pkgnote "$3" ; shift 3 ;;
                l|list)   tagl_pkgnote "$3" ; shift 3 ;;
                *)        echo "invalid tag action: $2" ; shift 2 ;;
            esac ;;
        *) echo "invalid option: $1" ; shift ;;
    esac
done

several examples

$ ./pkgnote.sh -e pkg1 -e pkg2
comments for package `pkg1':
this is package 1 [[project 1]]    
comments for package `pkg2':
this is package 2
$ ./pkgnote.sh -v pkg1
pkg1: this is package 1 [[project 1]]
$ ./pkgnote.sh -t list 'project 1'
packages with tag [[project 1]]:
pkg1
$ ./pkgnote.sh -t add 'project 1' 'pkg2 pkg3 pkg4'
$ ./pkgnote.sh -t list 'project 1'
packages with tag [[project 1]]:
pkg1
pkg2
pkg3
pkg4
$ ./pkgnote.sh -t add 'project 2' 'pkg3'
$ ./pkgnote.sh -t d 'project 1'
$ ./pkgnote.sh -t list 'project 1'
packages with tag [[project 1]]:
$ ./pkgnote.sh -t list 'project 2'
packages with tag [[project 2]]:
pkg3

note: --edit also overwrites tag(s) of the package
        As seen in the example(note 'pkg3'), --tag delete <tag> will not remove the whole packge comment line from db, unless <tag> is the only tag this package has, which should be as expected.

Still, it's a script that can be used with any kind of short comments...

Last edited by lolilolicon (2009-11-07 16:06:26)


This silver ladybug at line 28...

Offline

Board footer

Powered by FluxBB