2020-09-05 15:28:11 +02:00
|
|
|
#!/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]"
|
2020-09-21 12:23:52 +02:00
|
|
|
echo "Current configuration:"
|
|
|
|
cat $HOME/.config/mabox/mabox.conf
|
2020-09-05 15:28:11 +02:00
|
|
|
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}
|
2020-09-30 22:56:54 +02:00
|
|
|
#echo $1
|
2020-09-05 15:28:11 +02:00
|
|
|
search=$(echo $1|cut -d= -f1)
|
2020-09-21 12:23:52 +02:00
|
|
|
if [[ $search =~ "bottom_img" ]]; then
|
|
|
|
sed -i /^"$search="/d $FILE
|
|
|
|
fi
|
2020-09-05 15:28:11 +02:00
|
|
|
if grep -Rq $search $FILE
|
|
|
|
then #found
|
|
|
|
sed -i s/^"$search=".*$/"$1"/ $FILE
|
|
|
|
else #not found
|
|
|
|
echo $1 >> $FILE
|
|
|
|
fi
|