Skip to content

Commit f3a1993

Browse files
authored
Merge pull request #1 from kubouch/fehbg
Add script for setting random wallpaper
2 parents 4931534 + 2862585 commit f3a1993

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# Nushell Scripts
22

33
This is a place to share Nushell scripts with each other. If you'd like to share your scripts, create a PR that adds it to the repo.
4+
5+
## Included Scripts
6+
7+
| File | Nu version | Description |
8+
| ---- | ---------- | ---------- |
9+
| [fehbg.nu](../blob/main/fehbg.nu) | >0.25.1 | Sets a random image from a directory as a wallpaper (Linux only) |

fehbg.nu

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env nu
2+
#
3+
# ~/.fehbg.nu
4+
#
5+
# This script selects a random image from a directory and sets it as a
6+
# wallpaper. An additional feature is that it draws the path of the image in
7+
# the lower left corner which makes it easier to find the image later.
8+
#
9+
# The procedure is as follows::
10+
# * Select a random image from a directory (recursively entering all
11+
# subdirectories)
12+
# * Print the path of the image as an overlay on top of the selected image
13+
# * Save the result in a temporary file
14+
# * Set the temporary image as a wallpaper.
15+
#
16+
# !! Requires `WALLPAPER_DIR` and `TMP_DIR` environment variables to be set !!
17+
# (or just hardcode your own paths below)
18+
#
19+
# You can set this script to run on desktop startup, e.g., by adding it to
20+
# xinitrc.
21+
#
22+
# Dependencies;
23+
# * nu version >0.25.1 (0.25.1 doesn't work due to coercion error bug)
24+
# * feh
25+
# * imagemagick
26+
27+
# Path definitions
28+
let img_dir = $nu.env.WALLPAPER_DIR
29+
let tmp_image = $(build-string $nu.env.TMP_DIR "/wallpaper.jpg")
30+
31+
# Monitor resolution
32+
let resolution_y = 1440
33+
34+
# Position of the caption
35+
let pos_x = 5
36+
let pos_y = 0.995 * $resolution_y
37+
38+
# Helper commands
39+
def select_random [] { shuffle | first }
40+
41+
# List all images in a directory and all its subdirectories
42+
def list_images [dir] {
43+
ls $(build-string $dir /**/*) | where type == File | where name =~ jpg || name =~ jpeg || name =~ tif || name =~ tiff
44+
}
45+
46+
# Set the caption text (just filename for now)
47+
def caption [img_f] {
48+
echo $img_f
49+
}
50+
51+
# Build the argument for the '-draw' command of the 'convert' utility
52+
def draw_str [img_f] {
53+
build-string 'text ' $pos_x ',' $pos_y ' "' $(caption $img_f) '" '
54+
}
55+
56+
# Select random image
57+
let img_name = $(list_images $img_dir | select_random | get name)
58+
59+
# Resize the image to the monitor height, draw the caption and save it
60+
let res_str = $(build-string 'x' $resolution_y)
61+
convert -resize $res_str -pointsize 15 -fill "rgb(255,200,150)" -draw $(draw_str $img_name) $img_name $tmp_image
62+
63+
# Set the created image as a background
64+
feh --no-fehbg --bg-max $tmp_image

0 commit comments

Comments
 (0)