set wallpapers from wallhaven

This commit is contained in:
Adithya 2023-05-16 00:19:04 +05:30
parent 516efdf34d
commit 9eb67b68ee
Signed by: adtya
GPG key ID: 48FC9915FFD326D0
4 changed files with 25 additions and 2 deletions

View file

@ -13,6 +13,7 @@ let
wpctl = "${pkgs.wireplumber}/bin/wpctl";
xdg-user-dir = "${pkgs.xdg-user-dirs}/bin/xdg-user-dir";
change-wallpaper = "${pkgs.scripts}/bin/chpaper \${HOME}/Pictures/Wallpapers";
wallhaven-wallpaper = "${pkgs.scripts}/bin/wallhaven";
in
{
home.packages = with pkgs; [
@ -161,6 +162,7 @@ in
bind = SUPER,d, exec, ${rofi} -show drun
bind = SUPER,escape, exec, ${swaylock} -f -i /tmp/lockpaper.jpg
bind = SUPER_SHIFT,W, exec, ${change-wallpaper}
bind = SUPER_ALT,W, exec, ${wallhaven-wallpaper}
bind = SUPER_SHIFT,escape, exec, ${pkgs.scripts}/bin/power-menu
bind = SUPER,f11, exec, ${pkgs.scripts}/bin/tmux-sessions

2
packages/scripts/chpaper.sh Executable file → Normal file
View file

@ -16,5 +16,5 @@ random_paper() {
find -L "${DIR}"/ -type f -regextype egrep -regex ".*\.(jpe?g|png)$" | shuf -n1
}
convert "$(random_paper)" /tmp/wallpaper.jpg && swaybg -i "/tmp/wallpaper.jpg" -m fill &
convert "$(random_paper)" /tmp/wallpaper.jpg && (pkill swaybg; swaybg -i "/tmp/wallpaper.jpg" -m fill &)
convert "$(random_paper)" /tmp/lockpaper.jpg

View file

@ -1,4 +1,4 @@
{ lib, stdenvNoCC, makeWrapper, libnotify, rofi-wayland, tmux, kitty, imagemagick, swaybg, sway, hyprland }:
{ lib, stdenvNoCC, makeWrapper, libnotify, rofi-wayland, tmux, kitty, imagemagick, swaybg, sway, hyprland, jq, curl }:
stdenvNoCC.mkDerivation {
pname = "scripts";
@ -21,5 +21,9 @@ stdenvNoCC.mkDerivation {
cp chpaper.sh $out/bin/chpaper
chmod +x $out/bin/chpaper
wrapProgram $out/bin/chpaper --prefix PATH : ${lib.makeBinPath [ imagemagick swaybg ]}
cp wallhaven.sh $out/bin/wallhaven
chmod +x $out/bin/wallhaven
wrapProgram $out/bin/wallhaven --prefix PATH : ${lib.makeBinPath [ imagemagick swaybg jq curl ]}
'';
}

View file

@ -0,0 +1,17 @@
#!/bin/sh
set -eu
wallpaper() {
FILENAME="/tmp/image-${RANDOM}"
URL="https://wallhaven.cc/api/v1/search?categories=100&purity=100&atleast=1920x1080&ratios=16x9&sorting=random"
ID="$(curl --silent $URL | jq -r '.data[0].id')"
IMAGE_URL="$(curl --silent "https://wallhaven.cc/api/v1/w/$ID" | jq -r '.data.path')"
curl --silent -L --output "$FILENAME" "$IMAGE_URL"
echo $FILENAME
}
convert "$(wallpaper)" "/tmp/wallpaper.jpg" && (pkill swaybg; swaybg -i "/tmp/wallpaper.jpg" -m fill &)
convert "$(wallpaper)" "/tmp/lockpaper.jpg"