forked from sayan01/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubg
executable file
·78 lines (64 loc) · 2.4 KB
/
ubg
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
#!/bin/bash
# ubg - universal background wallpaper changer
# changes background as well as lockscreen picture to provided image
# dont use if you want different images as bg and lockscreen.
# works only with bgclock and betterlockscreen already set up
# usage: ubg image [delta]
# if you feel the accent color generated is too similar or too dissimilar to
# dominant color of image, then pass 2nd argument delta. higher delta = more difference
# default value of delta = 50
error(){
echo "$@"
exit 1
}
src="$1"
path="${HOME}/.config/wall"
if test -z "$1"; then error "usage: ubg image"; fi
if test ! -r "$src" ; then error "File $src does not exist or is unreadable"; fi
if test -d "$src" ; then error "$src is not a image file, it is a directory"; fi
if test -d "$src"; then error "$src is a directory, not an image" ; fi
if ! isimage "$src"; then error "$src is not a valid image file" ; fi
delta="$2"
if test -z "$2"; then delta=50; fi
if ! mkdir -p "$path"; then echo "unable to create directory"; exit 1; fi
cp -f "$src" "${path}/"
cd "$path" || exit 1
src="$(basename "$src")"
rm wall || exit 1
# set background to be read by bgclock
ln -s "$src" wall || exit 1
echo "background set"
# set lockscreen to be used by betterlockscreen, this takes a while
betterlockscreen -u "$src" || exit 1
echo "lockscreen set"
# get dominant color of picture
dc="$(domcol "$src")"
# get if image color is light or dark
contrast="$(lord "$dc")"
# if image is dark, make accent lighter. if image is light, make accent darker
case "$contrast" in
"light") tone=-${delta} ;;
"dark") tone=${delta} ;;
esac
# get accent color
accentcolor="$(hexcolortoner "$dc" "$tone")"
# get accentcolor contrast (light or dark)
contrast="$(lord "$accentcolor")"
# if accentcolor is light, make text black, else make text white
case "$contrast" in
"light") textcolor="#111111";;
"dark") textcolor="#eeeeee";;
esac
echo "dominantcolor= $dc"
echo "accentcolor= $accentcolor"
echo "textcolor= $textcolor"
# write the theme to .theme file in ~/.config/wall
printf "dwm.selfgcolor:\t%s\ndwm.selbordercolor:\t%s\ndwm.selbgcolor:\t%s\n" \
"$textcolor" "$accentcolor" "$accentcolor" > .theme
echo "theme written to $path"
echo -n "do you want to write these themes to xresources? [Y/n] "
read -r ch
if test "$ch" == "n"; then exit 0; fi
xrdb -merge .theme
xrdb -edit "${HOME}/.Xresources"
echo "theme applied and written to .Xresources. Restart dwm to reflect changes"