~smlavine/scripts

ref: 5af0022d2df522079823605c7340e26ab9847202 scripts/src/addpackage -rwxr-xr-x 1.1 KiB
5af0022dSebastian LaVine dotfiles -> scripts 10 months ago
                                                                                
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
#!/bin/sh
# Copyright (c) 2020-2021 Sebastian LaVine <mail@smlavine.com>
# Licensed under the GNU GPLv3. See GPLv3.txt for details.
#
# File:        addpackage
# Description: Add the given package to smlss's install lists.
# Options:     -a        Add packages to the AUR list, not the Arch list.
# Arguments:   names of packages to add

usage()
{
	echo "Usage: addpackage [-$options] packages..."
}

options="a"
while getopts "$options" o; do
	case "$o" in
		a) aur=1 ;;
		*) usage && exit ;;
	esac
done

shift $((OPTIND - 1))

if [ "$#" -eq 0 ]; then
	usage
	exit
fi

pkgs="$*"

if [ ! "$SMLSS_DIR" ]; then
	# Single quotes intended, I don't want the value of $SMLSS_DIR here.
	# shellcheck disable=SC2016
	echo 'addpackage: error: $SMLSS_DIR does not exist.' >&2
	exit 1
fi

if [ "$aur" ]; then
	file="$SMLSS_DIR/aur-packages.txt"
else
	file="$SMLSS_DIR/packages.txt"
fi

echo "$pkgs" | tr ' ' '\n' | cat "$file" - | sort | sponge "$file" \
	&& git -C "$SMLSS_DIR" add "$file"

msg="$(basename "$file"): Add $(echo "$pkgs" | sed -e 's/ /, /g' -e 's/, $//')"

git -C "$SMLSS_DIR" commit -vem "$msg"