mb-setvar - utility to set/change config variables
parent
7149da49fb
commit
21b54444d5
|
@ -0,0 +1,27 @@
|
|||
#!/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
|
||||
|
Loading…
Reference in New Issue