This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomWallpaper.sh
executable file
·128 lines (104 loc) · 4.8 KB
/
randomWallpaper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# ██████╗██╗ ██╗██╗███╗ ██╗ ██████╗ ██╗ ██╗
# ██╔════╝██║ ██║██║████╗ ██║██╔════╝ ██║ ██║
# ██║ ███████║██║██╔██╗ ██║██║ ███╗██║ ██║
# ██║ ██╔══██║██║██║╚██╗██║██║ ██║██║ ██║
# ╚██████╗██║ ██║██║██║ ╚████║╚██████╔╝╚██████╔╝
# ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═════╝
## possible options
# - random
# - favorite
# - reapply
# - fuzzy
# - sxiv
# - fuzzyFavorite
# - favoriteSxiv
# - remove
# - file manager
# - path
scriptDirectory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$scriptDirectory/config.sh"
CYAN='\033[0;36m'
NC='\033[0m' # No color
# if no arguments passed will prompt for options in dmenu
if [[ -z "$*" ]]; then
wallpaper_name=$(readlink "$scriptDirectory/wallpaper" | xargs -i basename {})
wallpaper_path=$(readlink "$scriptDirectory/wallpaper" | xargs -i dirname {} | xargs -i basename {})
notify-send --icon=preferences-desktop-wallpaper "Wallpaper" "current: $wallpaper_name in $wallpaper_path"
option=$(echo -e "random\nfavorite\nreapply\nsxiv\nfuzzy\nfuzzyFavorite\nfavoriteSxiv\nremove\nfiles" | rofi -i -dmenu -p "randomWallpaper")
else
# else first argument is used
option=$1
fi
function setWallpaper() {
choice=$1
width=$(identify -format "%w" "$choice" 2>/tmp/randomWallpaper.errors.log)
height=$(identify -format "%h" "$choice" 2>/tmp/randomWallpaper.errors.log)
# if resolution of picture is agove 1080p, then will set wallpaper
# otherwise will call main funtion again and try with another choice
if [[ $width -ge $minWidth ]] && [[ $height -ge $minHeight ]]; then
ln -sf "$choice" "$scriptDirectory/wallpaper"
applyWallpaper
echo -e "Wallpaper is\n $choice"
echo -e "$choice" >>"$scriptDirectory/wallpaper.log"
exit 0
else
# call function again to find a new compatible picture
echo "$choice not large than wanted :("
chooseRandom
fi
}
applyWallpaper() {
wm=$(wmctrl -m | head -n 1)
if [[ $wm =~ "GNOME" ]]; then
gsettings set org.gnome.desktop.background picture-uri-dark file:"$scriptDirectory/wallpaper"
gsettings set org.gnome.desktop.background picture-uri file:"$scriptDirectory/wallpaper"
else
xwallpaper --zoom "$scriptDirectory/wallpaper"
fi
}
function chooseRandom() {
# the path of a random picture
choice=$(fd "(jpg|gif|png|jpeg)" "$wallpaperPath" -E '*samDoesArt' | shuf | head -n 1)
setWallpaper "$choice"
}
if [[ $option = "random" ]]; then
chooseRandom
# if favorite flag, then will put the file to a favorites file
elif [[ $option = "favorite" ]]; then
currentWallpaper=$(readlink "$scriptDirectory/wallpaper")
echo "Adding Wallpaper - $currentWallpaper to favorites"
notify-send "💚 ChinguRandomWallpaper" "$currentWallpaper to favorites"
echo -e "$currentWallpaper" >>"$scriptDirectory/favorites.log"
elif [[ $option = "fuzzyFavorite" ]]; then
choice=$(cat "$scriptDirectory/favorites.log" | shuf | sed "s#$wallpaperPath/##" | rofi -dmenu -p "fuzzyFavorite")
setWallpaper "$wallpaperPath/$choice"
elif [[ $option = "reapply" ]] || [[ $1 = "reapply" ]]; then
echo -e "${CYAN}reapplying wallpaper${NC}"
notify-send "💚 ChinguRandomWallpaper" "reapplying wallpaper" -t 200 -i live-wallpaper
setWallpaper
elif [[ $option = "fuzzy" ]]; then
# choice=$(cd $wallpaperPath && fd '\.jpg$|\.png' | shuf | fzf --height=100 --info=default --preview='tiv -w 92 -h 16 {}' --header='choose wallpaper here ;)')
choice=$(cd "$wallpaperPath" && fd '\.jpg$|\.png' | shuf | rofi -dmenu -p "fuzzy")
setWallpaper "$wallpaperPath/$choice"
elif [[ $option = "sxiv" ]]; then
choice=$(cd "$wallpaperPath" && fd '\.jpg$|\.png' | shuf | head -n 30 | nsxiv -to -)
setWallpaper "$wallpaperPath/$choice"
elif [[ $option = "favoriteSxiv" ]]; then
cat "$scriptDirectory/favorites.log" | nsxiv -t -
elif
[[ $option = "remove" ]]
then
to_remove=$(tail "$scriptDirectory/wallpaper.log" -n 1)
trash "$to_remove" && echo "successfully moved to trash"
notify-send "Trash status" "trashed $to_remove"
elif [[ $option = "files" ]]; then
choice=$(readlink "$scriptDirectory/wallpaper")
$fileManager "$choice"
# put path in argument and specify image as second argument
elif [[ $option = "path" ]]; then
choice=$2
setWallpaper "$wallpaperPath/$choice"
else
echo "no valid option chosen :("
fi