diff --git a/.install/library.sh b/.install/library.sh index b420282..28fdb1c 100755 --- a/.install/library.sh +++ b/.install/library.sh @@ -230,3 +230,46 @@ _replaceInFile() { sleep 2 fi } + +# replaceLineInFile $findText $customtext $targetFile +_replaceLineInFile() { + # Set function parameters + find_string="$1" + new_string="$2" + file_path=$3 + + # Counters + find_line_counter=0 + line_found=0 + + if [ -f $file_path ] ;then + + # Detect Line + while read -r line + do + ((find_line_counter++)) + if [[ $line = *$find_string* ]]; then + # echo "Start found in $start_line_counter" + line_found=$find_line_counter + break + fi + done < "$file_path" + + if [[ ! "$line_found" == "0" ]] ;then + + #Remove the line + sed -i "$line_found d" $file_path + + # Add the new line + sed -i "$line_found i $new_string" $file_path + + else + echo "ERROR: Target line not found." + sleep 2 + fi + + else + echo "ERROR: Target file not found." + sleep 2 + fi +} \ No newline at end of file diff --git a/.install/restore.sh b/.install/restore.sh index dbd0524..6a3f9ea 100755 --- a/.install/restore.sh +++ b/.install/restore.sh @@ -269,5 +269,15 @@ echo -e "${NONE}" echo "nm-applet restored." fi + # Restore Keyboard natural_scroll + targetFile="$HOME/dotfiles-versions/$version/hypr/conf/keyboard.conf" + settingsFile="$HOME/dotfiles/.settings/keyboard_naturalscroll" + if [ -f $settingsFile ] ;then + findMarker="natural_scroll" + customtext="$(cat $settingsFile)" + _replaceLineInFile "$findMarker" "$customtext" "$targetFile" + echo "keyboard natural_scroll restored." + fi + echo "" fi diff --git a/CHANGELOG b/CHANGELOG index b57ad7f..03d8a56 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,8 @@ https://gitlab.com/stephan-raabe/dotfiles/-/releases/2.7.1 -------------------------------------------------------- Hyprland: - Add optional network-manager applet support. Can be activated in Settings script System/nm-applet -- Settings: Show/Hide network module +- Show/Hide network module in Settings script +- New Settings for keyboard (incl. natural_scroll for touchpads) Version 2.7 https://gitlab.com/stephan-raabe/dotfiles/-/releases/2.7 diff --git a/hypr/settings/.library/library.sh b/hypr/settings/.library/library.sh index 6429ada..1258aad 100644 --- a/hypr/settings/.library/library.sh +++ b/hypr/settings/.library/library.sh @@ -265,6 +265,49 @@ _replaceInFile() { fi } +# replaceLineInFile $findText $customtext $targetFile +_replaceLineInFile() { + # Set function parameters + find_string="$1" + new_string="$2" + file_path=$3 + + # Counters + find_line_counter=0 + line_found=0 + + if [ -f $file_path ] ;then + + # Detect Line + while read -r line + do + ((find_line_counter++)) + if [[ $line = *$find_string* ]]; then + # echo "Start found in $start_line_counter" + line_found=$find_line_counter + break + fi + done < "$file_path" + + if [[ ! "$line_found" == "0" ]] ;then + + #Remove the line + sed -i "$line_found d" $file_path + + # Add the new line + sed -i "$line_found i $new_string" $file_path + + else + echo "ERROR: Target line not found." + sleep 2 + fi + + else + echo "ERROR: Target file not found." + sleep 2 + fi +} + # _writeSettings $settingsFile $customtext _writeSettings() { if [ ! -f $1 ] ;then diff --git a/hypr/settings/modules/system/keyboard/config.sh b/hypr/settings/modules/system/keyboard/config.sh new file mode 100644 index 0000000..0ab4fdc --- /dev/null +++ b/hypr/settings/modules/system/keyboard/config.sh @@ -0,0 +1,2 @@ +name="Keyboard" +order=30 diff --git a/hypr/settings/modules/system/keyboard/module.sh b/hypr/settings/modules/system/keyboard/module.sh new file mode 100755 index 0000000..e3efe99 --- /dev/null +++ b/hypr/settings/modules/system/keyboard/module.sh @@ -0,0 +1,2 @@ +#!/bin/bash +_getHeader "$name" diff --git a/hypr/settings/modules/system/keyboard/naturalscroll/config.sh b/hypr/settings/modules/system/keyboard/naturalscroll/config.sh new file mode 100644 index 0000000..198788e --- /dev/null +++ b/hypr/settings/modules/system/keyboard/naturalscroll/config.sh @@ -0,0 +1,2 @@ +name="Natural Scrolling" +order=1 diff --git a/hypr/settings/modules/system/keyboard/naturalscroll/module.sh b/hypr/settings/modules/system/keyboard/naturalscroll/module.sh new file mode 100755 index 0000000..08b89bc --- /dev/null +++ b/hypr/settings/modules/system/keyboard/naturalscroll/module.sh @@ -0,0 +1,31 @@ +#!/bin/bash +_getHeader "$name" "$author" + +echo "Enable/Disable the natural scrolling for touchpads." + +# Define File +targetFile="$HOME/dotfiles/hypr/conf/keyboard.conf" +settingsFile="$HOME/dotfiles/.settings/keyboard_naturalscroll" + +# Define Markers +findMarker="natural_scroll" + +# Select Value +customvalue=$(gum choose "Enable" "Disable") + +if [ ! -z $customvalue ]; then + if [ "$customvalue" == "Enable" ] ;then + customtext=" natural_scroll = true" + else + customtext=" natural_scroll = false" + fi + _replaceLineInFile "$findMarker" "$customtext" "$targetFile" + _writeSettings "$settingsFile" "$customtext" + echo "Keyboard settings changed." + sleep 2 + _goBack +else + echo "ERROR: Define a value." + sleep 2 + _goBack +fi