From 6e861bc3b7596fac769a5bf3b3506770cbc0338c Mon Sep 17 00:00:00 2001 From: omagdy Date: Tue, 22 Jul 2025 21:40:14 +0300 Subject: scripts: Edited some scripts to check for escape to close selector menu --- scripts/.scripts/create_tmp.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'scripts/.scripts/create_tmp.sh') diff --git a/scripts/.scripts/create_tmp.sh b/scripts/.scripts/create_tmp.sh index 097940d..33ec935 100755 --- a/scripts/.scripts/create_tmp.sh +++ b/scripts/.scripts/create_tmp.sh @@ -1,22 +1,30 @@ #!/bin/sh choice="py" + +# Define list of extensions +extensions="cpp\nc\npy\nrs\njs\nts\ngo\ntxt\nmd\nhtml\ncss" + # Detect whether we're in a Wayland or X11 session if [ "$XDG_SESSION_TYPE" = "wayland" ]; then - # Wayland session - use wofi - launcher="wofi --dmenu -i -l 10" - choice=$(echo -e "cpp\nc\npy\nrs\njs\nts\ngo\ntxt\nmd\nhtml\ncss" | wofi --dmenu -p "Select extension: " -l 10) + # Wayland session - use rofi with width override + launcher=(rofi -dmenu -p "Select extension: " -l 10 -theme-str "window { width: 45%; }") elif [ "$XDG_SESSION_TYPE" = "x11" ]; then # X11 session - use dmenu - # Choose an extenstion for the temp file - choice=$(echo -e "cpp\nc\npy\nrs\njs\nts\ngo\ntxt\nmd\nhtml\ncss" | dmenu -p "Select extension: " -l 10) + launcher=(dmenu -p "Select extension: " -l 10) else echo "Error: Could not detect display server (Wayland or X11)." exit 1 fi +# Run the launcher and get the user's choice +choice=$(echo -e "$extensions" | "${launcher[@]}") + +# Exit silently if Escape was pressed or menu was closed +[ -z "$choice" ] && exit 0 + # choose random word from a dictionary -random_word=$(cat /usr/share/dict/cracklib-small | shuf -n 1) +random_word=$(shuf -n 1 /usr/share/dict/cracklib-small) # create temp file and open it in nvim -alacritty -e nvim /tmp/$random_word.$choice +alacritty -e nvim "/tmp/$random_word.$choice" -- cgit v1.2.3