lazyworktree: add shell integration
Add shell integration that functions similar to lazygit for navigating to directory of the chosen worktree. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
6da59c400c
commit
f31dbc1042
1 changed files with 46 additions and 0 deletions
|
|
@ -46,12 +46,58 @@ in
|
|||
for supported values.
|
||||
'';
|
||||
};
|
||||
|
||||
enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; };
|
||||
|
||||
enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; };
|
||||
|
||||
enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
||||
|
||||
shellWrapperName = mkOption {
|
||||
type = lib.types.str;
|
||||
default = "lwt";
|
||||
example = "wt";
|
||||
description = ''
|
||||
Name of the shell wrapper that launches lazyworktree and changes to the
|
||||
selected worktree directory on exit.
|
||||
This option only has an effect when at least one shell integration
|
||||
option is enabled.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = mkIf (cfg.package != null) [ cfg.package ];
|
||||
|
||||
xdg.configFile."lazyworktree/config.yaml" = mkIf (cfg.settings != { }) {
|
||||
source = yamlFormat.generate "lazyworktree.yaml" cfg.settings;
|
||||
};
|
||||
|
||||
programs = {
|
||||
bash.initExtra = mkIf cfg.enableBashIntegration ''
|
||||
function ${cfg.shellWrapperName}() {
|
||||
local lazyworktree_dir
|
||||
lazyworktree_dir="$(command lazyworktree "$@")" || return
|
||||
[ -n "$lazyworktree_dir" ] && [ -d "$lazyworktree_dir" ] && cd "$lazyworktree_dir"
|
||||
}
|
||||
'';
|
||||
|
||||
zsh.initContent = mkIf cfg.enableZshIntegration ''
|
||||
function ${cfg.shellWrapperName}() {
|
||||
local lazyworktree_dir
|
||||
lazyworktree_dir="$(command lazyworktree "$@")" || return
|
||||
[ -n "$lazyworktree_dir" ] && [ -d "$lazyworktree_dir" ] && cd "$lazyworktree_dir"
|
||||
}
|
||||
'';
|
||||
|
||||
fish.functions.${cfg.shellWrapperName} = mkIf cfg.enableFishIntegration ''
|
||||
set -l lazyworktree_dir (command lazyworktree $argv)
|
||||
or return
|
||||
|
||||
if test -n "$lazyworktree_dir"; and test -d "$lazyworktree_dir"
|
||||
cd "$lazyworktree_dir"
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue