diff --git a/home/home.nix b/home/home.nix index 5f456f8..41573ef 100644 --- a/home/home.nix +++ b/home/home.nix @@ -25,7 +25,7 @@ in { ./programs/ssh ./programs/tealdeer ./programs/thunderbird.nix - ./programs/tmux.nix + ./programs/tmux ./programs/zsh ./services/nix-channel-update.nix diff --git a/home/programs/tmux.nix b/home/programs/tmux/default.nix similarity index 77% rename from home/programs/tmux.nix rename to home/programs/tmux/default.nix index 6df3e6c..68b4b32 100644 --- a/home/programs/tmux.nix +++ b/home/programs/tmux/default.nix @@ -1,4 +1,4 @@ -{pkgs, ...}: +{ pkgs, lib, ... }: { programs.tmux = { enable = true; @@ -19,7 +19,25 @@ tmux-fzf urlview ]; - extraConfig = '' + extraConfig = let + fileContentsWithoutShebang = script: lib.pipe script [ + lib.fileContents + (lib.splitString "\n") + (lib.drop 3) # remove shebang + (lib.concatStringsSep "\n") + ]; + + fcitx5-status = (pkgs.writeShellApplication { + name = "tmux-fcitx5-status"; + runtimeInputs = with pkgs; [ dbus ]; + text = fileContentsWithoutShebang ./scripts/fcitx5-status.sh; + }); + mpd-status = (pkgs.writeShellApplication { + name = "tmux-mpd-status"; + runtimeInputs = with pkgs; [ mpc-cli gawk gnugrep ]; + text = fileContentsWithoutShebang ./scripts/mpd-status.sh; + }); + in '' # Don't rename windows automatically after rename with ',' set-option -g allow-rename off @@ -91,8 +109,8 @@ ### DESIGN CHANGES ### ###################### - set-option -g status-left '#{prefix_highlight} #[bg=blue]#[fg=black,bold] ###S #[bg=default] #[fg=green]#(~/.scripts/tmux/fcitx) #[fg=red]%H:%M ' - set-option -g status-right '#[fg=red]#(~/.scripts/tmux/mpd)' + set-option -g status-left '#{prefix_highlight} #[bg=blue]#[fg=black,bold] ###S #[bg=default] #[fg=green]#(${lib.getExe fcitx5-status}) #[fg=red]%H:%M ' + set-option -g status-right '#[fg=red]#(${lib.getExe mpd-status})' set-window-option -g window-status-current-style fg=magenta set-option -g status-style 'bg=black fg=default' set-option -g default-shell '${pkgs.zsh}/bin/zsh' diff --git a/home/programs/tmux/scripts/fcitx5-status.sh b/home/programs/tmux/scripts/fcitx5-status.sh new file mode 100755 index 0000000..5ad3787 --- /dev/null +++ b/home/programs/tmux/scripts/fcitx5-status.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p dbus + +printState() { + STATUS=$(dbus-send --session --print-reply=literal --dest='org.fcitx.Fcitx5' '/controller' 'org.fcitx.Fcitx.Controller1.CurrentInputMethod' | tr -d '[:space:]') + + case $STATUS in + keyboard-us) + echo 'US' + ;; + keyboard-no) + echo 'NO' + ;; + mozc) + echo '日本語' + ;; + *) + echo "$STATUS?" + ;; + esac +} + +while :; do + printState + sleep 1 +done diff --git a/home/programs/tmux/scripts/mpd-status.sh b/home/programs/tmux/scripts/mpd-status.sh new file mode 100755 index 0000000..9193a4d --- /dev/null +++ b/home/programs/tmux/scripts/mpd-status.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i sh -p mpc-cli gawk gnugrep + +while true; do + MPC_OUTPUT=$(mpc --format '[[%artist% - ]%title%]|[%file%]') + + TITLE=$(head -n 1 <<<"$MPC_OUTPUT") + + if [ ${#TITLE} -gt 60 ]; then + TITLE=$(awk '{print substr($0,0,57) "..."}' <<<"$TITLE") + fi + + LINE2=$(head -n 2 <<<"$MPC_OUTPUT" | tail -n 1) + + PLAY_STATUS_RAW=$(awk '{print $1}' <<<"$LINE2") + + if [ "$PLAY_STATUS_RAW" == "[playing]" ]; then + PLAY_STATUS="▶" + elif [ "$PLAY_STATUS_RAW" == "[paused]" ]; then + PLAY_STATUS="⏸" + else + PLAY_STATUS="??" + fi + + TIME=$(awk '{print $3}' <<<"$LINE2") + + echo -e "$PLAY_STATUS $TITLE | [$TIME]" + sleep 1 +done