How to apply `git --no-pager` for specific commands?

git, zsh

Solution

As this answer points out, you can use `pager.stash false` to turn off pagination for `stash`:

git config --global pager.stash false

More generally, you can use `pager.<command>` with other commands, like `diff`

git config --global pager.<command> false
git config --global pager.diff false

From the official Linux Kernel Git documentation for `git config`:

pager.<cmd>

If the value is boolean, turns on or off pagination of the output of a particular git subcommand when writing to a tty. Otherwise, turns on pagination for the subcommand using the pager specified by the value of `pager.<cmd>`. If `--paginate` or `--no-pager` is specified on the command line, it takes precedence over this option. To disable pagination for all commands, set `core.pager` or `GIT_PAGER` to `cat`.

Problem

I realize that you can do `git --no-pager <command>` to prevent the output from being run through a pager. I also realize you can use, for instance, `git config --global core.pager cat`. However there are some commands where I do want to use the pager automatically, e.g. `diff`, and others where I do not, e.g. `stash`. Typing out `--no-pager` each time is not as efficient as I'd like. Is there any way to set configuration like this for individual commands? As an alternative, is it possible to have `zsh` automatically insert `--no-pager` when calling `stash` without using an alias?

Original source

Related problems