wallp (1314B)
1 #!/bin/rc 2 # usage: wallp [-s] [-n|-r] [dir] [monitors] 3 # randomly select wallpaper for each monitor and apply 4 # -S select monitors via dmenu 5 # -s select subdirectory via dmenu 6 # -n only select new wallpaper for monitors without one 7 # -r don't select new wallpapers, restore from cache 8 # usage: wallp [-l] 9 # list monitors 10 11 fn checkempty { 12 if ($1 ()) 13 exit 14 } 15 16 _dir = $home/.local/wall 17 mkdir -p $_dir 18 19 while (~ $1 -*) { 20 flags = ($flags $1) 21 shift 22 } 23 24 if (!~ $1 ()) { 25 search = $1 26 shift 27 } 28 29 if (~ $flags -s) { 30 search = `$nl{find $search -type d | dmenu -i} 31 checkempty $search 32 } 33 34 if (~ $flags -S) { 35 monitors = `$nl{xrandr --listactivemonitors | awk '$4 {print $4}' | dmenu -i} 36 checkempty $monitors 37 } else if (~ $1 ()) { 38 monitors = `$nl{xrandr --listactivemonitors | awk '$4 {print $4}'} 39 } else { 40 monitors = $* 41 } 42 43 if (~ $flags -l) { 44 exec echo $^monitors 45 } 46 47 if (~ $flags -n) { 48 for (m in $monitors) { 49 if (!test -f $_dir/$m) { 50 pop = ($pop $m) 51 } 52 } 53 } else { 54 pop = $monitors 55 } 56 57 if (!~ $flags -r) { 58 wallpapers = `$nl{find $search -type f | shuf -n $#pop} 59 for (i in `{seq $#pop}) { 60 rm -f $_dir/$pop($i) 61 ln -s `$nl{realpath $wallpapers($i)} $_dir/$pop($i) 62 } 63 } 64 65 args = () 66 for (m in $monitors) { 67 args = ($args --output $m --zoom $_dir/$m) 68 } 69 xwallpaper $args