Skip to content

Conversation

@RossSmyth
Copy link
Contributor

This adds the comma -m arg, which allows comma to open manpages for you. Example usage:

❯ , -m rg

which then opens the ripgrep manpage.

I tested it on my machine and it seems to work fine.

@RossSmyth
Copy link
Contributor Author

RossSmyth commented Oct 30, 2025

Maybe instead of a CLI flag it should be a subcommand, so it more closely replicates how man is used without comma, for example:

> , man rg

If for some reason a user wants to run , man, they can run , -- man and it will run the man program and not the subcommand.

@RossSmyth
Copy link
Contributor Author

Let me know which is preferred.

@SuperSandro2000
Copy link
Member

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.

@rszyma
Copy link

rszyma commented Nov 12, 2025

, man <cmd> is likely what people naturally try and it fails miserably (I did at least!). If we implemented this, it would be a nice UX, since it's so natural.

Comment on lines +375 to +417
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;
}
}
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

NixOS/nix#4642

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants