aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-cat
blob: bfc9d660e71692997c26129bd3c4e428c84d82e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh -e
# Concatanate package files in the installed package database
# File names are printed to stderr.

## SYNOPSIS:
## .Nm
## .Op Ar pkg
## .Op Ar file...

## DESCRIPTION:
## .Nm
## outputs the contents of the given package's database files to the standard
## output. The names of the files being printed will also be printed, but to
## stderr. Thus, you can pipe the contents of a file without worrying about
## mixing filenames into that file.
##
## If no package is specified,
## .Nm
## will assume that the package in the current directory is going to be printed.
##
## If no file is specified,
## .Nm
## will print the contents
## .Em build ,
## .Em depends ,
## .Em sources
## and
## .Em version
## files.

case "$1" in
    --help|-h)
        printf 'usage: %s [pkg] [file...]\n' "${0##*/}"
        exit 0
        ;;
    '')
        [ "$#" -gt 1 ] && shift
        set -- "${PWD##*/}" "$@"
esac

pkg=$1; shift
cpt-list "$pkg" >/dev/null

[ "$1" ] || set -- build depends sources version

for file; do
    [ -f "$CPT_ROOT/var/db/cpt/installed/$pkg/$file" ] || continue
    printf '\033[1m%s:\033[m\n' "$file" >&2
    cat "$CPT_ROOT/var/db/cpt/installed/$pkg/$file"
done