lazygit: add shell integrations
This commit is contained in:
parent
af6bb5ea8e
commit
24cad38b3f
1 changed files with 62 additions and 1 deletions
|
|
@ -5,7 +5,7 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkIf;
|
||||
inherit (lib) mkIf types;
|
||||
|
||||
cfg = config.programs.lazygit;
|
||||
|
||||
|
|
@ -49,6 +49,23 @@ in
|
|||
for supported values.
|
||||
'';
|
||||
};
|
||||
|
||||
enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; };
|
||||
|
||||
enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; };
|
||||
|
||||
enableNushellIntegration = lib.hm.shell.mkNushellIntegrationOption { inherit config; };
|
||||
|
||||
enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
||||
|
||||
shellWrapperName = lib.mkOption {
|
||||
type = types.str;
|
||||
default = "lg";
|
||||
example = "lg";
|
||||
description = ''
|
||||
Name of the shell wrapper to be called.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
|
@ -65,5 +82,49 @@ in
|
|||
{
|
||||
source = yamlFormat.generate "lazygit-config" cfg.settings;
|
||||
};
|
||||
|
||||
programs =
|
||||
let
|
||||
bashIntegration = ''
|
||||
${cfg.shellWrapperName}()
|
||||
{
|
||||
export LAZYGIT_NEW_DIR_FILE=~/.lazygit/newdir
|
||||
lazygit "$@"
|
||||
if [ -f $LAZYGIT_NEW_DIR_FILE ]; then
|
||||
cd "$(cat $LAZYGIT_NEW_DIR_FILE)"
|
||||
rm -f $LAZYGIT_NEW_DIR_FILE > /dev/null
|
||||
fi
|
||||
}
|
||||
'';
|
||||
|
||||
fishIntegration = ''
|
||||
set -x LAZYGIT_NEW_DIR_FILE ~/.lazygit/newdir
|
||||
command lazygit $argv
|
||||
if test -f $LAZYGIT_NEW_DIR_FILE
|
||||
cd (cat $LAZYGIT_NEW_DIR_FILE)
|
||||
rm -f $LAZYGIT_NEW_DIR_FILE
|
||||
end
|
||||
'';
|
||||
|
||||
nushellIntegration = ''
|
||||
def --env ${cfg.shellWrapperName} [...args] {
|
||||
$env.LAZYGIT_NEW_DIR_FILE = "~/.lazygit/newdir"
|
||||
lazygit ...$args
|
||||
if ($env.LAZYGIT_NEW_DIR_FILE | path exists) {
|
||||
cd (open $env.LAZYGIT_NEW_DIR_FILE)
|
||||
rm -f $env.LAZYGIT_NEW_DIR_FILE
|
||||
}
|
||||
}
|
||||
'';
|
||||
in
|
||||
{
|
||||
bash.initExtra = mkIf cfg.enableBashIntegration bashIntegration;
|
||||
|
||||
zsh.initContent = mkIf cfg.enableZshIntegration bashIntegration;
|
||||
|
||||
fish.functions.${cfg.shellWrapperName} = mkIf cfg.enableFishIntegration fishIntegration;
|
||||
|
||||
nushell.extraConfig = mkIf cfg.enableNushellIntegration nushellIntegration;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue