summaryrefslogtreecommitdiff
path: root/ar/.local/bin/setlock
blob: 611ae5edc9ac5f1bc5613de1c85ff294d0b92922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

lockloc="${XDG_DATA_HOME:-${HOME}/.local/share}/wallpapers/lock"

# Give -s as parameter to make notifications silent.
while getopts "s" o; do
  case "${o}" in
  s) silent='1' ;;
  *) ;;
  esac
done

shift $((OPTIND - 1))

trueloc="$(readlink -f "$1")" &&
  case "$(file --mime-type -b "$trueloc")" in
  image/*) ln -sf "$trueloc" "$lockloc" && [ -z "$silent" ] && notify-send -i "$lockloc" "Changing lock screen..." ;;
  inode/directory) ln -sf "$(find -L "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$lockloc" && [ -z "$silent" ] && notify-send -i "$lockloc" "Random Lock Screen chosen." ;;
  *)
    [ -z "$silent" ] && notify-send "🖼️ Error" "Not a valid image or directory."
    exit 1
    ;;
  esac