Update Replacement Function

This commit is contained in:
Stephan Raabe 2023-12-19 16:48:01 +01:00
parent eee71d8b5f
commit f6ad27e30f
5 changed files with 34 additions and 81 deletions

View File

@ -1,4 +1,4 @@
# ML4W dotfiles 2.7 BETA 1
# ML4W dotfiles 2.7 BETA 2
This is my configuration of Hyprland (Wayland) and Qtile (Xorg & Wayland) for Arch. This package includes an installation script to install and setup the required components.

View File

@ -193,6 +193,21 @@ _writeConf() {
fi
}
# _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
else
echo "ERROR: $1 and/or $2 not found in $4"
sleep 2
_goBack
fi
}
# Return the version of the hyprland-settings script
_getVersion() {
echo $version

View File

@ -19,26 +19,11 @@ customvalue=$(gum input --placeholder="Define the Apps label")
if [ ! -z $customvalue ]; then
# Replace in Template
customtext="${customtemplate/VALUE/"$customvalue"}"
# Ensure that markers are in target file
if grep -s "$startMarker" $targetFile && grep -s "$endMarker" $targetFile; then
# Write into File
sed -i '/'"$startMarker"'/,/'"$endMarker"'/ {
//!d
/'"$startMarker"'/a\
'"$customtext"'
}' $targetFile
# Reload Waybar
setsid $HOME/dotfiles/waybar/launch.sh 1>/dev/null 2>&1 &
_goBack
else
echo "ERROR: Marker not found."
sleep 2
_goBack
fi
_replaceInFile $startMarker $endMarker $customtext $targetFile
# Reload Waybar
setsid $HOME/dotfiles/waybar/launch.sh 1>/dev/null 2>&1 &
_goBack
else
echo "ERROR: Define a value."
sleep 2

View File

@ -26,55 +26,23 @@ customtemplate="VALUE\"bluetooth\","
customvalue=$(gum choose "SHOW" "HIDE")
if [ ! -z $customvalue ]; then
if [ "$customvalue" == "SHOW" ] ;then
customvalue=""
else
customvalue="//"
fi
# Replace in Template
customtext="${customtemplate/VALUE/"$customvalue"}"
# Ensure that markers are in target file
if grep -s "$startMarker" $targetFile1 && grep -s "$endMarker" $targetFile1 && grep -s "$startMarker" $targetFile2 && grep -s "$endMarker" $targetFile2 && grep -s "$startMarker" $targetFile3 && grep -s "$endMarker" $targetFile3 && grep -s "$startMarker" $targetFile4 && grep -s "$endMarker" $targetFile4; then
# Write into File
sed -i '/'"$startMarker"'/,/'"$endMarker"'/ {
//!d
/'"$startMarker"'/a\
'"$customtext"'
}' $targetFile1
# Write into File
sed -i '/'"$startMarker"'/,/'"$endMarker"'/ {
//!d
/'"$startMarker"'/a\
'"$customtext"'
}' $targetFile2
# Write into File
sed -i '/'"$startMarker"'/,/'"$endMarker"'/ {
//!d
/'"$startMarker"'/a\
'"$customtext"'
}' $targetFile3
# Write into File
sed -i '/'"$startMarker"'/,/'"$endMarker"'/ {
//!d
/'"$startMarker"'/a\
'"$customtext"'
}' $targetFile4
# Reload Waybar
setsid $HOME/dotfiles/waybar/launch.sh 1>/dev/null 2>&1 &
_goBack
else
echo "ERROR: Marker not found."
sleep 2
_goBack
fi
_replaceInFile $startMarker $endMarker $customtext $targetFile1
_replaceInFile $startMarker $endMarker $customtext $targetFile2
_replaceInFile $startMarker $endMarker $customtext $targetFile3
_replaceInFile $startMarker $endMarker $customtext $targetFile4
# Reload Waybar
setsid $HOME/dotfiles/waybar/launch.sh 1>/dev/null 2>&1 &
_goBack
else
echo "ERROR: Define a value."
sleep 2

View File

@ -19,25 +19,10 @@ if [ ! -z $customvalue ]; then
# Replace in Template
customtext="${customtemplate/VALUE/"$customvalue"}"
# Ensure that markers are in target file
if grep -s "$startMarker" $targetFile && grep -s "$endMarker" $targetFile; then
# Write into File
sed -i '/'"$startMarker"'/,/'"$endMarker"'/ {
//!d
/'"$startMarker"'/a\
'"$customtext"'
}' $targetFile
# Reload Waybar
setsid $HOME/dotfiles/waybar/launch.sh 1>/dev/null 2>&1 &
_goBack
else
echo "ERROR: Marker not found."
sleep 2
_goBack
fi
_replaceInFile $startMarker $endMarker $customtext $targetFile
# Reload Waybar
setsid $HOME/dotfiles/waybar/launch.sh 1>/dev/null 2>&1 &
else
echo "ERROR: Define a value."
sleep 2