From 9e33dc24ba3ea8d793b929b5a2bb25eb50908a31 Mon Sep 17 00:00:00 2001 From: Michael van Straten Date: Sat, 29 Mar 2025 20:43:02 +0900 Subject: [PATCH] sesh: add module 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. --- modules/lib/maintainers.nix | 6 ++ modules/misc/news.nix | 11 +++ modules/modules.nix | 1 + modules/programs/sesh.nix | 86 +++++++++++++++++++ tests/default.nix | 1 + .../programs/sesh/basic-configuration.nix | 33 +++++++ .../programs/sesh/basic-configuration.toml | 12 +++ tests/modules/programs/sesh/default.nix | 1 + 8 files changed, 151 insertions(+) create mode 100644 modules/programs/sesh.nix create mode 100644 tests/modules/programs/sesh/basic-configuration.nix create mode 100644 tests/modules/programs/sesh/basic-configuration.toml create mode 100644 tests/modules/programs/sesh/default.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 9fb20cdd5..05cb685b2 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -732,4 +732,10 @@ github = "Noodlez1232"; githubId = 12480453; }; + michaelvanstraten = { + name = "Michael van Straten"; + email = "michael@vanstraten.de"; + github = "michaelvanstraten"; + githubId = 50352631; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 51c35976a..da0069754 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2180,6 +2180,17 @@ in { scrobbler (e.g. last.fm) ''; } + + { + time = "2025-03-29T11:16:07+00:00"; + message = '' + A new module is available: 'programs.sesh'. + + 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. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index b48ef31af..bf2795b8a 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -237,6 +237,7 @@ let ./programs/scmpuff.nix ./programs/script-directory.nix ./programs/senpai.nix + ./programs/sesh.nix ./programs/sftpman.nix ./programs/sioyek.nix ./programs/skim.nix diff --git a/modules/programs/sesh.nix b/modules/programs/sesh.nix new file mode 100644 index 000000000..fac50c044 --- /dev/null +++ b/modules/programs/sesh.nix @@ -0,0 +1,86 @@ +{ 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)' + )\"" + ''; + }) + ]); +} diff --git a/tests/default.nix b/tests/default.nix index 04d7b1c52..a7d561695 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -386,6 +386,7 @@ in import nmtSrc { ./modules/programs/sbt ./modules/programs/scmpuff ./modules/programs/senpai + ./modules/programs/sesh ./modules/programs/sftpman ./modules/programs/sioyek ./modules/programs/sm64ex diff --git a/tests/modules/programs/sesh/basic-configuration.nix b/tests/modules/programs/sesh/basic-configuration.nix new file mode 100644 index 000000000..120cae3aa --- /dev/null +++ b/tests/modules/programs/sesh/basic-configuration.nix @@ -0,0 +1,33 @@ +{ pkgs, ... }: + +{ + config = { + programs.fzf.tmux.enableShellIntegration = true; + + programs.sesh = { + enable = true; + package = pkgs.writeScriptBin "dummy-polybar" ""; + settings = { + default_session.startup_command = "nvim -c ':Telescope find_files'"; + session = [ + { + name = "Downloads 📥"; + path = "~/Downloads"; + startup_command = "ls"; + } + { + name = "tmux config"; + path = "~/c/dotfiles/.config/tmux"; + startup_command = "nvim tmux.conf"; + } + ]; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/sesh/sesh.toml + assertFileContent home-files/.config/sesh/sesh.toml \ + ${./basic-configuration.toml} + ''; + }; +} diff --git a/tests/modules/programs/sesh/basic-configuration.toml b/tests/modules/programs/sesh/basic-configuration.toml new file mode 100644 index 000000000..1b7ce6da5 --- /dev/null +++ b/tests/modules/programs/sesh/basic-configuration.toml @@ -0,0 +1,12 @@ +[default_session] +startup_command = "nvim -c ':Telescope find_files'" + +[[session]] +name = "Downloads 📥" +path = "~/Downloads" +startup_command = "ls" + +[[session]] +name = "tmux config" +path = "~/c/dotfiles/.config/tmux" +startup_command = "nvim tmux.conf" diff --git a/tests/modules/programs/sesh/default.nix b/tests/modules/programs/sesh/default.nix new file mode 100644 index 000000000..36d878501 --- /dev/null +++ b/tests/modules/programs/sesh/default.nix @@ -0,0 +1 @@ +{ sesh-basic-configuration = ./basic-configuration.nix; }