feat(hyprland): add random wallpaper service
This commit is contained in:
parent
f02b3ae0ea
commit
f9fd542206
4 changed files with 70 additions and 42 deletions
|
|
@ -4,21 +4,27 @@
|
|||
with lib;
|
||||
let
|
||||
cfg = config.my.programs.wallpaper;
|
||||
|
||||
|
||||
script = pkgs.writeShellApplication {
|
||||
name = "wallpaper";
|
||||
runtimeInputs = with pkgs; [ findutils coreutils feh hyprland jq fzf viu ];
|
||||
text = builtins.readFile ./wallpaper.sh;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.my.programs.wallpaper.enable = mkEnableOption "wallpaper";
|
||||
options.my.programs.wallpaper = {
|
||||
enable = mkEnableOption "wallpaper";
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = script;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages =
|
||||
let
|
||||
wallpaper = pkgs.writeShellApplication {
|
||||
name = "wallpaper";
|
||||
runtimeInputs = with pkgs; [ findutils coreutils feh hyprland jq fzf viu ];
|
||||
text = builtins.readFile ./wallpaper.sh;
|
||||
};
|
||||
in
|
||||
[
|
||||
wallpaper
|
||||
cfg.package
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ WALLPAPERS_PATH="$HOME/.config/wallpapers"
|
|||
WALLPAPERS=$(find "$WALLPAPERS_PATH" -type f,l)
|
||||
|
||||
function help() {
|
||||
echo "Usage: wallpaper [OPTIONS]"
|
||||
echo "Usage:"
|
||||
echo -e " wallpaper [OPTIONS] [PATH]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message and exit"
|
||||
echo " -r, --random Set a random wallpaper"
|
||||
echo " -s, --set <PATH> Set a wallpaper"
|
||||
echo -e " -h, --help \n\t Show this help message and exit"
|
||||
echo -e " -r, --random \n\t Set a random wallpaper"
|
||||
echo -e " -s, --set <PATH> \n\t Set a wallpaper"
|
||||
}
|
||||
|
||||
function randomWallpaper() {
|
||||
|
|
@ -17,7 +18,7 @@ function randomWallpaper() {
|
|||
}
|
||||
|
||||
function setWallpaper() {
|
||||
case "$DESKTOP_SESSION" in
|
||||
case "${XDG_CURRENT_DESKTOP,,}" in
|
||||
hyprland)
|
||||
hyprctl hyprpaper preload "$1" &>/dev/null
|
||||
hyprctl monitors -j | jq '.[].name' | xargs -I{} -P 0 hyprctl hyprpaper wallpaper '{}',"$1" &>/dev/null
|
||||
|
|
@ -58,13 +59,25 @@ done
|
|||
|
||||
set -- "${POSITIONAL[@]}" # restore positional arguments
|
||||
|
||||
if [[ -z ${WALLPAPER+x} ]]; then
|
||||
WALLPAPER=$(echo "$WALLPAPERS" | fzf --preview="viu -sb -h 30 {}" --preview-window=right:70%:wrap)
|
||||
if [[ $# -gt 1 ]]; then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$WALLPAPER" ]]; then
|
||||
if [[ $# -eq 1 ]]; then
|
||||
WALLPAPER="$1"
|
||||
fi
|
||||
|
||||
if [[ -z ${WALLPAPER+x} ]]; then
|
||||
WALLPAPER=$(echo "$WALLPAPERS" | fzf --preview="viu -sb -h 30 {}" --preview-window=right:70%:wrap)
|
||||
fi
|
||||
|
||||
WALLPAPER=$(realpath "$WALLPAPER")
|
||||
|
||||
if [[ ! -e "$WALLPAPER" ]]; then
|
||||
echo "File not found: $WALLPAPER"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Setting wallpaper: '$WALLPAPER'"
|
||||
setWallpaper "$WALLPAPER"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue