-
Notifications
You must be signed in to change notification settings - Fork 5
/
lazywal-cli
executable file
·96 lines (86 loc) · 1.64 KB
/
lazywal-cli
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
#!/usr/bin/env sh
_help()
{
echo
echo "Usage: lazywal-cli [OPTION] [PATH_TO_VIDEO]"
echo "Options:"
echo " -h - Display this message"
echo " -r - Restore last wallpaper"
echo " -k - Kill wallpaper"
echo " -d - Debug"
echo " -D - Display with specification (e.g., 1980x1080+0)"
}
xwinwrap_func()
{
if [ "$display" = "" ];then
# https://superuser.com/questions/196532/how-do-i-find-out-my-screen-resolution-from-a-shell-script
display=$(xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
xwinwrap_args="-g $display -ni -b -st -un -o 1.0 -ov -debug"
else
xwinwrap_args="-g $display -ni -b -st -un -o 1.0 -ov -debug"
fi
}
_set_display()
{
display=$1
}
_kill()
{
pkill xwinwrap
sleep 0.05
}
_use_wal()
{
_kill
file_path=$1
xwinwrap_func
mpv_args="-wid WID --loop --no-audio --no-resume-playback --panscan=1.0"
if [ "$debug" = "true" ];
then
xwinwrap $xwinwrap_args -- mpv $mpv_args $file_path
else
xwinwrap $xwinwrap_args -- mpv $mpv_args $file_path &> /dev/null &
fi
}
_restore()
{
file_path=$(cat $HOME/.lazywal)
_use_wal $file_path
}
if [ $# -lt 1 ]
then
echo "No options found!"
_help
exit 1
fi
while getopts "hdrkD:" option; do
case $option in
h) # display Help
_help
exit;;
k) # kill wallpaper
_kill
exit;;
d) # debug
debug="true"
echo debug
continue;;
r) # restore wal
_restore
exit;;
D) # display on specification (use this for external monitors)
_set_display ${OPTARG}
continue;;
*) # Illegal option
_help
exit;;
esac
done
for i in "$@"; do
if [ -e $i ]
then
file_path=$(realpath $i)
echo $file_path > $HOME/.lazywal
_restore
fi
done