diff options
| author | omagdy <omar.professional8777@gmail.com> | 2025-07-22 21:40:14 +0300 |
|---|---|---|
| committer | omagdy <omar.professional8777@gmail.com> | 2025-07-22 21:40:14 +0300 |
| commit | 6e861bc3b7596fac769a5bf3b3506770cbc0338c (patch) | |
| tree | aee42c480ea54055075d203dd6e98f50fba9bc82 /scripts | |
| parent | 14d2af5be5d3c7c7d04345399feed63480a0d1cf (diff) | |
| download | dotfiles-6e861bc3b7596fac769a5bf3b3506770cbc0338c.tar.xz dotfiles-6e861bc3b7596fac769a5bf3b3506770cbc0338c.zip | |
scripts: Edited some scripts to check for escape to close selector menu
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/.scripts/books.sh | 16 | ||||
| -rwxr-xr-x | scripts/.scripts/config_files.sh | 18 | ||||
| -rwxr-xr-x | scripts/.scripts/create_tmp.sh | 22 |
3 files changed, 34 insertions, 22 deletions
diff --git a/scripts/.scripts/books.sh b/scripts/.scripts/books.sh index 71232e0..5f43410 100755 --- a/scripts/.scripts/books.sh +++ b/scripts/.scripts/books.sh @@ -12,22 +12,22 @@ path="/mnt/Storage/omar/Books/" if [ "$XDG_SESSION_TYPE" = "wayland" ]; then - launcher="rofi -dmenu -i -l 10" + launcher=(rofi -dmenu -i -l 10 -p "Book name" -theme-str "window { width: 45%; }") elif [ "$XDG_SESSION_TYPE" = "x11" ]; then - launcher="dmenu -i -l 10" + launcher=(dmenu -i -l 10) else echo "Error: Could not detect display server (Wayland or X11)." exit 1 fi -# Direct approach - no temp file, just pipe everything -choice=$(fd -e pdf . "$path" -x basename | sort | $launcher) +# Pipe filenames to launcher and capture choice +choice=$(fd -e pdf . "$path" -x basename | sort | "${launcher[@]}") -if [ -z "$choice" ]; then - exit 0 -fi +# Exit silently if nothing selected +[ -z "$choice" ] && exit 0 -# Find the file again (less efficient but simpler) +# Find the full path of the selected file full_path=$(fd -e pdf . "$path" | grep "/$choice$" | head -1) +# Open in zathura fullscreen zathura --mode fullscreen "$full_path" diff --git a/scripts/.scripts/config_files.sh b/scripts/.scripts/config_files.sh index 5051304..05bed33 100755 --- a/scripts/.scripts/config_files.sh +++ b/scripts/.scripts/config_files.sh @@ -1,6 +1,7 @@ #!/usr/bin/sh -configs=("aliases:$HOME/dotfiles/aliases/.aliases/aliases" +configs=( + "aliases:$HOME/dotfiles/aliases/.aliases/aliases" "alacritty:$HOME/dotfiles/alacritty/.config/alacritty/alacritty.toml" "awesome:$HOME/dotfiles/awesome/.config/awesome/rc.lua" "kitty:$HOME/dotfiles/kitty/.config/kitty/kitty.conf" @@ -19,11 +20,11 @@ configs=$(printf '%s\n' "${configs[@]}") # 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" + # Wayland session - use rofi with theme override + launcher=(rofi -dmenu -l 10 -theme-str "window { width: 45%; }") elif [ "$XDG_SESSION_TYPE" = "x11" ]; then # X11 session - use dmenu - launcher="dmenu -i -l 10 -p 'open config file'" + launcher=(dmenu -i -l 10 -p 'open config file') else echo "Error: Could not detect display server (Wayland or X11)." exit 1 @@ -31,9 +32,12 @@ fi program_names=$(echo "$configs" | cut -d':' -f1) -choice=$(echo "$program_names" | $launcher) +choice=$(echo "$program_names" | "${launcher[@]}") + +# Exit silently if Escape was pressed or menu was closed +[ -z "$choice" ] && exit 0 file=$(echo "$configs" | grep -w "$choice" | cut -d':' -f2) -cwd=$(dirname $file) -kitty -e nvim -c "cd $cwd" $file +cwd=$(dirname "$file") +kitty -e nvim -c "cd $cwd" "$file" 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" |
