aboutsummaryrefslogtreecommitdiff
path: root/dbx-link
blob: cab4ecb76cd8c2c13a7b442f577e1b533f5e116b (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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only

set -euo pipefail

if [[ $# -ne 1 ]]; then
    echo "ERROR: missing command to link" >&2
    exit 1
fi

r="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
c="dbx"
p="$HOME/.local/share/dbx/bin"

cmd="$1"
link="$p/$cmd"
if [[ -e "$link" ]]; then
    echo "already linked"
    exit
fi

if ! "$r/dbx-run" which "$cmd" &>/dev/null; then
    echo "ERROR: command '$cmd' not found"
    exit 1
fi

mkdir -p "$p"
echo "#!/bin/sh" > "$link"
echo "exec '$r/dbx-run' '$cmd' "'"$@"' >> "$link"
chmod +x "$link"