Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions home-manager/programs/fish/functions/_two_function.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ function _two_function --description "Attach to tmux work session"
return
end

set -l restore (tmux list-keys 2>/dev/null | string match -rg '(/\S+/resurrect/scripts/restore\.sh)')
set -l restore $restore[1]
set -l bootstrapped 0

# Start a server if needed so we can invoke the restore script.
# Start a server if needed so plugins load and resurrect becomes available.
if not tmux list-sessions 2>/dev/null | grep -q .
tmux new-session -d -s _bootstrap
set bootstrapped 1
end

# Resolve restore script after server is running (plugins are loaded).
set -l restore (tmux show-options -gv @resurrect-restore-script-path 2>/dev/null)
if test -z "$restore"
set restore (tmux list-keys 2>/dev/null | string match -rg '(/\S+/resurrect/scripts/restore\.sh)')
set restore $restore[1]
end

if test -n "$restore"
tmux run-shell "$restore"
# Give tmux-resurrect a moment to recreate the work session.
for _i in (seq 1 50)
if tmux has-session -t work 2>/dev/null
if test $bootstrapped -eq 1
Expand All @@ -41,7 +45,6 @@ function _two_function --description "Attach to tmux work session"
tmux kill-session -t _bootstrap 2>/dev/null
end

# Restore didn't produce work — fall back to the built-in session bootstrap.
__tmux_bootstrap_default_session work
or return 1

Expand Down
34 changes: 29 additions & 5 deletions home-manager/programs/tmux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,38 @@
enable = true;
extraConfig = builtins.readFile ./tmux.conf;
plugins = with pkgs.tmuxPlugins; [
continuum
extrakto
{
plugin = extrakto;
extraConfig = "set -g @extrakto_key 'tab'";
}
open
resurrect
{
plugin = resurrect;
extraConfig = ''
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-processes 'btop fish git'
set -g @resurrect-hook-post-save-all 'd=~/.tmux/resurrect && f="$d/$(readlink "$d/last")" && grep -P "^(pane|window)\twork\t" "$f" > "$f.tmp" && printf "state\twork\n" >> "$f.tmp" && mv "$f.tmp" "$f"'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The resurrect-hook-post-save-all hook is somewhat fragile as it relies on the user's PATH for commands like grep, readlink, and mv. In a Nix environment, it's more robust to use absolute paths from pkgs. Additionally, using $HOME instead of ~ and adding a check for the existence of the last symlink improves reliability.

          set -g @resurrect-hook-post-save-all 'd=$HOME/.tmux/resurrect; [ -L "$d/last" ] && f="$d/$(${pkgs.coreutils}/bin/readlink "$d/last")" && ${pkgs.gnugrep}/bin/grep -P "^(pane|window)\twork\t" "$f" > "$f.tmp" && ${pkgs.coreutils}/bin/printf "state\twork\n" >> "$f.tmp" && ${pkgs.coreutils}/bin/mv "$f.tmp" "$f"'

'';
}
{
plugin = continuum;
extraConfig = ''
set -g @continuum-restore 'on'
set -g @continuum-save-interval '3'
set -g status-right "#[fg=colour250]#{?#{pane_current_command},#{pane_current_command},} #[fg=colour28]| #[fg=colour255]%Y/%m/%d %H:%M:%S #{continuum_status}"
set -g status-right-length 60
'';
}
sensible
tmux-fzf
tmux-sessionx
tmux-thumbs
{
plugin = tmux-sessionx;
extraConfig = "set -g @sessionx-bind 'o'";
}
{
plugin = tmux-thumbs;
extraConfig = "set -g @thumbs-key Space";
}
yank
];
};
Expand Down
24 changes: 3 additions & 21 deletions home-manager/programs/tmux/tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ set -g @clipboard_cmd "~/.local/scripts/clipboard-copy"
# Status bar
set -g status "on"
set -g status-justify "left"
set -g status-left-length "100"
set -g status-right-length "100"
set -g status-left ""
set -g status-left-style NONE
set -g status-right-style NONE
Expand Down Expand Up @@ -107,9 +105,9 @@ set -g clock-mode-style 24
# =============================================================================
set -g status-style "bg=colour22,fg=colour255"
set -g status-left "#[bg=colour28,fg=colour255,bold] #S #[bg=colour22,fg=colour28] "
set -g status-right "#[fg=colour250]#{?#{pane_current_command},#{pane_current_command},} #[fg=colour28]| #[fg=colour255]%Y/%m/%d %H:%M:%S #{continuum_status}"
# status-right and status-right-length are set in default.nix continuum
# extraConfig so the plugin can prepend its save trigger to status-right.
set -g status-left-length 30
set -g status-right-length 60

# Window status
set -g window-status-format " #I:#W "
Expand All @@ -124,25 +122,12 @@ set -g pane-active-border-style "fg=colour82,bold"
set -g message-style "bg=colour28,fg=colour255"

# =============================================================================
# Plugin configuration
# Plugin configuration (options are in default.nix extraConfig per plugin)
# =============================================================================
# Resurrect + Continuum (session persistence — work session only)
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-processes 'btop fish git'
set -g @resurrect-hook-post-save-all 'd=~/.tmux/resurrect && f="$d/$(readlink "$d/last")" && grep -E "^(pane|window) work " "$f" > "$f.tmp" && printf "state\twork\n" >> "$f.tmp" && mv "$f.tmp" "$f"'
set -g @continuum-restore 'on'
set -g @continuum-save-interval '3'

# Auto-save on detach/close so kills don't lose state
set-hook -g client-detached 'run-shell #{@resurrect-save-script-path}'
set-hook -g session-closed 'run-shell #{@resurrect-save-script-path}'

# Tmux-thumbs (quick text copy)
set -g @thumbs-key Space

# Sessionx (session manager)
set -g @sessionx-bind 'o'

# Tmux sessionizer (fzf session picker)
bind S run-shell "tmux new-window 'fish -c _tss_function'"

Expand All @@ -158,9 +143,6 @@ bind H run-shell "tmux new-window 'fish -c _tsh_function'"
# Kill sessions/windows via fzf
bind K run-shell "tmux new-window 'fish -c _tsk_function'"

# Extrakto (text extraction)
set -g @extrakto_key 'tab'

set -g history-limit 2147483647

# =============================================================================
Expand Down
Loading