Compare commits

...

2 Commits

Author SHA1 Message Date
Zynh Ludwig 581d729b79 tmux-sessionizer: preview 2024-08-23 06:27:44 -07:00
Zynh Ludwig 9fee4f6f3d tmux-sessionizer: 2.0 2024-08-23 06:26:48 -07:00
2 changed files with 39 additions and 37 deletions

View File

@ -1,12 +1,43 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
inherit (lib) getExe getExe'; inherit (lib) getExe;
cfg = config.snowhawk.tmux.sessionizer; cfg = config.snowhawk.tmux.sessionizer;
tmuxCfg = config.snowhawk.tmux; tmuxCfg = config.snowhawk.tmux;
enable = cfg.enable && tmuxCfg.enable; enable = cfg.enable && tmuxCfg.enable;
tmux-sessionizer = pkgs.writeShellApplication {
name = "tmux-sessionizer";
runtimeInputs = with pkgs; [ tmux fzf findutils coreutils procps ];
text = ''
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find -L ${lib.concatStringsSep " " cfg.paths} -mindepth 1 -maxdepth 1 -type d \
| fzf --tmux center --preview="ls {} --color || true")
fi
if [[ -z $selected ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
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"
'';
};
in in
{ {
options.snowhawk.tmux.sessionizer = { options.snowhawk.tmux.sessionizer = {
@ -25,8 +56,9 @@ in
]; ];
}; };
pkg = lib.mkOption { package = lib.mkOption {
type = lib.types.package; type = lib.types.package;
default = tmux-sessionizer;
description = '' description = ''
tmux-sessionizer binary package tmux-sessionizer binary package
''; '';
@ -34,37 +66,10 @@ in
}; };
config = lib.mkIf enable { config = lib.mkIf enable {
snowhawk.tmux.sessionizer.pkg = home.packages = [ cfg.package ];
lib.mkDefault (pkgs.writeShellApplication {
name = "tmux-sessionizer";
runtimeInputs = with pkgs; [ tmux fzf findutils coreutils procps ];
text = ''
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find -L ${lib.concatStringsSep " " cfg.paths} -mindepth 1 -maxdepth 1 -type d | fzf)
fi
if [[ -z $selected ]]; then programs.tmux.extraConfig = ''
exit 0 bind-key -r f run-shell "tmux neww ${getExe cfg.package}"
fi '';
selected_name=$(basename "$selected" | tr . _)
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"
'';
});
home.packages = [ cfg.pkg ];
}; };
} }

View File

@ -1,10 +1,9 @@
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
let let
inherit (lib) getExe optionalString; inherit (lib) getExe;
cfg = config.snowhawk.tmux; cfg = config.snowhawk.tmux;
sessionizer = cfg.sessionizer;
macos = config.snowhawk.macos.enable; macos = config.snowhawk.macos.enable;
in in
{ {
@ -41,8 +40,6 @@ in
bind '"' split-window -v -c "#{pane_current_path}" bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}"
'' + optionalString sessionizer.enable ''
bind-key -r f run-shell "tmux neww ${getExe sessionizer.pkg}"
''; '';
}; };