Skip to content

mikesmithgh/git-prompt-string-lualine.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

28 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ git-prompt-string-lualine.nvim

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+ semantic-release: angular test status nightly test status

git-prompt-string-lualine

๐Ÿ“š Prerequisites

๐Ÿ“ฆ Installation

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 git@github.com:mikesmithgh/git-prompt-string-lualine.nvim
mkdir -p "$HOME/.config/nvim"
echo "require('git-prompt-string-lualine')" >> "$HOME/.config/nvim/init.lua"

๐Ÿ› ๏ธ Setup

โš™๏ธ Configuration

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' },
  },
})

Configuration Options

{
  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 },
        },
      },
    },
  },
})