From f6ad27e30fd16126b60a149469725a3567b9e2ef Mon Sep 17 00:00:00 2001 From: Stephan Raabe Date: Tue, 19 Dec 2023 16:48:01 +0100 Subject: [PATCH] Update Replacement Function --- README.md | 2 +- hypr/settings/.library/library.sh | 15 ++++++ .../modules/waybar/appslabel/module.sh | 25 ++-------- .../modules/waybar/bluetooth/module.sh | 50 ++++--------------- hypr/settings/modules/waybar/date/module.sh | 23 ++------- 5 files changed, 34 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 90d5495..c871538 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/hypr/settings/.library/library.sh b/hypr/settings/.library/library.sh index 2a0e7db..8a8d727 100644 --- a/hypr/settings/.library/library.sh +++ b/hypr/settings/.library/library.sh @@ -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 diff --git a/hypr/settings/modules/waybar/appslabel/module.sh b/hypr/settings/modules/waybar/appslabel/module.sh index 322b48b..554a8d2 100755 --- a/hypr/settings/modules/waybar/appslabel/module.sh +++ b/hypr/settings/modules/waybar/appslabel/module.sh @@ -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 diff --git a/hypr/settings/modules/waybar/bluetooth/module.sh b/hypr/settings/modules/waybar/bluetooth/module.sh index 2b6f5df..88246b7 100755 --- a/hypr/settings/modules/waybar/bluetooth/module.sh +++ b/hypr/settings/modules/waybar/bluetooth/module.sh @@ -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 diff --git a/hypr/settings/modules/waybar/date/module.sh b/hypr/settings/modules/waybar/date/module.sh index 509f735..4c0be33 100755 --- a/hypr/settings/modules/waybar/date/module.sh +++ b/hypr/settings/modules/waybar/date/module.sh @@ -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