Browse Source

code clean up, no action if no wallpaper selected

pull/18/head
JaKooLit 2 years ago
parent
commit
b3a7ac2b3f
  1. 59
      config/hypr/scripts/WallpaperSelect.sh
  2. 20
      config/hypr/scripts/WaybarStyles.sh

59
config/hypr/scripts/WallpaperSelect.sh

@ -1,35 +1,30 @@
#!/bin/bash #!/bin/bash
# WALLPAPERS PATH # WALLPAPERS PATH
DIR=$HOME/Pictures/wallpapers DIR=$HOME/Pictures/wallpapers
# Transition config
# Transition config (type swww img --help for more settings
FPS=30 FPS=30
TYPE="simple" TYPE="simple"
DURATION=3 DURATION=3
SWWW_PARAMS="--transition-fps $FPS --transition-type $TYPE --transition-duration $DURATION" SWWW_PARAMS="--transition-fps $FPS --transition-type $TYPE --transition-duration $DURATION"
PICS=($(ls ${DIR} | grep -e ".jpg$" -e ".jpeg$" -e ".png$" -e ".gif$")) # Check if swaybg is running
#PICS=($(find ${DIR} -type f \( -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" \))) if pidof swaybg > /dev/null; then
RANDOM_PIC=${PICS[ $RANDOM % ${#PICS[@]} ]}
RANDOM_PIC_NAME="${#PICS[@]}. random"
# to check if swaybg is running
if [[ $(pidof swaybg) ]]; then
pkill swaybg pkill swaybg
fi fi
## Rofi Command # Retrieve image files
PICS=($(ls "${DIR}" | grep -E ".jpg$|.jpeg$|.png$|.gif$"))
RANDOM_PIC="${PICS[$((RANDOM % ${#PICS[@]}))]}"
RANDOM_PIC_NAME="${#PICS[@]}. random"
# Rofi command
rofi_command="rofi -dmenu -config ~/.config/rofi/config-short.rasi" rofi_command="rofi -dmenu -config ~/.config/rofi/config-short.rasi"
menu() { menu() {
# Here we are looping in the PICS array that is composed of all images in the $DIR folder for i in "${!PICS[@]}"; do
for i in ${!PICS[@]}; do # Displaying .gif to indicate animated images
# keeping the .gif to make sue you know it is animated if [[ -z $(echo "${PICS[$i]}" | grep .gif$) ]]; then
if [[ -z $(echo ${PICS[$i]} | grep .gif$) ]]; then printf "$i. $(echo "${PICS[$i]}" | cut -d. -f1)\n"
printf "$i. $(echo ${PICS[$i]} | cut -d. -f1)\n" # n°. <name_of_file_without_identifier>
else else
printf "$i. ${PICS[$i]}\n" printf "$i. ${PICS[$i]}\n"
fi fi
@ -43,32 +38,28 @@ swww query || swww init
main() { main() {
choice=$(menu | ${rofi_command}) choice=$(menu | ${rofi_command})
# no choice case # No choice case
if [[ -z $choice ]]; then return; fi if [[ -z $choice ]]; then
exit 0
fi
# random choice case # Random choice case
if [ "$choice" = "$RANDOM_PIC_NAME" ]; then if [ "$choice" = "$RANDOM_PIC_NAME" ]; then
swww img ${DIR}/${RANDOM_PIC} $SWWW_PARAMS swww img "${DIR}/${RANDOM_PIC}" $SWWW_PARAMS
return exit 0
fi fi
pic_index=$(echo $choice | cut -d. -f1) pic_index=$(echo "$choice" | cut -d. -f1)
swww img ${DIR}/${PICS[$pic_index]} $SWWW_PARAMS swww img "${DIR}/${PICS[$pic_index]}" $SWWW_PARAMS
} }
# Check if rofi is already running # Check if rofi is already running
if pidof rofi > /dev/null; then if pidof rofi > /dev/null; then
pkill rofi pkill rofi
exit 0 exit 0
else
main
fi fi
exec $HOME/.config/hypr/scripts/PywalSwww.sh & main
exec $HOME/.config/hypr/scripts/Refresh.sh
# Uncomment to launch something if a choice was made $HOME/.config/hypr/scripts/PywalSwww.sh &
# if [[ -n "$choice" ]]; then $HOME/.config/hypr/scripts/Refresh.sh
# Restart Waybar
# fi

20
config/hypr/scripts/WaybarStyles.sh

@ -20,11 +20,17 @@ STYLES=(
# Build ROFI # Build ROFI
SELECTED_STYLE=$(printf "%s\n" "${STYLES[@]}" | rofi -dmenu -config ~/.config/rofi/config-waybar.rasi "${#STYLES[@]}") SELECTED_STYLE=$(printf "%s\n" "${STYLES[@]}" | rofi -dmenu -config ~/.config/rofi/config-waybar.rasi "${#STYLES[@]}")
# Here you verify the selected theme # Check if rofi is already running
if pidof rofi > /dev/null; then
pkill rofi
exit 0
fi
# Verify the selected theme
if [[ " ${STYLES[@]} " =~ " $SELECTED_STYLE " ]]; then if [[ " ${STYLES[@]} " =~ " $SELECTED_STYLE " ]]; then
SWITCHTO="${SELECTED_STYLE}" SWITCHTO="${SELECTED_STYLE}"
else else
echo "It is not valid =c" echo "Invalid selection"
exit 1 exit 1
fi fi
@ -32,17 +38,15 @@ fi
THEMEFILE="$HOME/.config/waybar/style/style-${SWITCHTO}.css" THEMEFILE="$HOME/.config/waybar/style/style-${SWITCHTO}.css"
if [ -f "$THEMEFILE" ]; then if [ -f "$THEMEFILE" ]; then
ln -sf "$THEMEFILE" "$HOME/.config/waybar/style.css" ln -sf "$THEMEFILE" "$HOME/.config/waybar/style.css"
else else
echo "Error: $THEMEFILE not found" echo "Error: $THEMEFILE not found"
exit 1 exit 1
fi fi
_ps=(waybar mako dunst) # Restart relevant processes
for _prs in "${_ps[@]}"; do for process in waybar mako dunst; do
if [[ $(pidof ${_prs}) ]]; then if pidof "$process" > /dev/null; then
pkill ${_prs} pkill "$process"
fi fi
done done

Loading…
Cancel
Save