From 8404644c6e0e81e3c25e8ea6ede02d27273c2bcb Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Sat, 21 Sep 2024 13:52:03 +0900 Subject: added functionality on copy.sh to check if neovim or vim is installed and offer either as default editor :) --- copy.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/copy.sh b/copy.sh index b3dfd524..6f0bd3ac 100755 --- a/copy.sh +++ b/copy.sh @@ -104,7 +104,7 @@ layout=$(detect_layout) if [ "$layout" = "(unset)" ]; then while true; do printf "\n%.0s" {1..1} -print_color $ORANGE " + print_color $ORANGE " █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█ STOP AND READ █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█ @@ -131,7 +131,7 @@ NOTE: layout="$new_layout" break else - echo "Please enter a keyboard layout." + echo "${CAT} Please enter a keyboard layout." fi done fi @@ -140,19 +140,20 @@ printf "${NOTE} Detecting keyboard layout to prepare proper Hyprland Settings\n\ # Prompt the user to confirm whether the detected layout is correct while true; do - read -p "$ORANGE Current keyboard layout is: $layout ${CAT} Is this correct? [y/n] " confirm + printf "${NOTE} Current keyboard layout is ${ORANGE}$layout${RESET}\n" + read -p "${CAT} Is this correct? [y/n] " keyboard_layout - case $confirm in + case $keyboard_layout in [yY]) # If the detected layout is correct, update the 'kb_layout =' line in the file awk -v layout="$layout" '/kb_layout/ {$0 = " kb_layout = " layout} 1' config/hypr/UserConfigs/UserSettings.conf > temp.conf mv temp.conf config/hypr/UserConfigs/UserSettings.conf - echo "${NOTE} kb_layout $layout configured in settings. " 2>&1 | tee -a "$LOG" + echo "${NOTE} kb_layout ${ORANGE}$layout${RESET} configured in settings." 2>&1 | tee -a "$LOG" break ;; [nN]) printf "\n%.0s" {1..2} -print_color $ORANGE " + print_color $ORANGE " █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█ STOP AND READ █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█ @@ -172,17 +173,17 @@ NOTE: • You can also set more than 2 keyboard layouts • For example us, kr, gb, ru " - printf "\n%.0s" {1..1} - - read -p "${CAT} - Please enter the correct keyboard layout: " new_layout - - # Update the 'kb_layout =' line with the correct layout in the file - awk -v new_layout="$new_layout" '/kb_layout/ {$0 = " kb_layout = " new_layout} 1' config/hypr/UserConfigs/UserSettings.conf > temp.conf - mv temp.conf config/hypr/UserConfigs/UserSettings.conf - echo "${NOTE} kb_layout $new_layout configured in settings." 2>&1 | tee -a "$LOG" - break ;; + printf "\n%.0s" {1..1} + + read -p "${CAT} - Please enter the correct keyboard layout: " new_layout + + # Update the 'kb_layout =' line with the correct layout in the file + awk -v new_layout="$new_layout" '/kb_layout/ {$0 = " kb_layout = " new_layout} 1' config/hypr/UserConfigs/UserSettings.conf > temp.conf + mv temp.conf config/hypr/UserConfigs/UserSettings.conf + echo "${NOTE} kb_layout $new_layout configured in settings." 2>&1 | tee -a "$LOG" + break ;; *) - echo "${ERROR} Please enter either 'y' or 'n'." ;; + echo "${ERROR} Please enter either 'y' or 'n'." ;; esac done @@ -195,6 +196,36 @@ fi printf "\n" +# Checking if neovim or vim is installed and offer user if they want to make as default editor +# Function to modify the ENVariables.conf file +update_editor() { + local editor=$1 + sed -i "s/#env = EDITOR,.*/env = EDITOR,$editor #default editor/" config/hypr/UserConfigs/ENVariables.conf + echo "${OK} Default editor set to $editor." 2>&1 | tee -a "$LOG" +} + +# Check for neovim if installed +if command -v nvim &> /dev/null; then + printf "${NOTE} neovim is detected as installed\n" + read -p "${CAT} Do you want to make neovim the default editor? (y/n): " EDITOR_CHOICE + if [[ "$EDITOR_CHOICE" == "y" ]]; then + update_editor "nvim" + fi +fi + +# Check for vim if installed +if command -v vim &> /dev/null; then + printf "${NOTE} vim is detected as installed\n" + read -p "${CAT} Do you want to make vim the default editor? (y/n): " EDITOR_CHOICE + if [[ "$EDITOR_CHOICE" == "y" ]]; then + update_editor "vim" + fi +else + echo "${ORANGE} Neither neovim nor vim is installed." +fi + +printf "\n" + # Action to do for better rofi and kitty appearance while true; do echo "$ORANGE Select monitor resolution for better config appearance and fonts:" -- cgit v1.2.3 From 1f8343e132d8f71650f31c8ba131643442c8ac88 Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Sat, 21 Sep 2024 13:59:50 +0900 Subject: minor tweak for updating default editor function --- copy.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/copy.sh b/copy.sh index 6f0bd3ac..3d6993a7 100755 --- a/copy.sh +++ b/copy.sh @@ -201,22 +201,23 @@ printf "\n" update_editor() { local editor=$1 sed -i "s/#env = EDITOR,.*/env = EDITOR,$editor #default editor/" config/hypr/UserConfigs/ENVariables.conf - echo "${OK} Default editor set to $editor." 2>&1 | tee -a "$LOG" + echo "${OK} Default editor set to ${ORANGE}$editor${RESET}." 2>&1 | tee -a "$LOG" } # Check for neovim if installed if command -v nvim &> /dev/null; then - printf "${NOTE} neovim is detected as installed\n" - read -p "${CAT} Do you want to make neovim the default editor? (y/n): " EDITOR_CHOICE + printf "${NOTE} ${ORANGE}neovim${RESET} is detected as installed\n" + read -p "${CAT} Do you want to make ${ORANGE}neovim${RESET} the default editor? (y/n): " EDITOR_CHOICE if [[ "$EDITOR_CHOICE" == "y" ]]; then update_editor "nvim" + exit 0 fi fi # Check for vim if installed if command -v vim &> /dev/null; then - printf "${NOTE} vim is detected as installed\n" - read -p "${CAT} Do you want to make vim the default editor? (y/n): " EDITOR_CHOICE + printf "${NOTE} ${ORANGE}vim${RESET} is detected as installed\n" + read -p "${CAT} Do you want to make ${ORANGE}vim${RESET} the default editor? (y/n): " EDITOR_CHOICE if [[ "$EDITOR_CHOICE" == "y" ]]; then update_editor "vim" fi -- cgit v1.2.3