From dbea61d65258eee2cc7a679ad79191ae6fb2a71f Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Wed, 4 Sep 2024 01:50:34 +0200 Subject: [PATCH] feat(home-manager): add cmus module --- hosts/morty/home-config.nix | 1 + modules/home-manager/audio/cmus/default.nix | 17 ++++++ .../home-manager/audio/cmus/files/notify.sh | 45 +++++++++++++++ modules/home-manager/audio/cmus/files/rc | 56 +++++++++++++++++++ modules/home-manager/default.nix | 1 + 5 files changed, 120 insertions(+) create mode 100644 modules/home-manager/audio/cmus/default.nix create mode 100755 modules/home-manager/audio/cmus/files/notify.sh create mode 100644 modules/home-manager/audio/cmus/files/rc diff --git a/hosts/morty/home-config.nix b/hosts/morty/home-config.nix index bd1d909..ed7d5a9 100644 --- a/hosts/morty/home-config.nix +++ b/hosts/morty/home-config.nix @@ -5,6 +5,7 @@ zathura.enable = true; foot.enable = true; }; + audio.cmus.enable = true; cli = { direnv.enable = true; ghq.enable = true; diff --git a/modules/home-manager/audio/cmus/default.nix b/modules/home-manager/audio/cmus/default.nix new file mode 100644 index 0000000..acec36f --- /dev/null +++ b/modules/home-manager/audio/cmus/default.nix @@ -0,0 +1,17 @@ +{ lib, config, pkgs, ... }: +with lib; +let + cfg = config.modules.audio.cmus; +in +{ + options.modules.audio.cmus= { + enable = mkEnableOption "enable cmus audio player"; + }; + config = mkIf cfg.enable { + home.packages = with pkgs; [ + cmus + ]; + home.file.".config/cmus/rc".source = ./files/rc; + home.file.".config/cmus/notify.sh".source = ./files/notify.sh; + }; +} diff --git a/modules/home-manager/audio/cmus/files/notify.sh b/modules/home-manager/audio/cmus/files/notify.sh new file mode 100755 index 0000000..d11fbff --- /dev/null +++ b/modules/home-manager/audio/cmus/files/notify.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2154 +process_args() { + while [ "$#" -ge 2 ] + do + printf -v "$1" "%s" "$2" + shift + shift + done +} + +main() { + filename=${file#*/} + image=${file%/*}/cover.jpg + [ -f "$image" ] && options="$options -i \"${image}\"" + + title=${title:-$filename} + if [[ ${#title} -gt 25 ]]; then + title="${title:0:24}…" + fi + + if [ -n "$artist" ] + then + if [[ ${#artist} -gt 22 ]]; then + artist="by ${artist:0:21}…" + fi + fi + + if [ -n "$album" ] + then + if [[ ${#album} -gt 19 ]]; then + album="${album:0:18}…" + fi + fi + + if [ -n "$date" ] + then + date="${date%%-*}" + fi + printf -v body "%s\n%-19s %s" "${artist:-}" "${album:-}" "${date:-}" + notify-send --app-name=cmus -i "$image" "$title" "$body" +} + +process_args "$@" +main diff --git a/modules/home-manager/audio/cmus/files/rc b/modules/home-manager/audio/cmus/files/rc new file mode 100644 index 0000000..ea71c79 --- /dev/null +++ b/modules/home-manager/audio/cmus/files/rc @@ -0,0 +1,56 @@ +## Base16 Default Dark + +# overall background and foreground color +set color_win_fg=7 +set color_win_bg=0 + +# bottom status line +set color_statusline_fg=20 +set color_statusline_bg=19 + +# bottom title line +set color_titleline_fg=7 +set color_titleline_bg=18 + +# top title area +set color_win_title_fg=20 +set color_win_title_bg=19 +set color_win_title_attr=bold + +# command-line colors +set color_cmdline_bg=default +set color_cmdline_fg=default +set color_error=1 +set color_info=6 + +# separator of windows +# should be black +set color_separator=16 + +# unselected currently playing track's text +set color_win_cur=13 + +# active selection for currently playing track +set color_win_cur_sel_bg=20 +set color_win_cur_sel_fg=0 +set color_win_cur_sel_attr=none + +# inactive selection for currently playing track +set color_win_inactive_cur_sel_bg=8 +set color_win_inactive_cur_sel_fg=21 + +# active selection +set color_win_sel_bg=6 +set color_win_sel_fg=0 +set color_win_sel_attr=none + +# inactive selection +set color_win_inactive_sel_bg=19 +set color_win_inactive_sel_fg=20 + +# directory listing color +set color_win_dir=default + +set status_display_program=~/.config/cmus/notify.sh + +add -l ~/medias/music diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index 9025c48..eee7b36 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -5,6 +5,7 @@ ./application/gnupg ./application/imv ./application/zathura + ./audio/cmus ./cli/direnv ./cli/ghq/default.nix ./cli/git