feat: wallpaper-driven theming + native wallpaper picker
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ZYoSQwwYWhJHLX6VBCGnF
This commit is contained in:
1 parent
fef7cacc9e
commit
44cf203da4
22 files changed
+594
-285
No files matched your search
@@ -4,8 +4,8 @@ const image_exts = ["jpg" "jpeg" "png" "webp"]
|
||||
|
||||
def wallpaper-dirs [] {
|
||||
[
|
||||
($"($env.HOME)/Nextcloud/Wallpaper")
|
||||
($"($env.HOME)/Nextcloud/Wallpaper_32x9")
|
||||
($"($env.HOME)/ownCloud/Personal/Wallpaper")
|
||||
($"($env.HOME)/ownCloud/Personal/Wallpaper_32x9")
|
||||
] | where {|dir| $dir | path exists }
|
||||
}
|
||||
|
||||
@@ -14,39 +14,63 @@ def list-wallpapers [] {
|
||||
| each {|dir| ls $dir }
|
||||
| flatten
|
||||
| where type == file
|
||||
| where {|file| (($file.name | path parse | get extension | str downcase) in $image_exts) }
|
||||
| where {|file| (($file.name | path parse | get extension | str lowercase) in $image_exts) }
|
||||
| sort-by name
|
||||
}
|
||||
|
||||
const thumb_size = "480x640"
|
||||
|
||||
def thumbnail-dir [] {
|
||||
let dir = $"($env.HOME)/.cache/quickshell-wallpaper-thumbs"
|
||||
mkdir $dir
|
||||
$dir
|
||||
}
|
||||
|
||||
def thumbnail-path [src: string] {
|
||||
let hash = ($src | hash sha256 | str substring 0..24)
|
||||
$"(thumbnail-dir)/($hash).jpg"
|
||||
}
|
||||
|
||||
# Pre-rendered small JPEG cached in ~/.cache, so the picker never has to
|
||||
# decode a multi-megapixel wallpaper just to show a thumbnail.
|
||||
def ensure-thumbnail [src: string] {
|
||||
let thumb = (thumbnail-path $src)
|
||||
if not ($thumb | path exists) {
|
||||
try {
|
||||
magick $src -auto-orient -thumbnail $"($thumb_size)^" -gravity center -extent $thumb_size -quality 85 $thumb
|
||||
} catch {}
|
||||
}
|
||||
$thumb
|
||||
}
|
||||
|
||||
def list-wallpapers-with-thumbs [] {
|
||||
list-wallpapers | get name | par-each {|f| { path: $f, thumb: (ensure-thumbnail $f) } }
|
||||
}
|
||||
|
||||
def set-wallpaper [path: string] {
|
||||
if not ($path | path exists) {
|
||||
notify-send "Wallpaper not found" $path
|
||||
try { notify-send "Wallpaper not found" $path }
|
||||
exit 1
|
||||
}
|
||||
|
||||
awww img $path --transition-type grow --transition-duration 1
|
||||
try { awww img $path --transition-type grow --transition-duration 1 }
|
||||
$path | save -f $"($env.HOME)/.config/current-wallpaper"
|
||||
notify-send "Wallpaper applied" ($path | path basename)
|
||||
}
|
||||
|
||||
def choose-wallpaper [] {
|
||||
let files = (list-wallpapers)
|
||||
if ($files | is-empty) {
|
||||
notify-send "No wallpapers found" "~/Nextcloud/Wallpaper or ~/Nextcloud/Wallpaper_32x9"
|
||||
exit 1
|
||||
# An unhandled external-command failure aborts the rest of a nu script, so
|
||||
# this must not depend on awww/notify-send succeeding above.
|
||||
try {
|
||||
bash -lc $"nu ~/.dotfiles/config/nushell/scripts/wallpaper-theme.nu \"($path)\""
|
||||
} catch {|e|
|
||||
try { notify-send "Theme update failed" $e.msg }
|
||||
}
|
||||
|
||||
let choice = ($files | get name | path basename | str join "\n" | wofi --dmenu --prompt "Wallpaper")
|
||||
if ($choice == "") { exit }
|
||||
|
||||
let selected = ($files | where {|file| ($file.name | path basename) == $choice } | get name | first)
|
||||
set-wallpaper $selected
|
||||
try { notify-send "Wallpaper applied" ($path | path basename) }
|
||||
}
|
||||
|
||||
def random-wallpaper [] {
|
||||
let files = (list-wallpapers)
|
||||
if ($files | is-empty) {
|
||||
notify-send "No wallpapers found" "~/Nextcloud/Wallpaper or ~/Nextcloud/Wallpaper_32x9"
|
||||
notify-send "No wallpapers found" "~/ownCloud/Personal/Wallpaper or ~/ownCloud/Personal/Wallpaper_32x9"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -56,18 +80,23 @@ def random-wallpaper [] {
|
||||
|
||||
def current-wallpaper [] {
|
||||
let file = $"($env.HOME)/.config/current-wallpaper"
|
||||
if ($file | path exists) { open $file | str trim }
|
||||
if ($file | path exists) { open $file | str trim } else { "" }
|
||||
}
|
||||
|
||||
def main [
|
||||
path?: string
|
||||
--menu
|
||||
--random
|
||||
--set: string
|
||||
--current
|
||||
--list
|
||||
--list-with-current
|
||||
] {
|
||||
if $list {
|
||||
if $list_with_current {
|
||||
{
|
||||
wallpapers: (list-wallpapers-with-thumbs),
|
||||
current: (current-wallpaper)
|
||||
} | to json --raw
|
||||
} else if $list {
|
||||
list-wallpapers | get name | to json --raw
|
||||
} else if $current {
|
||||
current-wallpaper
|
||||
@@ -78,6 +107,6 @@ def main [
|
||||
} else if $path != null {
|
||||
set-wallpaper $path
|
||||
} else {
|
||||
choose-wallpaper
|
||||
notify-send "Wallpaper picker" "Use the mod+W wallpaper carousel instead"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user