Bash function with arguments as a specific command wrapper

Bash aliases and functions can’t contain (white)space characters. Since Flatpak programs can’t seemingly feasibly ship with man pages I’d prefer the following functionality for a program (as an example):

command executes
man mpv w3m ''

So man mpv would run w3m '' (opens the online documentation in a browser).

I’ve of course used an dashed alias so far, but retaining the past command is much preferred due to muscle memory (I used to source mpv from RPM Fusion).

alias man-mpv='w3m ""'


  1. mpv has apparently been available in the main Fedora repository since release 35; see ↩︎

You want to change the man command, mpv is just the argument.

Either you add those entries yourself (which flatpak should totally do), or yoz write a wrapper for man that looks up custom pages if the manpage is not found.


man() {
#check if man entry exists, dont output error messages
    if man -w "$1" >/dev/null 2>&1; then
        command man "$1"
#otherwise use custom command per entry, put as many elifs here as needed
    elif [[ "$1" == "mpv" ]]; then
        w3m ''
        echo "No manual entry found for $1"

man "$@"

To be fair the best solution would be if flatpak could have a dedicated man entry container that it can use, and man having support for it.


Good solution.

Remarks: case would be useful if there are many entries. Shell function definitions can be collected in a startup script.

1 Like

@boredsquirrel Doesn’t work on my end. I created and ran the script, but man mpv prints the echo error message you’ve added. The native man pages appear to load.

I also tested in a fresh Fedora 39 VM. I may be using the script incorrectly, I’m not familiar with wrapper scripts.

Try to remove the -w from the man command?

I’m playing with this, added as a function to my bashrc
Edit … added comments

flatman () {
#looking to see if a manpage exists where fedora normally keeps them
manfile=$(ls /usr/share/man/*/"${1}".[0-9].gz 2>/dev/null || ls /usr/local/share/man/*/"${1}".[0-9].gz 2>/dev/null)

if [[ ! -z "${manfile}" ]]; then
# if the manfile variable is not null look at the regular man age
    man "${1}"
# if $1 matches the pattern below use that for the man page otherwise
# say there is nothing to display
    case "${1}" in
        w3m "" 2>/dev/null
        echo "Nothing to display"
1 Like

After being added to .bashrc without the -w flag, still prints the “no manual found” message when launching a new shell.

man searches are also now very delayed (F39 Workstation VM, 8 GB of RAM) ­— but sure, technically works; thank you for the effort.

no manual entry found for 

I’ve downloaded the page locally to avoid repeatedly hitting the domain. I recommend everyone doing so:

wget --quiet --output-document=/tmp/mpv-manual.html ''
1 Like

Check the version below.

And yes it makes most sense to have 2 scripts and download the manpages to a directory, then just cat them