Skip to content
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

Closed

Conversation

@radomirbosak
Copy link
Contributor

radomirbosak commented Dec 26, 2016

This PR 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 #3618.


# 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])

This comment has been minimized.

Copy link
@faho

faho Dec 26, 2016

Member

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.

This comment has been minimized.

Copy link
@radomirbosak

radomirbosak Dec 26, 2016

Author Contributor

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 '^-')

This comment has been minimized.

Copy link
@faho

faho Dec 26, 2016

Member

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.

This comment has been minimized.

Copy link
@radomirbosak

radomirbosak Dec 26, 2016

Author Contributor

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.

This comment has been minimized.

Copy link
@faho

faho Dec 26, 2016

Member

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").

This comment has been minimized.

Copy link
@radomirbosak

radomirbosak Dec 26, 2016

Author Contributor

Oh, my mistake.. I tested it with echo (commandline -po) | grep ... and didn't realize it was echo which was creating the spaces.

@faho
Copy link
Member

faho commented Dec 26, 2016

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 ip addr, but that's because the actual subcommand is "address" and "addr" is just a short form - not something that needs to be supported).

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.

@faho faho added the enhancement label Dec 26, 2016
@faho faho added this to the fish 2.5.0 milestone Dec 26, 2016
@radomirbosak radomirbosak force-pushed the radomirbosak:complex-manpages branch from 590ef45 to fa2d64e Dec 26, 2016
@krader1961
Copy link
Contributor

krader1961 commented Dec 26, 2016

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 commandline -f repaint to the bottom of the function fixes it.

@radomirbosak
Copy link
Contributor Author

radomirbosak commented Dec 26, 2016

@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 #3618.
@radomirbosak radomirbosak force-pushed the radomirbosak:complex-manpages branch from fa2d64e to b0f0102 Dec 26, 2016
@radomirbosak
Copy link
Contributor Author

radomirbosak commented Dec 26, 2016

Added commandline -f repaint to the bottom of the function.

@krader1961
Copy link
Contributor

krader1961 commented Dec 27, 2016

Added commandline -f repaint to the bottom of the function.

Thanks. The reason you don't need it, and probably most people, is that you're using less or another pager that switches to the alternate screen by default. I don't like that behavior so I put --no-init in my $LESS env var. Which means less scribbles on the screen containing the prompt for me. I've never bothered to fix this because I've only used [alt]H a couple of times when exploring what various key bindings do.

@faho
faho approved these changes Dec 27, 2016
@krader1961
Copy link
Contributor

krader1961 commented Dec 28, 2016

Merged as commit f9835b5. Thanks.

@krader1961 krader1961 closed this Dec 28, 2016
@faho faho added the release notes label Jan 8, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.