feat(devkit): use tmux since zellij is currently broken

This commit is contained in:
Guz
2025-02-18 18:46:59 -03:00
parent 7b5a017e2b
commit 62eb5cfbf8
5 changed files with 249 additions and 8 deletions

View File

@@ -32,6 +32,10 @@ in {
type = with types; bool;
default = cfg.enable;
};
tmux.enable = mkOption {
type = with types; bool;
default = cfg.enable;
};
yazi.enable = mkOption {
type = with types; bool;
default = cfg.enable;
@@ -132,17 +136,59 @@ in {
};
## Zellij (Terminal multiplexer)
programs.zellij = lib.mkIf cfg.zellij.enable {
#
# CURRENTLY BORKED https://github.com/zellij-org/zellij/issues/3970
#
# programs.zellij = lib.mkIf cfg.zellij.enable {
# enable = true;
# package = devkitPkgs.zellij;
# # package = pkgs.zellij;
# };
## Tmux (Backup terminal multiplexer)
programs.tmux = lib.mkIf cfg.tmux.enable {
enable = true;
package = devkitPkgs.zellij;
# package = pkgs.zellij;
package = devkitPkgs.tmux;
# baseIndex = 1;
# keyMode = "vi";
# mouse = true;
# prefix = "Ctrl-G";
# shell = lib.getExe config.programs.zsh.package;
# terminal = "screen-256color";
# plugins = with pkgs; [
# {
# plugin = tmuxPlugins.catppuccin.overrideAttrs (_: {
# src = fetchFromGitHub {
# owner = "guz013";
# repo = "frappuccino-tmux";
# rev = "4255b0a769cc6f35e12595fe5a33273a247630aa";
# sha256 = "0k8yprhx5cd8v1ddpcr0dkssspc17lq2a51qniwafkkzxi3kz3i5";
# };
# });
# }
# {plugin = tmuxPlugins.better-mouse-mode;}
# {
# plugin = tmuxPlugins.mkTmuxPlugin {
# pluginName = "tmux.nvim";
# version = "unstable-2024-04-05";
# src = fetchFromGitHub {
# owner = "aserowy";
# repo = "tmux.nvim";
# rev = "63e9c5e054099dd30af306bd8ceaa2f1086e1b07";
# sha256 = "0ynzljwq6hv7415p7pr0aqx8kycp84p3p3dy4jcx61dxfgdpgc4c";
# };
# };
# }
# {plugin = tmuxPlugins.resurrect;}
# {plugin = tmuxPlugins.continuum;}
# ];
};
## ZSH (Default shell)
programs.zsh = lib.mkIf cfg.zsh.enable {
enable = true;
# package = devkitPkgs.zsh;
package = pkgs.zsh;
package = devkitPkgs.zsh;
# package = pkgs.zsh;
};
};
}

View File

@@ -3,9 +3,9 @@
git = pkgs.callPackage ./git {};
lazygit = pkgs.callPackage ./lazygit {};
starship = pkgs.callPackage ./starship {};
tmux = pkgs.callPackage ./tmux {shell = zsh;};
yazi = pkgs.callPackage ./yazi {};
zellij = pkgs.callPackage ./zellij {
shell = zsh;
};
# CURRENTLY BORKED https://github.com/zellij-org/zellij/issues/3970
# zellij = pkgs.callPackage ./zellij {shell = zsh;};
zsh = pkgs.callPackage ./zsh {};
}

View File

@@ -0,0 +1,75 @@
set -g default-terminal "screen-256color"
set -g base-index 1
setw -g pane-base-index 1
set -g status-keys vi
set -g mode-keys vi
# rebind main key: C-g
unbind C-b
set -g prefix C-g
bind -N "Send the prefix key through to the application" \
C-g send-prefix
set -g mouse on
setw -g aggressive-resize off
setw -g clock-mode-style 12
set -s escape-time 500
set -g history-limit 2000
set -sg terminal-overrides ",*:RGB"
set -g renumber-windows on
# Split panes
bind -T prefix / split-window -v -c "#{pane_current_path}"
bind -T prefix \\ split-window -h -c "#{pane_current_path}"
# Panes
bind 'h' select-pane -L # move left after prefix
bind 'j' select-pane -D # move down after prefix
bind 'k' select-pane -U # move up after prefix
bind 'l' select-pane -R # move right after prefix
bind -n 'C-h' select-pane -L # move left
bind -n 'C-j' select-pane -D # move down
bind -n 'C-k' select-pane -U # move up
bind -n 'C-l' select-pane -R # move right
# bind -r 'S-h' resize-pane -L 5
# bind -r 'S-j' resize-pane -D 5
# bind -r 'S-k' resize-pane -U 5
# bind -r 'S-l' resize-pane -R 5
bind '<' swap-pane -D # swap current pane with the next one
bind '>' swap-pane -U # swap current pane with the previous one
# Windows
bind 'C-h' previous-window # select previous window
bind 'C-l' next-window # select next window
bind 'Tab' last-window # select last window
bind 'c' new-window -c "${pane_current_path}" # new window
set -g @catppuccin_window_number_position "right"
set -g @catppuccin_window_default_fill "number"
set -g @catppuccin_window_default_text "#W"
set -g @catppuccin_window_current_fill "number"
set -g @catppuccin_window_current_text "#W"
set -g @catppuccin_status_modules_right "directory user host session"
set -g @catppuccin_status_fill "icon"
set -g @catppuccin_status_connect_separator "no"
set -g @catppuccin_directory_text "#{pane_current_path}"
set -g @resurrect-strategy-nvim 'session'
set-option -g mouse on
set -g @continuum-restore 'on'

View File

@@ -0,0 +1,80 @@
{
symlinkJoin,
makeWrapper,
pkgs,
lib,
fetchFromGitHub,
tmux ? pkgs.tmux,
fzf ? pkgs.fzf,
shell ? pkgs.zsh,
}: let
# colors = import ../colors.nix;
sessionizer = pkgs.writeShellScriptBin "sessionizer" ''
function tmux() { ${lib.getExe tmux} "$@"; }
function fzf() { ${lib.getExe fzf} "$@"; }
${builtins.readFile ./sessionizer.sh}
'';
plugins = with pkgs.tmuxPlugins; [
sensible
better-mouse-mode
continuum
resurrect
(catppuccin.overrideAttrs (_: {
src = fetchFromGitHub {
owner = "guz013";
repo = "frappuccino-tmux";
rev = "4255b0a769cc6f35e12595fe5a33273a247630aa";
sha256 = "0k8yprhx5cd8v1ddpcr0dkssspc17lq2a51qniwafkkzxi3kz3i5";
};
}))
];
cfg = pkgs.writeText "tmux.conf" ''
${(lib.concatMapStringsSep "\n\n" (p: ''
run-shell ${p.rtp}
'')
plugins)}
set -g default-shell "${lib.getExe shell}"
${builtins.readFile ./config.conf}
bind -T prefix g run-shell "tmux neww ${lib.getExe sessionizer}"
'';
drv = symlinkJoin ({
paths = tmux;
nativeBuildInputs = [makeWrapper];
postBuild = ''
wrapProgram $out/bin/tmux \
--add-flags '-f' --add-flags '${cfg}'
'';
}
// {inherit (tmux) name pname man meta;});
in
pkgs.stdenv.mkDerivation (rec {
name = drv.name;
pname = drv.pname;
buildCommand = let
desktopEntry = pkgs.makeDesktopItem {
name = pname;
desktopName = name;
exec = "${lib.getExe drv}";
terminal = true;
};
in ''
mkdir -p $out/bin
cp ${lib.getExe drv} $out/bin
mkdir -p $out/share/applications
cp ${desktopEntry}/share/applications/${pname}.desktop $out/share/applications/${pname}.desktop
'';
}
// {inherit (tmux) man meta;})

View File

@@ -0,0 +1,40 @@
# "Chat is MIT"
# https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/scripts/tmux-sessionizer
SEARCH_PATHS=("$HOME/.projects" "$HOME/.job" "$HOME/.work")
function tmux_sessionizer() {
local paths=()
for p in "${SEARCH_PATHS[@]}"; do
if [ -d "$p" ]; then
paths+=("$p")
fi
done
if [[ $# -eq 1 ]]; then
selected="$1"
else
selected="$(find "${paths[@]}" -mindepth 1 -maxdepth 1 -type d | fzf)"]
fi
if [[ -z "$selected" ]]; then
exit 0
fi
local selected_name="$(basename "$selected" | tr . _)"
local tmux_running="$(pgrep tmux)"
if [[ -z "$TMUX" ]] && [[ -z "$tmux_running" ]]; then
tmux new-session -s "$selected_name" -c "$selected"
exit 0
fi
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
tmux new-session -ds "$selected_name" -c "$selected"
fi
tmux switch-client -t "$selected_name"
}
tmux_sessionizer "$@"