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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 add
and pressingalt+h
, the manpage forgit-add
instead ofgit
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 toman command
it the first try doesn't succeed.Fixes #3618.