aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-cat
blob: 45e0dd93ecc8269b26eb82f13f6dcf9368b840a8 (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
51
52
53
54
55
56
#!/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.

parser_definition() {
    setup REST help:usage -- "usage: ${0##*/} [pkg] [file...]"
    global_options silent
}

# shellcheck disable=1091
. cpt-lib

[ "$1" ] || {
    # Usage such as `cpt-cat '' build` is also valid.
    [ "$#" -gt 1 ] && shift
    set -- "${PWD##*/}" "$@"
}

pkg=$1; shift
pkg_list "$pkg" >/dev/null

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

# $sys_db and color variables are defined by cpt-lib
# shellcheck disable=2154
for file; do
    [ -f "$sys_db/$pkg/$file" ] || continue
    printf '%b%s:%b\n' "$colbold" "$file" "$colre" >&2
    cat "$sys_db/$pkg/$file"
done