GithubHelp home page GithubHelp logo

mikesmithgh / git-prompt-string-lualine.nvim Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 0.0 44 KB

📍Add git-prompt-string to your Neovim statusline!

License: Apache License 2.0

Lua 94.83% Shell 4.18% Makefile 0.99%
git lua lualine neovim neovim-statusline nvim statusline

git-prompt-string-lualine.nvim's Introduction

📍 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 [email protected]: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 },
        },
      },
    },
  },
})

git-prompt-string-lualine.nvim's People

Contributors

mikesmithgh avatar semantic-release-bot avatar

Stargazers

Egor Tarasov avatar robin avatar gabe avatar Cal avatar  avatar Alexander Golovnya avatar  avatar Bruno Krugel avatar Chaz avatar Scott McKendry avatar Socialhead  avatar  avatar Ján Bočínec avatar Maksim Rozhkov avatar Oliver Tzeng avatar Ross Keenan avatar  avatar Yuta Katayama avatar

Watchers

 avatar  avatar

git-prompt-string-lualine.nvim's Issues

bug: non-english LOCAL causes errors is non-git directories

  • git-prompt.lua
return {
    {
        "mikesmithgh/git-prompt-string-lualine.nvim",
        lazy = true,
    },
    {
        "nvim-lualine/lualine.nvim",
        optional = true,
        opts = function(_, opts)
            return vim.tbl_deep_extend("force", opts, {
                sections = {
                    lualine_b = { "git_prompt_string" },
                },
            })
        end,
    },
}
  • lualine.lua
    {
        "nvim-lualine/lualine.nvim",
        event = "VeryLazy",
        init = function()
            vim.g.lualine_laststatus = vim.o.laststatus
            if vim.fn.argc(-1) > 0 then
                vim.o.statusline = " "
            else
                vim.o.laststatus = 0
            end
        end,
        opts = function()
            local lualine_require = require("lualine_require")
            lualine_require.require = require

            local icons = require("core.icons").icons

            vim.o.laststatus = vim.g.lualine_laststatus

            return {
                options = {
                    theme = "auto",
                    globalstatus = true,
                    disabled_filetypes = { statusline = { "dashboard", "alpha", "starter" } },
                },
                sections = {
                    lualine_a = { "mode" },
                    lualine_b = { "branch" },

                    lualine_c = {
                        GionVim.lualine.root_dir(),
                        {
                            "diagnostics",
                            symbols = {
                                error = icons.diagnostics.Error,
                                warn = icons.diagnostics.Warn,
                                info = icons.diagnostics.Info,
                                hint = icons.diagnostics.Hint,
                            },
                        },
                        { "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } },
                        { GionVim.lualine.pretty_path() },
                    },
                    lualine_x = {
                        {
                            function()
                                return require("noice").api.status.command.get()
                            end,
                            cond = function()
                                return package.loaded["noice"] and require("noice").api.status.command.has()
                            end,
                            color = GionVim.ui.fg("Statement"),
                        },
                        {
                            function()
                                return require("noice").api.status.mode.get()
                            end,
                            cond = function()
                                return package.loaded["noice"] and require("noice").api.status.mode.has()
                            end,
                            color = GionVim.ui.fg("Constant"),
                        },
                        {
                            require("lazy.status").updates,
                            cond = require("lazy.status").has_updates,
                            color = GionVim.ui.fg("Special"),
                        },
                        {
                            "diff",
                            symbols = {
                                added = icons.git.added,
                                modified = icons.git.modified,
                                removed = icons.git.removed,
                            },
                            source = function()
                                local gitsigns = vim.b.gitsigns_status_dict
                                if gitsigns then
                                    return {
                                        added = gitsigns.added,
                                        modified = gitsigns.changed,
                                        removed = gitsigns.removed,
                                    }
                                end
                            end,
                        },
                    },
                    lualine_y = {
                        { "encoding", separator = "|" },
                        { "progress", separator = " ", padding = { left = 1, right = 0 } },
                        { "location", padding = { left = 0, right = 1 } },
                    },
                    lualine_z = {
                        function()
                            return "" .. os.date("%R")
                        end,
                    },
                },
                extensions = { "neo-tree", "lazy" },
            }
        end,
    },
  • An error message appears when opening files in a folder without a '.git' directory
  • message: git-prompt-string-lualine.nvim: ERROR git-prompt-string error(read file HEAD): "open HEAD: no such file or directory".

Got this error on neovim nightly with archBTW

 Error 22時25分00秒 msg_show.lua_error Error executing vim.schedule lua callback: ...share/nvim/lazy/lualine.nvim/lua/lualine/utils/utils.lua:211: lualine: Failed to refresh statusline:
...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:429: Error executing lua: Vim:E475: Invalid value for argument cmd: 'git-prompt-string' is not executable
stack traceback:
[C]: in function 'jobstart'
...ring-lualine.nvim/lua/git-prompt-string-lualine/init.lua:49: in function 'git_prompt_string_json'
...ualine.nvim/lua/lualine/components/git_prompt_string.lua:57: in function 'update_status'
...l/share/nvim/lazy/lualine.nvim/lua/lualine/component.lua:273: in function 'draw'
...are/nvim/lazy/lualine.nvim/lua/lualine/utils/section.lua:26: in function 'draw_section'
...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:170: in function 'statusline'
...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:298: in function <...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:279>
[C]: in function 'nvim_win_call'
...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:429: in function 'refresh'
...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:524: in function <...zeng/.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:523>
[C]: in function 'pcall'
...share/nvim/lazy/lualine.nvim/lua/lualine/utils/utils.lua:214: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
[C]: in function 'error'
...share/nvim/lazy/lualine.nvim/lua/lualine/utils/utils.lua:211: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.