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,48 +1,22 @@
{ 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;
in
{
options.snowhawk.tmux.sessionizer = {
enable = lib.mkEnableOption "tmux-sessionizer home-manager module";
paths = lib.mkOption { tmux-sessionizer = pkgs.writeShellApplication {
type = with lib.types; listOf str;
description = ''
list of paths to select with tmux-sessionizer
'';
default = [ ];
example = [
"~"
"~/projects"
"~/src"
];
};
pkg = lib.mkOption {
type = lib.types.package;
description = ''
tmux-sessionizer binary package
'';
};
};
config = lib.mkIf enable {
snowhawk.tmux.sessionizer.pkg =
lib.mkDefault (pkgs.writeShellApplication {
name = "tmux-sessionizer"; name = "tmux-sessionizer";
runtimeInputs = with pkgs; [ tmux fzf findutils coreutils procps ]; runtimeInputs = with pkgs; [ tmux fzf findutils coreutils procps ];
text = '' text = ''
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
selected=$1 selected=$1
else else
selected=$(find -L ${lib.concatStringsSep " " cfg.paths} -mindepth 1 -maxdepth 1 -type d | fzf) selected=$(find -L ${lib.concatStringsSep " " cfg.paths} -mindepth 1 -maxdepth 1 -type d \
| fzf --tmux center --preview="ls {} --color || true")
fi fi
if [[ -z $selected ]]; then if [[ -z $selected ]]; then
@ -63,8 +37,39 @@ in
tmux switch-client -t "$selected_name" tmux switch-client -t "$selected_name"
''; '';
}); };
in
{
options.snowhawk.tmux.sessionizer = {
enable = lib.mkEnableOption "tmux-sessionizer home-manager module";
home.packages = [ cfg.pkg ]; paths = lib.mkOption {
type = with lib.types; listOf str;
description = ''
list of paths to select with tmux-sessionizer
'';
default = [ ];
example = [
"~"
"~/projects"
"~/src"
];
};
package = lib.mkOption {
type = lib.types.package;
default = tmux-sessionizer;
description = ''
tmux-sessionizer binary package
'';
};
};
config = lib.mkIf enable {
home.packages = [ cfg.package ];
programs.tmux.extraConfig = ''
bind-key -r f run-shell "tmux neww ${getExe cfg.package}"
'';
}; };
} }

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}"
''; '';
}; };