-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: modularize tmux for better readability and maintainability
- Loading branch information
1 parent
d457ef1
commit 897a924
Showing
21 changed files
with
221 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
imports = builtins.attrValues (import ./../modules); | ||
|
||
konrad.programs.tmux.enable = true; | ||
konrad.programs.ssh-egress.enable = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ tmux-switcher, tmuxTextProcessor, pkgs, ... }: | ||
'' | ||
## KONRAD's SENSIBLE DEFAULTS | ||
# tmux messages are displayed for 4 seconds | ||
set-option -g display-time 4000 | ||
# upgrade color and fix italics | ||
set -ga terminal-overrides ",-256color:Tc,alacritty:Tc" | ||
# focus events enabled for terminals that support them | ||
set-option -g focus-events on | ||
# refresh interval | ||
set-option -g status-interval 60 | ||
# Let the window to be renamed automatically when launching a process | ||
set-option -g automatic-rename on | ||
# But prevent renaming once you have manually changed it. And you can re-rename it after. | ||
set-option -g allow-rename off | ||
set-option -g set-titles on | ||
# renumber so that we have 1,2,3 always | ||
set-option -g renumber-windows on | ||
# Set window notifications | ||
set-option -g monitor-activity on | ||
set-option -g visual-activity off | ||
# vim splits | ||
bind-key v split-window -h | ||
bind-key g split-window -v | ||
# vim panes | ||
bind-key h select-pane -L | ||
bind-key j select-pane -D | ||
bind-key k select-pane -U | ||
bind-key l select-pane -R | ||
# vim pane resize | ||
bind-key < resize-pane -L 10 | ||
bind-key > resize-pane -R 10 | ||
bind-key - resize-pane -D 10 | ||
bind-key + resize-pane -U 10 | ||
# Setup 'v' to begin selection, just like vim | ||
bind-key -T copy-mode-vi 'v' send-keys -X begin-selection | ||
bind-key -T copy-mode-vi 'V' send-keys -X select-line | ||
bind-key -T copy-mode-vi 'r' send-keys -X rectangle-toggle | ||
# Setup 'y' to yank (copy), just like VIM | ||
bind-key -T copy-mode-vi 'y' send-keys -X copy-selection-and-cancel | ||
# Setup P (capital) to paste after the prefix keys, JUST LIKE VIM | ||
bind P paste-buffer | ||
# Use m to toggle mouse mode | ||
unbind m | ||
bind-key m setw mouse | ||
# enable mouse by default, useful for resizing | ||
set-option -g mouse on | ||
# when nested tmux session, | ||
# C-a will send the prefix directly to the remote session | ||
# C-A clashes with C-A in neovim! | ||
#bind-key -n C-a send-prefix | ||
# facebook pathpicker | ||
bind-key F run-shell -b "${tmuxTextProcessor} '${pkgs.fpp}/bin/fpp' '#{pane_id}' '#{pane_current_path}'" | ||
# urlscan | ||
bind-key U run-shell -b "${tmuxTextProcessor} '${pkgs.urlscan}/bin/urlscan' '#{pane_id}' '#{pane_current_path}'" | ||
# tmux session switcher | ||
bind-key r run-shell -b "${tmux-switcher}/bin/tmux-switcher" | ||
# toggle last window | ||
bind-key W last-window | ||
# toggle last session | ||
bind-key S switch-client -l | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ config, lib, pkgs, ... }: | ||
with lib; | ||
let | ||
cfg = config.konrad.programs.tmux; | ||
tmuxTextProcessor = pkgs.callPackage ./text_processor.nix { }; | ||
tmux-sessionizer = pkgs.callPackage ./tmux-sessionizer { }; | ||
tmux-switcher = pkgs.callPackage ./tmux-switcher { }; | ||
tmux-windowizer = pkgs.callPackage ./tmux-windowizer { }; | ||
baseConfig = pkgs.callPackage ./config.nix { inherit tmuxTextProcessor tmux-switcher; }; | ||
themeConfig = import ./theme.nix { inherit (cfg) colorscheme; }; | ||
in | ||
{ | ||
options.konrad.programs.tmux = { | ||
enable = mkEnableOption "Enables personalized tmux through home-manager"; | ||
|
||
colorscheme = lib.mkOption { | ||
type = lib.types.nullOr lib.types.attrs; | ||
default = config.colorscheme; | ||
description = "Colorscheme attrset compatible with nix-colors format."; | ||
example = "config.colorscheme"; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable | ||
{ | ||
programs.tmux = { | ||
enable = true; | ||
aggressiveResize = true; | ||
sensibleOnTop = true; | ||
# tmux-256color is the proper one to enable italics | ||
# just ensure you have that terminfo, newer ncurses provide it | ||
# Macos does not have it but we fix that by installing ncurses through nix-darwin | ||
# screen-256color works properly everywhere but does not have italics | ||
terminal = "tmux-256color"; | ||
keyMode = "vi"; | ||
escapeTime = 0; | ||
baseIndex = 1; | ||
historyLimit = 50000; | ||
extraConfig = lib.concatStringsSep "\n" [ baseConfig themeConfig ]; | ||
plugins = [ ]; | ||
}; | ||
|
||
programs.git.ignores = [ | ||
".tmux.sh" | ||
]; | ||
|
||
programs.fzf.tmux.enableShellIntegration = true; | ||
|
||
programs.zsh = { | ||
initExtra = '' | ||
# tmux baby | ||
# (this cannot be a zsh widget unfortunately, tmux attach can only attach to a terminal, | ||
# but zsh widgets do not allocate/reuse current terminal) | ||
__txs() { ${pkgs.tmux-sessionizer}/bin/tmux-sessionizer } | ||
bindkey -s '^F' '^u__txs^M' | ||
# fix for ssh socket and display env var in tmux | ||
# run after attaching to a remote session for a 2+ time if you need it | ||
tmux-refresh() { | ||
eval "$(tmux show-environment -s SSH_AUTH_SOCK)" | ||
eval "$(tmux show-environment -s DISPLAY)" | ||
} | ||
''; | ||
shellAliases = { | ||
txs = "${tmux-sessionizer}/bin/tmux-sessionizer"; | ||
txw = "${tmux-windowizer}/bin/tmux-windowizer"; | ||
txr = "${tmux-switcher}/bin/tmux-switcher"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ tmux, writeShellScript, ... }: | ||
let | ||
tmux' = "${tmux}/bin/tmux"; | ||
in | ||
writeShellScript "tmux_text_processor" '' | ||
program="$1" | ||
paneid="$2" | ||
currentpanepath="$3" | ||
capturename="$(basename $program)-$paneid" | ||
showandpipe="${tmux'} show-buffer -b '$capturename' | $program || true; ${tmux'} delete-buffer -b '$capturename'" | ||
${tmux'} capture-pane -J -S - -E - -b "$capturename" -t "$paneid" | ||
${tmux'} split-window -c "$currentpanepath" "$showandpipe" | ||
'' |
Oops, something went wrong.