1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00
home-manager/modules/programs/sesh.nix
Michael 3527c8c778
sesh: add module (#5789)
Sesh is a CLI that helps you create and manage tmux sessions quickly and easily
using zoxide. See https://github.com/joshmedeski/sesh for more.
2025-03-29 09:32:11 -05:00

86 lines
2.8 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ pkgs, lib, config, ... }:
let
inherit (lib) mkEnableOption mkIf mkMerge mkOption mkPackageOption types;
cfg = config.programs.sesh;
tomlFormat = pkgs.formats.toml { };
in {
meta.maintainers = [ lib.hm.maintainers.michaelvanstraten ];
options.programs.sesh = {
enable = mkEnableOption "the sesh terminal session manager";
package = mkPackageOption pkgs "sesh" { };
fzfPackage = mkPackageOption pkgs "fzf" { nullable = true; };
zoxidePackage = mkPackageOption pkgs "zoxide" { nullable = true; };
settings = mkOption {
type = types.submodule { freeformType = tomlFormat.type; };
default = { };
description = ''
Configuration for sesh, written to `~/.config/sesh/sesh.toml`.
See the [sesh documentation](https://github.com/joshmedeski/sesh#configuration) for available options.
'';
};
enableAlias = mkOption {
type = types.bool;
default = true;
description =
"Whether to enable a shell alias `s` to quickly launch sessions.";
};
enableTmuxIntegration = mkOption {
type = types.bool;
default = true;
description = "Enable Tmux integration with sesh.";
};
tmuxKey = mkOption {
type = types.str;
default = "s";
description = "Keybinding for invoking sesh in Tmux.";
};
};
config = mkIf cfg.enable (mkMerge [
{
home.packages = [ cfg.package ];
home.file.".config/sesh/sesh.toml".source =
tomlFormat.generate "sesh.toml" cfg.settings;
}
(mkIf cfg.enableAlias {
home.packages = lib.mkIf (cfg.fzfPackage != null) [ cfg.fzfPackage ];
home.shellAliases.s = "sesh connect $(sesh list | fzf)";
})
(mkIf cfg.enableTmuxIntegration {
assertions = [{
assertion = config.programs.fzf.tmux.enableShellIntegration;
message =
"To use Tmux integration with sesh, enable `programs.fzf.tmux.enableShellIntegration`.";
}];
home.packages =
lib.mkIf (cfg.zoxidePackage != null) [ cfg.zoxidePackage ];
programs.tmux.extraConfig = ''
bind-key "${cfg.tmuxKey}" run-shell "sesh connect \"$(
sesh list | fzf-tmux -p 55%,60% \
--no-sort --ansi --border-label ' sesh ' --prompt ' ' \
--header ' ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \
--bind 'tab:down,btab:up' \
--bind 'ctrl-a:change-prompt( )+reload(sesh list)' \
--bind 'ctrl-t:change-prompt(🪟 )+reload(sesh list -t)' \
--bind 'ctrl-g:change-prompt( )+reload(sesh list -c)' \
--bind 'ctrl-x:change-prompt(📁 )+reload(sesh list -z)' \
--bind 'ctrl-f:change-prompt(🔎 )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
--bind 'ctrl-d:execute(tmux kill-session -t {})+change-prompt( )+reload(sesh list)'
)\""
'';
})
]);
}