Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: branch to show string instead of disabling #1257

Closed
daUnknownCoder opened this issue Jun 9, 2024 · 2 comments
Closed

Feat: branch to show string instead of disabling #1257

daUnknownCoder opened this issue Jun 9, 2024 · 2 comments
Labels
new feature New feature or feature request

Comments

@daUnknownCoder
Copy link

daUnknownCoder commented Jun 9, 2024

Requested feature

if im not in a git repo, the branch is just disabled

i came with this workaround:

        lualine_b = {
          {
            function()
               local is_git = vim.fn.system("git rev-parse --is-inside-work-tree")
               if is_git and vim.v.shell_error == 0 then
                 return vim.fn.system("git branch --show-current | tr -d '\n'")
               end
               return "ungit"
            end,
            icon = icons.git.Branch,
            padding = { left = 2, right = 1 },
          },
        },

which gets me the branch name or ungit but it take too much time to update, like around a few secs after neovim startup which i do not want...

or if the git branch is taking too much time, is there any way to return the component branch from a function?

@daUnknownCoder daUnknownCoder added the new feature New feature or feature request label Jun 9, 2024
@shadmansaleh
Copy link
Member

You can use fmt option to overwrite result of the component based on component output

      {'branch', fmt=function(str) return str ~= '' and str or 'ungit' end},

this should pretty much do what you want.

@daUnknownCoder
Copy link
Author

You can use fmt option to overwrite result of the component based on component output

      {'branch', fmt=function(str) return str ~= '' and str or 'ungit' end},

this should pretty much do what you want.

hi thanks for this, i was racking my brains too hard not to see a simple solution like this, CHEERS! 🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or feature request
Projects
None yet
Development

No branches or pull requests

2 participants