henrikruscon / hyper-statusline

Status Line Plugin for Hyper
MIT License
390 stars 79 forks source link

Strips username@ and only removes trailing .git from remote if it exists. #3

Closed s2tephen closed 7 years ago

s2tephen commented 7 years ago

Edits as discussed in #2. Sometimes the remote URL doesn't actually contain ".git" so this approach uses regex to only remove the substring if it exists.

henrikruscon commented 7 years ago

Fair point! Was focusing on speed and assumed it's always present. ✌️

henrikruscon commented 7 years ago

@s2tephen Weird, .replace(/.git$/, '') doesn't actually remove .git for me. Works with .replace(/\.git/, '')

Do you know of any issues not checking if it's end of line?

s2tephen commented 7 years ago

Oh, looks like I forgot to escape the period in .git, but that shouldn't make a difference in removing the .git extension — I'm not sure why the end of line selector isn't working for you.

Not including $ could potentially be a problem if the remote URL contains www.git, e.g. https://www.github.com/user/repo. GitHub doesn't include www. by default but if the remote is added manually, it's accepted. This also doesn't consider other git repository platforms/private repos, which could include .git anywhere in the URL. The $ is essential for isolating file extensions only.

If you can share which remote URLs the regex was breaking on, I can take a look and debug it.

henrikruscon commented 7 years ago

I'm not either. Works fine in Scriptular

However, doesn't work in Hyper for me.

replace

s2tephen commented 7 years ago

See if #8 fixes the problem.