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
Add Mercurial to Git Prompt #2431
Comments
There's really two parts to this:
I've done the former, though somewhat differently from your solution.
This is probably insufficient as I don't believe hg adds a .hg directory in every subdirectory in a repository. It's easy to call
This is much easier with just Now, the latter I need to think about - for one I'd call it "Classic + VCS", because "Classic + Git + Mercurial" is a bit unwieldy and doesn't scale if someone implements e.g. fossil support (we do have someone who cares about completions for that). I also don't like adding every vcs again and again and again in every prompt, so I'd probably add a wrapper function "__fish_vcs_prompt" or so, that checks all vcsen we have functions for and then executes either the first or all matching functions (dunno yet). |
Did you test I think Classic + Git + Mercurial is explicit. |
Urgh... it prints all of them, with no indication which one is current.
That's objectively true. However, my points still stand - it's rather long and would presumably get even longer if more VCSen get a prompt function ("Classic + Git + Mercurial + Svn + Fossil + Darcs"). It also nicely fits with making one function that calls all vcs prompt functions - then the prompt wouldn't gain mercurial support, it would receive support for every vcs we add, automatically. |
Fixed, thanks. Edit:
This might be a good idea regardless, though I'm not sure what the text would be. The only thing that comes to my mind is stuff like "A tasteful prompt for the discerning mind. Short pwd with a hint of username, with a smooth ">" finish".... and that's just ridiculous. |
The other option to get the current bookmark is in the file cat (hg root)/.hg/bookmarks.current But if no bookmark is selected then the file will not exist. |
I've looked into this a bit and after changing But since in the worst case (a directory that's both a git and an hg repository) on my system (i7 with data stored on spinning rust) this all adds up to about 0.3 seconds (best case of no repo being 0.1 seconds), it's probably still worth it for git and hg. For other VCSs we might however want to add Anyone have an opinion on this? |
Branch can be found in cat (hg root)/.hg/branch What do you want to get from |
Ah, I thought it'd be something like that. What I didn't think is that file doesn't exist unless there's more than one branch. Is the default branch name always, well, "default"?
If any files have been added/deleted/modified/copied/untracked/unmerged - basically the first two characters of |
There will always be at least one branch called I'm not sure if the information from |
No - at least not with my mercurial 3.5.1. If I just do
For display - for every one of those things a symbol will be shown, and if at least one of added, modified, copied or deleted is true the branch name will be shown in a special color. |
You're right
Cool! I don't see special symbols or different colours in the prompt when I modify a git repo, is this a new feature? |
It's a feature of the hg prompt (though I do believe the git prompt has similar stuff, it might be locked behind some weird variables - the code for that is.... a bit complicated). (To be clear, when I talk about "$vcs prompt" in this context, I mean the _fish$vcs_prompt function that is supposed to be used by a prompt) |
The I found a blog post describing how to avoid hg calls. It has a pattern for finding the hg root without using So the only hg call would be |
Huh... I tried writing something like that and it looked earily similar - I even used the "find_hg_root" name. The only difference was I used
Yeah, I think I can live with that. |
@Siecje: Please check faho@3ae99e3. I've tested for a bit and it seems to work (and rather quickly at that), but since I don't really use hg I'm bound to miss something. |
I didn't install the latest version of fish. I don't know how. I tried setting it as my prompt though and I don't have So I don't like how the branch and bookmark are separated by a Maybe something like |
I picked the "/" because I was too lazy to mask the "|" while I was fiddling with other solutions. I'll make the switch. (Edit: see faho@1a1eb14)
|
Okay, I've now profiled and optimized this as far as it's gonna go - the remaining 80% of the time (about 8ms on my system) is spent doing one There's a I've changed the display slightly - it's now The issue I have is that, excluding the pipe symbol, this is like the git prompt if no bookmark is present, but I like the separation the parens give. Any suggestions? Put |
I'm not seeing the round brackets. I don't mind that it is the same as the git prompt (remove the
|
Sorry, I forgot to push. Should be there now.
Well, the idea was that I want to call both of them in a Of course we could also just check that in fish_vcs_prompt and then print a "hg: " and "git: " prefix for the respective functions if they produce output or exit non-zero (which would need a redefinition of when they exit non-zero - currently they exit zero if there's no repo). |
I'm in the process of writing a Oh My Fish plugin for abstracting VCS. You may want to give a look here: https://github.com/derekstavis/plugin-vcs Different than other approaches, it works by attaching to I have shamelessly incorporated some lines from your hg optimizations, @faho |
No problem, go ahead.
I took a look and it's a bit more complicated than what I have in mind (which is just a I haven't pushed anything because I haven't quite figured out what the output should look like - presumably all vcs-prompts should be a bit consistent (though they should implement the features the vcs provides), but that also means it's possible that you get a vcs-prompt and then don't know which vcs it's for. My idea was to print "git: " before a git-prompt, though that would make the prompt a bit longer. |
Yeah, it looks pretty complicated at a glance, and I still need to decide out the best approach (events, caching, etc).
I don't like the idea of handling multiple VCS in the same directory, although yes, it can happen and I don't know how to solve the user preferences. In the implementation I opted by testing top-down, in a way that
You can also define, by "API", that the result of |
That doesn't really apply if I want to drop-in "__fish_vcs_prompt" as a replacement for "__fish_git_prompt" in all sample prompts. |
Ah. I see your point. I'm not familiar with builtin prompts code, but as most refactorings, drop-in replacements which adds features are very hard to do, and, well, if you are refactoring, what's the additional effort of changing some lines around? |
So, here's what my current solution looks like with the classic + git prompt (the only change being @Siecje: Does that look okay to you? |
@faho My vote would be to not show If someone does use both in the same folder then they can either learn which one is shown first or create a custom prompt. |
It's not just about having a directory with both (which yes, is rather silly). What happens when you cd into a directory and you can't remember which VCS it is? Or maybe that actually doesn't happen. |
I dream with powerline patched fonts with VCS glyphs 👓 |
You try one command and then the other. |
This has been fixed by merging #2592. Thanks and sorry for the delay! |
As of #1837 the Terlar's fish prompt supports Mercurial.
However it doesn't support Mercurial bookmarks.
The other issue is that you don't know that the Terlar prompt supports Mercurial.
Mercurial support should be added to
Classic + Git
and the named changed toClassic + Git + Mercurial
Here is my personal modification
The text was updated successfully, but these errors were encountered: