mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
`literalExpression` is intended just to signify code that needs to stay a string that gets represented exactly as-is for docs. It has been misused heavily and people get confused repeatedly on when or not to use it because of the rampant misuse.
133 lines
3.7 KiB
Nix
133 lines
3.7 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
inherit (lib) mkIf types;
|
|
|
|
cfg = config.programs.lazygit;
|
|
|
|
yamlFormat = pkgs.formats.yaml { };
|
|
|
|
configDir =
|
|
if pkgs.stdenv.hostPlatform.isDarwin && !config.xdg.enable then
|
|
"Library/Application Support"
|
|
else
|
|
config.xdg.configHome;
|
|
in
|
|
{
|
|
meta.maintainers = [
|
|
lib.hm.maintainers.kalhauge
|
|
lib.maintainers.khaneliman
|
|
];
|
|
|
|
options.programs.lazygit = {
|
|
enable = lib.mkEnableOption "lazygit, a simple terminal UI for git commands";
|
|
|
|
package = lib.mkPackageOption pkgs "lazygit" { nullable = true; };
|
|
|
|
settings = lib.mkOption {
|
|
inherit (yamlFormat) type;
|
|
default = { };
|
|
defaultText = lib.literalExpression "{ }";
|
|
example = {
|
|
gui.theme = {
|
|
lightTheme = true;
|
|
activeBorderColor = [
|
|
"blue"
|
|
"bold"
|
|
];
|
|
inactiveBorderColor = [ "black" ];
|
|
selectedLineBgColor = [ "default" ];
|
|
};
|
|
};
|
|
description = ''
|
|
Configuration written to
|
|
{file}`$XDG_CONFIG_HOME/lazygit/config.yml`
|
|
on Linux or on Darwin if [](#opt-xdg.enable) is set, otherwise
|
|
{file}`~/Library/Application Support/lazygit/config.yml`.
|
|
See
|
|
<https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md>
|
|
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 {
|
|
home.packages = mkIf (cfg.package != null) [ cfg.package ];
|
|
|
|
home.file."${configDir}/lazygit/config.yml" = {
|
|
enable = cfg.settings != { };
|
|
source = yamlFormat.generate "lazygit-config" cfg.settings;
|
|
};
|
|
|
|
programs =
|
|
let
|
|
lazygitNewDirFilePath =
|
|
if config.home.preferXdgDirectories then
|
|
"${config.xdg.cacheHome}/lazygit/newdir"
|
|
else
|
|
"~/.lazygit/newdir";
|
|
|
|
bashIntegration = ''
|
|
function ${cfg.shellWrapperName}() {
|
|
export LAZYGIT_NEW_DIR_FILE=${lazygitNewDirFilePath}
|
|
command 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 ${lazygitNewDirFilePath}
|
|
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 = "${lazygitNewDirFilePath}" | path expand
|
|
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;
|
|
};
|
|
};
|
|
}
|