summaryrefslogtreecommitdiff
path: root/folders.sh
blob: 0a3fcfc907ab1418eca4086a6b75e66d62d29627 (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
#!/bin/bash

function PKG_DATA_() {
    echo "${PKG_BASE}/data/$1"
}

export -f PKG_DATA_

function PKG_WORK_() {
    echo "${PKG_BASE}/work/${PKG_TARG}/$1"
}

export -f PKG_WORK_

function PKG_DEST_() {
    echo "${PKG_BASE}/dest/${PKG_TARG}/$1"
}

export -f PKG_DEST_

function pkg_ {
    case "${1:0:1}" in
        (/) echo "${PKG_DEST}$1";;
        (%) echo "${PKG_DATA}${1:1}";;
        (*) echo -"$1" | sed -e 's/^.//';;
    esac
}

export -f pkg_

function pkg: {
    declare -a argv
    declare argc=$#

    for ((i=0; $i != $argc; ++i)); do
        argv[$i]=$(pkg_ "$1")
        shift
    done

    "${argv[@]}"
}

export -f pkg: