]> Sergey Matveev's repositories - nnn.git/blob - plugins/wallpaper
wallpaper plugin: add ability to set wallpaper for specific monitors using nitrogen
[nnn.git] / plugins / wallpaper
1 #!/usr/bin/env sh
2
3 # Description: Set the selected image as wallpaper.
4 # Uses nitrogen or pywal on X11, swww on wayland.
5 #
6 # Usage: Hover on an image and run the script to set it as wallpaper.
7 #
8 # Shell: POSIX compliant
9 # Author: juacq97
10
11 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
12 resp=
13
14 add_file ()
15 {
16     printf '%s\0' "$@" >> "$selection"
17 }
18
19 if [ -n "$1" ]; then
20     if [ "$(file --mime-type "$1" | awk '{print $NF}' | awk -F '/' '{print $1}')" = "image" ]; then
21         if [ "$XDG_SESSION_TYPE" = "x11" ]; then
22             if type nitrogen >/dev/null 2>&1; then
23                 printf "Set to full desktop or a specific monitors? [0, 1, etc. Defaults to full.]"
24                 read -r resp
25                 if [ "$resp" != "" ]; then
26                         nitrogen --set-zoom-fill --save "$1" --head="$resp"
27                 else
28                         nitrogen --set-zoom-fill --save "$1"
29                 fi
30             elif type wal >/dev/null 2>&1; then
31                 wal -i "$1"
32             else
33                 printf "nitrogen or pywal missing"
34                 read -r _
35             fi
36         else
37             if type swww >/dev/null 2>&1; then
38                 swww img "$1"
39             else
40                 printf "swww missing"
41                 read -r _
42             fi
43         fi
44
45     # If you want a system notification, uncomment the next 3 lines.
46     # notify-send -a "nnn" "Wallpaper changed!"
47     #   else
48     # notify-send -a "nnn" "No image selected"
49
50     fi
51 fi