mabox-tools/bin/mb-setvar

32 lines
743 B
Plaintext
Raw Permalink 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]"
echo "Current configuration:"
cat $HOME/.config/mabox/mabox.conf
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
search=$(echo $1|cut -d= -f1)
if [[ $search =~ "bottom_img" ]]; then
sed -i /^"$search="/d $FILE
fi
2022-05-18 21:43:29 +02:00
if grep -Rq $search= $FILE
then #found
2022-04-26 20:23:05 +02:00
sed -i s/^"$search=".*$/"$1"/ $FILE
#sed -i s/^"$search".*$/"$1"/ $FILE
else #not found
echo $1 >> $FILE
fi