2022-02-25 22:10:38 +03:00
|
|
|
#!/usr/bin/env engine-q
|
2021-01-23 15:10:28 +03:00
|
|
|
#
|
|
|
|
# ~/.fehbg.nu
|
|
|
|
#
|
|
|
|
# This script selects a random image from a directory and sets it as a
|
|
|
|
# wallpaper. An additional feature is that it draws the path of the image in
|
|
|
|
# the lower left corner which makes it easier to find the image later.
|
|
|
|
#
|
|
|
|
# The procedure is as follows::
|
|
|
|
# * Select a random image from a directory (recursively entering all
|
|
|
|
# subdirectories)
|
2022-02-25 22:10:38 +03:00
|
|
|
# * Print the path of the image on top of the selected image
|
2021-01-23 15:10:28 +03:00
|
|
|
# * Save the result in a temporary file
|
|
|
|
# * Set the temporary image as a wallpaper.
|
|
|
|
#
|
|
|
|
# !! Requires `WALLPAPER_DIR` and `TMP_DIR` environment variables to be set !!
|
|
|
|
# (or just hardcode your own paths below)
|
|
|
|
#
|
2021-01-23 15:21:12 +03:00
|
|
|
# You can set this script to run on desktop startup, e.g., by adding it to
|
|
|
|
# xinitrc.
|
|
|
|
#
|
2021-01-23 15:10:28 +03:00
|
|
|
# Dependencies;
|
2022-02-25 22:10:38 +03:00
|
|
|
# * new Nushell engine (https://github.com/nushell/engine-q)
|
2021-01-23 15:10:28 +03:00
|
|
|
# * feh
|
|
|
|
# * imagemagick
|
|
|
|
|
|
|
|
# Path definitions
|
2022-08-05 10:47:18 +03:00
|
|
|
let img_dir = $env.WALLPAPER_DIR
|
|
|
|
let tmp_image = ([ $env.TMP_DIR "wallpaper.jpg" ] | path join)
|
2021-01-23 15:10:28 +03:00
|
|
|
|
|
|
|
# Monitor resolution
|
2022-08-05 10:47:18 +03:00
|
|
|
let resolution_y = 1440
|
|
|
|
let res_str = ($"x($resolution-y)")
|
2021-01-23 15:10:28 +03:00
|
|
|
|
|
|
|
# Position of the caption
|
2022-08-05 10:47:18 +03:00
|
|
|
let pos_x = 5
|
|
|
|
let pos_y = (0.995 * $resolution_y | into int)
|
2021-01-23 15:10:28 +03:00
|
|
|
|
2022-02-25 22:10:38 +03:00
|
|
|
# Select random item from input
|
|
|
|
def select-random [] {
|
|
|
|
shuffle | first
|
|
|
|
}
|
2021-01-23 15:10:28 +03:00
|
|
|
|
|
|
|
# List all images in a directory and all its subdirectories
|
2022-02-25 22:10:38 +03:00
|
|
|
def list-images [dir: path] {
|
|
|
|
ls $"($dir)/**/*" |
|
|
|
|
where type == file |
|
|
|
|
str downcase name |
|
|
|
|
where name =~ jpg || name =~ jpeg || name =~ tif || name =~ tiff || name =~ png
|
2021-01-23 15:10:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Set the caption text (just filename for now)
|
2022-08-05 10:47:18 +03:00
|
|
|
def caption [img_f: string] {
|
|
|
|
echo $img_f
|
2021-01-23 15:10:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build the argument for the '-draw' command of the 'convert' utility
|
2022-08-05 10:47:18 +03:00
|
|
|
def draw-str [img_f: string] {
|
|
|
|
$"text ($pos_x), ($pos_y) (char dq)(caption $img_f)(char dq) "
|
2021-01-23 15:10:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Select random image
|
2022-08-05 10:47:18 +03:00
|
|
|
let img_name = (list-images $img_dir | select-random | get name) # TODO: change the env var to $img-dir
|
2021-01-23 15:10:28 +03:00
|
|
|
|
|
|
|
# Resize the image to the monitor height, draw the caption and save it
|
2022-08-05 10:47:18 +03:00
|
|
|
convert -resize $res_str -pointsize 15 -fill 'rgb(255,200,150)' -draw (draw-str $img_name) $img_name $tmp_image
|
2021-01-23 15:10:28 +03:00
|
|
|
|
|
|
|
# Set the created image as a background
|
2022-02-25 22:10:38 +03:00
|
|
|
feh --no-fehbg --bg-max $tmp-image
|