-
-
Notifications
You must be signed in to change notification settings - Fork 59
Add basic logic for opening program manpages #111
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
base: master
Are you sure you want to change the base?
Conversation
|
Maybe instead of a CLI flag it should be a subcommand, so it more closely replicates how man is used without comma, for example: If for some reason a user wants to run |
|
Let me know which is preferred. |
|
We already have -s for the shell, so -m is probably good enough for displaying the man page and I would not special case man subcommand. |
|
|
| debug!("Opening manpage for {command}"); | ||
|
|
||
| let path = get_command_path_from_cache( | ||
| &mut cache, | ||
| &entry, | ||
| use_channel, | ||
| command, | ||
| &args.nixpkgs_flake, | ||
| ); | ||
| let mut path: PathBuf = path.into(); | ||
| // Truncate to | ||
| // /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaa/ | ||
| path.pop(); | ||
| path.pop(); | ||
| // Push to | ||
| // /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaa/share/man/man1 | ||
| // as that is where the program manfiles reside. There are a few | ||
| // that are at `share/man`, but they are just improperly placed | ||
| path.push("share/man/man1"); | ||
| // /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaa/share/man/man1/thing | ||
| path.push(command); | ||
| // /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaa/share/man/man1/thing.1 | ||
| path.set_extension("1"); | ||
| match std::fs::exists(path.as_path()) { | ||
| // Open the manpage | ||
| Ok(true) => { | ||
| let mut cmd = open_manpage(&path); | ||
| // Replace this process with the man program | ||
| let err = cmd.exec(); | ||
| // This code will only run if an error occurs | ||
| eprintln!("{err:?}"); | ||
| return ExitCode::FAILURE; | ||
| } | ||
| // No manpage | ||
| Ok(false) => { | ||
| eprintln!("No manpage for \"{command}\" found."); | ||
| } | ||
| // Some error | ||
| Err(err) => { | ||
| eprintln!("{err:?}"); | ||
| return ExitCode::FAILURE; | ||
| } | ||
| } |
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 works
nix shell "nixpkgs#fish" --command man fish
Idk where in nix that is made to work
nix shell source code https://github.com/NixOS/nix/blob/master/src/nix/env.cc
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.
Hmm, interesting. The nix3 command works, but then something like nix-shell -p fish --run "man fish" does not 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.
But you can run nix-shell -p hello --run "man hello, so it seems to depends on if the man page is in a seperate output or not.
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.
Currently nix-shell -p package --run "man somepage" only works
occasionally and only due to a behavior of GNU's man-db that is not
documented: It tries to guess the man directory corresponding to every
entry in PATH which only works if the packages added to nix-shell have a
bin directory that gets added to PATH and is not supported by other
man page viewers like mandoc.
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.
I'm unsure how it works with separate outputs for nix3 though
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 I think it's because nix3 adds the man output as an output to install or something, because in the logs I saw that it was add the man output to the shell with nix3 in the verbose logs
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.
So, considering that it is an undocumented feature of the default manpager, I'm not convinced we should use that logic.
This adds the
comma -marg, which allows comma to open manpages for you. Example usage:which then opens the ripgrep manpage.
I tested it on my machine and it seems to work fine.