Skip to content

Is there a component to display current git repo name? #29

Answered by freddiehaddad
karambaq asked this question in Q&A
Discussion options

You must be logged in to vote
        provider = function()
	  -- Get the repo url
          local repo = vim.fn.system({ "git", "remote", "get-url", "origin" })
	  -- Trim the newline
          repo = repo:gsub("%s+", "")
	  -- Extract the part you want here...
          return repo
        end,

This should get you going.. It will run the command to get the URL and trim the newline.

You'll want to extract the part you want using a regular expression or substring search and use indices.

You're also going to want to add some error handling in case you're in a directory that's not a git repository.

Lastly, this is kind of an expensive function to run on each statusline update. So you might want to incorporate some logic…

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@freddiehaddad
Comment options

@freddiehaddad
Comment options

Comment options

You must be logged in to vote
7 replies
@freddiehaddad
Comment options

@karambaq
Comment options

@freddiehaddad
Comment options

@freddiehaddad
Comment options

Answer selected by freddiehaddad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants