home/tmux: add missing scripts

This commit is contained in:
Oystein Kristoffer Tveit 2024-11-18 14:21:53 +01:00
parent 2b8a661288
commit d65273e67a
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
4 changed files with 78 additions and 5 deletions

View File

@ -25,7 +25,7 @@ in {
./programs/ssh ./programs/ssh
./programs/tealdeer ./programs/tealdeer
./programs/thunderbird.nix ./programs/thunderbird.nix
./programs/tmux.nix ./programs/tmux
./programs/zsh ./programs/zsh
./services/nix-channel-update.nix ./services/nix-channel-update.nix

View File

@ -1,4 +1,4 @@
{pkgs, ...}: { pkgs, lib, ... }:
{ {
programs.tmux = { programs.tmux = {
enable = true; enable = true;
@ -19,7 +19,25 @@
tmux-fzf tmux-fzf
urlview 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 ',' # Don't rename windows automatically after rename with ','
set-option -g allow-rename off set-option -g allow-rename off
@ -91,8 +109,8 @@
### DESIGN CHANGES ### ### 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-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]#(~/.scripts/tmux/mpd)' set-option -g status-right '#[fg=red]#(${lib.getExe mpd-status})'
set-window-option -g window-status-current-style fg=magenta set-window-option -g window-status-current-style fg=magenta
set-option -g status-style 'bg=black fg=default' set-option -g status-style 'bg=black fg=default'
set-option -g default-shell '${pkgs.zsh}/bin/zsh' set-option -g default-shell '${pkgs.zsh}/bin/zsh'

View File

@ -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

View File

@ -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