Add support for subcommands in __fish_man_page#3678
Conversation
|
|
||
| # If there are at least two tokens not starting with "-", the second one might be a subcommand. | ||
| # Try "man first-second" and fall back to "man first" if that doesn't work out. | ||
| set -l maincmd (basename $args[1]) |
There was a problem hiding this comment.
This will now print an error when the commandline is empty.
There's a few ways to stop that, I think I prefer a set -q args[1]; or return above.
There was a problem hiding this comment.
You are right.. I didn't test the empty commandline scenario after adding basename.
I'm adding the check and additionally printing \a so that the behavior in case of empty commandline is consistent with other cases (non-existent manpage).
| man (basename (commandline -po; echo)[1]) ^/dev/null | ||
| or printf \a | ||
| # Get all commandline tokens not starting with "-" | ||
| set -l args (string join \n -- (commandline -po) | grep -v '^-') |
There was a problem hiding this comment.
What is the string join supposed to do here?
Also, the grep can be replaced with string match.
So: commandline -po | string match -rv '^-' should work.
There was a problem hiding this comment.
The string join \n was there because grep expects the tokens newline delimited, while commandline -po produces them space-delimited (maybe more precisely - it's that array-separator character).
In any case - your suggestion is simpler - so I'm changing the code to that.
There was a problem hiding this comment.
while commandline -po produces them space-delimited
It doesn't - it delimits with newline. Presumably whatever you tested this with changed the separator. I'd be interested to know what that was, since we don't want to be leaking \x1e (that "array-separator").
There was a problem hiding this comment.
Oh, my mistake.. I tested it with echo (commandline -po) | grep ... and didn't realize it was echo which was creating the spaces.
|
Now that I've addressed the code, on to the general idea. I'm actually suprised how well this rather simple approach works - so far I haven't found a case where it fails (well, it does with I'd be grateful if others could test this so that we don't have any embarrassing failures in obvious situations that I'm too dense to see. |
590ef45 to
fa2d64e
Compare
|
Looks okay to me. A problem with the original and new version of this function is that when I exit the man pager the command line isn't refreshed. Adding |
|
@krader1961 Interesting, I don't have the issue you are describing. After exiting the man pager, the commandline is (visually) in the same state as it was before entering the man pager. Which terminal are you using? I'm using gnome-terminal. |
This commit adds a feature that after typing "git add" and pressing "alt+h", the manpage for "git-add" instead of "git" would be displayed. The new logic takes the first argument which doesn't start with a dash and tries to display manpage for "command-argument"; it falls back to "man command" it the first try doesn't succeed. Fixes fish-shell#3618.
fa2d64e to
b0f0102
Compare
|
Added |
Thanks. The reason you don't need it, and probably most people, is that you're using |
|
Merged as commit f9835b5. Thanks. |
This PR adds a feature that after typing
git addand pressingalt+h, the manpage forgit-addinstead ofgitwould be displayed.The new logic takes the first argument which doesn't start with a dash
and tries to display manpage for
command-argument; it falls back toman commandit the first try doesn't succeed.Fixes #3618.