Add git-prompt-string to your Neovim statusline!
git-prompt-string-lualine.nvim is a lualine.nvim component for git-prompt-string, a shell agnostic git prompt written in Go.
- Neovim v0.9+
- git-prompt-string v1.3+
- lualine.nvim
Using lazy.nvim
{
'mikesmithgh/git-prompt-string-lualine.nvim',
enabled = true,
lazy = true,
}
Using packer.nvim
use({
'mikesmithgh/git-prompt-string-lualine.nvim',
disable = false,
opt = true,
})
Using Neovim's built-in package support pack
mkdir -p "$HOME/.local/share/nvim/site/pack/mikesmithgh/start/"
cd $HOME/.local/share/nvim/site/pack/mikesmithgh/start
git clone [email protected]:mikesmithgh/git-prompt-string-lualine.nvim
mkdir -p "$HOME/.config/nvim"
echo "require('git-prompt-string-lualine')" >> "$HOME/.config/nvim/init.lua"
- Install git-prompt-string following the Installation instructions.
- Install lualine.nvim following the Installation instructions.
To add git-prompt-string in a section of lualine, simply use the component name git_prompt_string
.
Important
Make sure to use underscores in the component name git_prompt_string
. Do not use hyphens git-prompt-string
.
For example, the following replaces the default lualine setup's component branch
with git_prompt_string
.
require('lualine').setup({
sections = {
lualine_b = { 'git_prompt_string', 'diff', 'diagnostics' },
},
})
{
trim_prompt_prefix = true, -- remove whitespace from beginning of prompt prefix
-- git-prompt-string configuration options, see https://github.com/mikesmithgh/git-prompt-string?tab=readme-ov-file#configuration-options
prompt_config = {
prompt_prefix = nil,
prompt_suffix = nil,
ahead_format = nil,
behind_format = nil,
diverged_format = nil,
no_upstream_remote_format = nil,
color_disabled = false,
color_clean = { fg = vim.g.terminal_color_2 or 'DarkGreen' },
color_delta = { fg = vim.g.terminal_color_3 or 'DarkYellow' },
color_dirty = { fg = vim.g.terminal_color_1 or 'DarkRed' },
color_untracked = { fg = vim.g.terminal_color_5 or 'DarkMagenta' },
color_no_upstream = { fg = vim.g.terminal_color_8 or 'DarkGray' },
color_merging = { fg = vim.g.terminal_color_4 or 'DarkBlue' },
},
}
By default, git-prompt-string-lualine.nvim attempts to use the default Neovim terminal colors, if they are defined. Otherwise, a default Neovim color is selected. See the configuration snippet above for more details.
The colors for git-prompt-string-lualine.nvim must be compatible with lualine.nvim. Below is a snippet of instructions from lualine.nvim's README regarding valid color formats.
-- Defines a custom color for the component:
--
-- 'highlight_group_name' | { fg = '#rrggbb'|cterm_value(0-255)|'color_name(red)', bg= '#rrggbb', gui='style' } | function
-- Note:
-- '|' is synonymous with 'or', meaning a different acceptable format for that placeholder.
-- color function has to return one of other color types ('highlight_group_name' | { fg = '#rrggbb'|cterm_value(0-255)|'color_name(red)', bg= '#rrggbb', gui='style' })
-- color functions can be used to have different colors based on state as shown below.
--
-- Examples:
-- color = { fg = '#ffaa88', bg = 'grey', gui='italic,bold' },
-- color = { fg = 204 } -- When fg/bg are omitted, they default to the your theme's fg/bg.
-- color = 'WarningMsg' -- Highlight groups can also be used.
-- color = function(section)
-- return { fg = vim.bo.modified and '#aa3355' or '#33aa88' }
-- end,
The following is an example of how you could modify the configuration options of the git_prompt_string
component.
require('lualine').setup({
sections = {
lualine_b = {
{
'git_prompt_string',
trim_prompt_prefix = false,
prompt_config = {
prompt_prefix = 'git(',
prompt_suffix = ')',
color_clean = { fg = 'LightGreen' },
color_delta = 'WarningMsg',
color_dirty = function()
return 'ErrorMsg'
end,
color_untracked = { fg = '#b16286', bg = 'Black' },
color_no_upstream = { fg = '#c7c7c7' },
color_merging = { fg = 4 },
},
},
},
},
})