diff --git a/home/alice.nix b/home/alice.nix index bdea14d..e91af17 100644 --- a/home/alice.nix +++ b/home/alice.nix @@ -35,6 +35,7 @@ in fzf fastfetch bun + oils-for-unix sheldon zsh-abbr lazygit diff --git a/script/cycle_wallpaper.ysh b/script/cycle_wallpaper.ysh new file mode 100755 index 0000000..83e15cb --- /dev/null +++ b/script/cycle_wallpaper.ysh @@ -0,0 +1,126 @@ +#!/usr/bin/env ysh + +forward_mode=0 +reverse_mode=1 +current_paper_path="$HOME/dotfiles/.config/hypr/env/CURRENT_PAPER" +wallpaper_dir="$HOME/Pictures/wallpapers/" +wallvideo_path="$HOME/Pictures/wallvideo/ok_geek_eyes_24.mp4" +mpvpaper_args="--hwdec=auto-safe --vo=gpu" + +get_all() { + find "$1" -maxdepth 1 -type f | sort +} + +get_first_path() { + get_all "$1" | head -n 1 +} + +get_next_path() { + local current_path="$1" + local listed_paths="$2" + local rev_mode="$3" + local matched + + if (( rev_mode == forward_mode )); then + matched="$(printf '%s\n' "$listed_paths" | grep -Fx "$current_path" -A 1)" + else + matched="$(printf '%s\n' "$listed_paths" | grep -Fx "$current_path" -B 1)" + fi + + local matched_lines + matched_lines="$(printf '%s\n' "$matched" | wc -l | tr -d ' ')" + + if (( matched_lines != 2 )); then + if (( rev_mode == forward_mode )); then + printf '%s\n' "$listed_paths" | head -n 1 + else + printf '%s\n' "$listed_paths" | tail -n 1 + fi + else + if (( rev_mode == forward_mode )); then + printf '%s\n' "$matched" | tail -n 1 + else + printf '%s\n' "$matched" | head -n 1 + fi + fi +} + +seq_or_rev() { + local rev_mode="$1" + local wallpaper_dir="$2" + local next + + if [[ -s "$current_paper_path" ]]; then + local current_paper + current_paper="$(cat "$current_paper_path")" + if [[ -f "$current_paper" ]]; then + local list + list="$(get_all "$wallpaper_dir")" + next="$(get_next_path "$current_paper" "$list" "$rev_mode")" + else + next="$(get_first_path "$wallpaper_dir")" + fi + else + next="$(get_first_path "$wallpaper_dir")" + fi + + printf '%s\n' "$next" >"$current_paper_path" + printf '%s\n' "$next" +} + +random_paper() { + local wallpaper_dir="$1" + local randomed_path + + randomed_path="$(find "$wallpaper_dir" -type f | shuf -n 1)" + printf '%s\n' "$randomed_path" >"$current_paper_path" + printf '%s\n' "$randomed_path" +} + +toggle_systemtimer() { + if systemctl --user is-active --quiet cycle_wallpaper.timer; then + if systemctl --user stop cycle_wallpaper.timer; then + notify-send "Stop slideshow" + else + notify-send "Failed stop slideshow" + fi + else + if systemctl --user start cycle_wallpaper.timer; then + notify-send "Start slideshow" + else + notify-send "Failed start slideshow" + fi + fi +} + +toggle_video() { + local v_pid + v_pid="$(pgrep mpvpaper || true)" + + if [[ -n "$v_pid" ]]; then + if pkill mpvpaper; then + notify-send "Stop wallvideo" + else + notify-send "Failed stop wallvideo" + fi + else + if mpvpaper '*' "$wallvideo_path" -o "no-audio loop" --fork --mpv-args="$mpvpaper_args"; then + notify-send "Start wallvideo" + else + notify-send "Failed start wallvideo" + fi + fi +} + +case "${1:-}" in + seq) wall_path="$(seq_or_rev "$forward_mode" "$wallpaper_dir")" ;; + rev) wall_path="$(seq_or_rev "$reverse_mode" "$wallpaper_dir")" ;; + rnd) wall_path="$(random_paper "$wallpaper_dir")" ;; + vdo) toggle_video && exit 0 || exit 1 ;; + pse) toggle_systemtimer && exit 0 || exit 1 ;; + *) wall_path="${2:-}" ;; +esac + +mkdir -p "$HOME/dotfiles/.config/hypr/env" + +awww img "$wall_path" --transition-type center --transition-duration 0.5