diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 9793d5c3f..920080366 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -587,4 +587,10 @@ github = "zorrobert"; githubId = 118135271; }; + 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 bef867bb4..60b495859 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1703,6 +1703,17 @@ in { one place. See https://github.com/glanceapp/glance for more. ''; } + + { + time = "2024-09-01T10:01:13+00:0"; + 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 dbeebfbf7..8c1f03385 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -213,6 +213,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..99f89b700 --- /dev/null +++ b/modules/programs/sesh.nix @@ -0,0 +1,72 @@ +{ pkgs, lib, config, ... }: +with lib; +let + cfg = config.programs.sesh; + tomlFormat = pkgs.formats.toml { }; +in { + meta.maintainers = [ maintainers.michaelvanstraten ]; + + options.programs.sesh = { + enable = mkEnableOption "sesh"; + package = mkPackageOption pkgs "sesh" { }; + settings = mkOption { + type = types.submodule { freeformType = tomlFormat.type; }; + default = { }; + description = '' + Configuration settings for sesh, written to `~/.config/sesh/sesh.toml`. + + For more details, refer to the [sesh configuration documentation](https://github.com/joshmedeski/sesh?tab=readme-ov-file#configuration). + ''; + }; + enableAlias = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable the `s` shell alias for sesh. + ''; + }; + enableTmuxIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Tmux integration for sesh. + ''; + }; + tmuxKey = mkOption { + type = types.str; + default = "s"; + description = '' + The key to bind for the sesh command in tmux. + ''; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + { + # Sesh needs fzf installed by default + home.packages = [ cfg.package pkgs.fzf ]; + home.shellAliases = + mkIf cfg.enableAlias { s = "sesh connect $(sesh list | fzf)"; }; + home.file.".config/sesh/sesh.toml".source = + tomlFormat.generate "sesh.toml" cfg.settings; + } + (mkIf cfg.enableTmuxIntegration { + home.packages = [ pkgs.zoxide ]; + programs.fzf.tmux.enableShellIntegration = true; + 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 1c143716f..bdfd11676 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -139,6 +139,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..58ac7ba71 --- /dev/null +++ b/tests/modules/programs/sesh/basic-configuration.nix @@ -0,0 +1,31 @@ +{ pkgs, ... }: + +{ + config = { + 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; }