mabox-tools/bin/mb-setvar

28 lines
554 B
Plaintext
Raw Normal View History

#!/bin/bash
# mb-setvar: utility to set/change config variables
# Copyright (C) 2020 napcok <napcok@gmail.com>
if [[ $# < 1 ]]; then
self=$(basename $0)
echo "Usage: $self variable=value [/PATH/TO/CONFIG_FILE]"
exit 2
fi
if [[ $1 != *"="* ]]; then
self=$(basename $0)
echo "$self: First argument must be variable=value"
exit 2
fi
FILE=${2:-$HOME/.config/mabox/mabox.conf}
search=$(echo $1|cut -d= -f1)
if grep -Rq $search $FILE
then #found
sed -i s/^"$search=".*$/"$1"/ $FILE
else #not found
echo $1 >> $FILE
fi