Add gitgutter

This commit is contained in:
Pedro Alves 2021-01-07 16:06:39 +00:00
parent 1b4f79b137
commit a0fe9e6ca4
3 changed files with 149 additions and 16 deletions

View file

@ -43,6 +43,8 @@
enable = true; enable = true;
powerline = true; powerline = true;
}; };
plugins.gitgutter.enable = true;
}; };
}) })
]; ];

View file

@ -107,6 +107,13 @@ in
description = "Extra contents for init.vim"; description = "Extra contents for init.vim";
}; };
extraPackages = mkOption {
type = types.listOf types.package;
default = [];
example = "[ pkgs.shfmt ]";
description = "Extra packages to be made available to neovim";
};
configure = mkOption { configure = mkOption {
type = types.attrsOf types.anything; type = types.attrsOf types.anything;
default = { }; default = { };
@ -176,8 +183,12 @@ in
withRuby = false; withRuby = false;
}; };
extraWrapperArgs = optionalString (cfg.extraPackages != [])
''--prefix PATH : "${makeBinPath cfg.extraPackages}"'';
wrappedNeovim = pkgs.wrapNeovimUnstable cfg.package (neovimConfig // { wrappedNeovim = pkgs.wrapNeovimUnstable cfg.package (neovimConfig // {
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs; wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " "
+ extraWrapperArgs;
}); });
mappings = mappings =

View file

@ -49,10 +49,119 @@ in {
default = false; default = false;
description = "Make the background colors match the sign column"; description = "Make the background colors match the sign column";
}; };
signs = mkOption {
type = let
signOption = desc: mkOption {
type = types.nullOr types.str;
default = null;
description = "Sign for ${desc}";
};
in types.submodule {
options = {
added = signOption "added lines";
modified = signOption "modified lines";
removed = signOption "removed lines";
modifiedAbove = signOption "modified line above";
removedFirstLine = signOption "a removed first line";
removedAboveAndBelow = signOption "lines removed above and below";
modifiedRemoved = signOption "modified and removed lines";
};
};
default = {};
description = "Custom signs for the sign column";
};
diffRelativeToWorkingTree = mkOption {
type = types.bool;
default = false;
description = "Make diffs relative to the working tree instead of the index";
};
extraGitArgs = mkOption {
type = types.str;
default = "";
description = "Extra arguments to pass to git";
};
extraDiffArgs = mkOption {
type = types.str;
default = "";
description = "Extra arguments to pass to git diff";
};
grep = mkOption {
type = types.nullOr (types.oneOf [ types.submodule {
options = {
command = mkOption {
type = types.str;
description = "The command to use as a grep alternative";
};
package = mkOption {
type = types.package;
description = "The package of the grep alternative to use";
};
};
} types.str]);
default = null;
description = "A non-standard grep to use instead of the default";
};
enableByDefault = mkOption {
type = types.bool;
default = true;
description = "Enable gitgutter by default";
};
signsByDefault = mkOption {
type = types.bool;
default = true;
description = "Show signs by default";
};
highlightLines = mkOption {
type = types.bool;
default = true;
description = "Highlight lines by default";
};
highlightLineNumbers = mkOption {
type = types.bool;
default = true;
description = "Highlight line numbers by default";
};
runAsync = mkOption {
type = types.bool;
default = true;
description = "Disable this to run git diff syncrhonously instead of asynchronously";
};
previewWinFloating = mkOption {
type = types.bool;
default = false;
description = "Preview hunks on floating windows";
};
useLocationList = mkOption {
type = types.bool;
default = false;
description = "Load chunks into windows's location list instead of the quickfix list";
};
terminalReportFocus = mkOption {
type = types.bool;
default = true;
description = "Let the terminal report its focus status";
};
}; };
}; };
config = mkIf cfg.enable { config = let
grepPackage = if builtins.isAttrs cfg.grep then [ cfg.grep.package ] else [];
grepCommand = if builtins.isAttrs cfg.grep then cfg.grep.command else cfg.grep;
in mkIf cfg.enable {
programs.nixvim = { programs.nixvim = {
extraPlugins = [ pkgs.vimPlugins.gitgutter ]; extraPlugins = [ pkgs.vimPlugins.gitgutter ];
@ -61,6 +170,8 @@ in {
foldtext = "gitgutter#fold#foldtext"; foldtext = "gitgutter#fold#foldtext";
}; };
extraPackages = [ pkgs.git ] ++ grepPackage;
globals = { globals = {
gitgutter_max_signs = mkIf (!isNull cfg.maxSigns) cfg.maxSigns; gitgutter_max_signs = mkIf (!isNull cfg.maxSigns) cfg.maxSigns;
gitgutter_show_msg_on_hunk_jumping = mkIf (!cfg.showMessageOnHunkJumping) 0; gitgutter_show_msg_on_hunk_jumping = mkIf (!cfg.showMessageOnHunkJumping) 0;
@ -69,20 +180,29 @@ in {
gitgutter_sign_priority = mkIf (!isNull cfg.signPriority) cfg.signPriority; gitgutter_sign_priority = mkIf (!isNull cfg.signPriority) cfg.signPriority;
gitgutter_set_sign_backgrounds = mkIf (cfg.matchBackgrounds) 1; gitgutter_set_sign_backgrounds = mkIf (cfg.matchBackgrounds) 1;
# TODO these config options: gitgutter_sign_added = mkIf (!isNull cfg.signs.added) cfg.signs.added;
# gitgutter_sign_* gitgutter_sign_modified = mkIf (!isNull cfg.signs.modified) cfg.signs.modified;
# gitgutter_diff_relative_to gitgutter_sign_removed = mkIf (!isNull cfg.signs.removed) cfg.signs.removed;
# gitgutter_diff_base gitgutter_sign_removed_first_line = mkIf (!isNull cfg.signs.removedFirstLine) cfg.signs.removedFirstLine;
# gitgutter_git_args gitgutter_sign_removed_above_and_bellow = mkIf (!isNull cfg.signs.removedAboveAndBelow) cfg.signs.removedAboveAndBelow;
# gitgutter_diff_args gitgutter_sign_modified_above = mkIf (!isNull cfg.signs.modifiedAbove) cfg.signs.modifiedAbove;
# gitgutter_grep
# gitgutter_enabled gitgutter_diff_relative_to = mkIf (cfg.diffRelativeToWorkingTree) "working_tree";
# gitgutter_signs gitgutter_git_args = mkIf (cfg.extraGitArgs != "") cfg.extraGitArgs;
# gitgutter_highlight_lines gitgutter_diff_args = mkIf (cfg.extraDiffArgs != "") cfg.extraDiffArgs;
# gitgutter_highlight_linenrs
# gitgutter_async gitgutter_grep = mkIf (!isNull grepCommand) grepCommand;
# gitgutter_preview_win_floating
# gitgutter_use_location_list gitgutter_enabled = mkIf (!cfg.enableByDefault) 0;
gitgutter_signs = mkIf (!cfg.signsByDefault) 0;
gitgutter_highlight_lines = mkIf (!cfg.highlightLines) 0;
gitgutter_highlight_linenrs = mkIf (!cfg.highlightLineNumbers) 0;
gitgutter_async = mkIf (!cfg.runAsync) 0;
gitgutter_preview_win_floating = mkIf (cfg.previewWinFloating) 1;
gitgutter_use_location_list = mkIf (cfg.useLocationList) 1;
gitgutter_terminal_report_focus = mkIf (!cfg.terminalReportFocus) 0;
}; };
}; };
}; };