This commit is contained in:
Stephan Raabe
2023-12-27 23:19:24 +01:00
parent 7a8de31afe
commit bd8fdde4d3
15 changed files with 282 additions and 148 deletions

View File

@@ -197,19 +197,82 @@ _writeConf() {
# _replaceInFile $startMarket $endMarker $customtext $targetFile
_replaceInFile() {
if grep -s "$1" $4 && grep -s "$2" $4 ;then
sed -i '/'"$1"'/,/'"$2"'/ {
//!d
/'"$1"'/a\
'"$3"'
}' $4
# Set function parameters
start_string=$1
end_string=$2
new_string="$3"
file_path=$4
# Counters
start_line_counter=0
end_line_counter=0
start_found=0
end_found=0
if [ -f $file_path ] ;then
# Detect Start String
while read -r line
do
((start_line_counter++))
if [[ $line = *$start_string* ]]; then
# echo "Start found in $start_line_counter"
start_found=$start_line_counter
break
fi
done < "$file_path"
# Detect End String
while read -r line
do
((end_line_counter++))
if [[ $line = *$end_string* ]]; then
# echo "End found in $end_line_counter"
end_found=$end_line_counter
break
fi
done < "$file_path"
# Check that deliminters exists
if [[ "$start_found" == "0" ]] ;then
echo "ERROR: Start deliminter not found."
sleep 2
fi
if [[ "$end_found" == "0" ]] ;then
echo "ERROR: End deliminter not found."
sleep 2
fi
# Replace text between delimiters
if [[ ! "$start_found" == "0" ]] && [[ ! "$end_found" == "0" ]] && [ "$start_found" -le "$end_found" ] ;then
# Remove the old line
((start_found++))
if [ ! "$start_found" == "$end_found" ] ;then
((end_found--))
sed -i "$start_found,$end_found d" $file_path
fi
# Add the new line
sed -i "$start_found i $new_string" $file_path
else
echo "ERROR: Delimiters syntax."
sleep 2
fi
else
echo "ERROR: $1 and/or $2 not found in $4"
echo "ERROR: Target file not found."
sleep 2
_goBack
fi
}
# _writeSettings $settingsFile $customtext
_writeSettings() {
if [ ! -f $1 ] ;then
touch $1
fi
echo "$2" > $1
}
# Return the version of the hyprland-settings script
_getVersion() {
echo $version