mirror of
https://git.adityakumar.xyz/betterlockscreen-openrc.git
synced 2024-12-28 03:02:52 +00:00
added recursive function for getting a random file
This commit is contained in:
parent
20ab92c2bb
commit
1c59e59309
1 changed files with 14 additions and 6 deletions
20
lock.sh
20
lock.sh
|
@ -57,6 +57,17 @@ postlock() {
|
||||||
pkill -u "$USER" -USR2 dunst
|
pkill -u "$USER" -USR2 dunst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rec_get_random() {
|
||||||
|
dir="$1"
|
||||||
|
if [ ! -d "$dir" ]; then
|
||||||
|
user_input="$dir"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
dir=($dir/*)
|
||||||
|
dir=${dir[RANDOM % ${#dir[@]}]}
|
||||||
|
rec_get_random "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -98,6 +109,7 @@ case "$1" in
|
||||||
echo " -u --update"
|
echo " -u --update"
|
||||||
echo " to update image cache, you should do this before using any other options"
|
echo " to update image cache, you should do this before using any other options"
|
||||||
echo " Ex: ./lock.sh -u path/to/image.png when image.png is custom background"
|
echo " Ex: ./lock.sh -u path/to/image.png when image.png is custom background"
|
||||||
|
echo " Or you can use ./lock.sh -u path/to/imagedir and a random file will be selected"
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
echo " -l --lock"
|
echo " -l --lock"
|
||||||
|
@ -198,12 +210,8 @@ case "$1" in
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get random file in dir if passed argument is a dir
|
# get random file in dir if passed argument is a dir
|
||||||
user_input=$2
|
rec_get_random "$2"
|
||||||
if [ -d $user_input ]; then
|
|
||||||
user_input=($user_input/*)
|
|
||||||
user_input=${user_input[RANDOM % ${#user_input[@]}]}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# get user image
|
# get user image
|
||||||
cp "$user_input" "$user_image"
|
cp "$user_input" "$user_image"
|
||||||
if [ ! -f $user_image ]; then
|
if [ ! -f $user_image ]; then
|
||||||
|
|
Loading…
Reference in a new issue