How to get `kubectl` to pipe mulitpage output to a pager?

73 Views Asked by At

In git I can use:

git config --global core.pager "less -FX"

This will:

  • When an output is longer (like git log) than a single page a pager (less) is used
  • When output is short, it is not

Is there a configuration like this for kubectl?

1

There are 1 best solutions below

0
tripleee On

You could always wrap it in a function.

kubectl () {
    command kubectl "$@" |
    less --quit-if-one-screen
}

If you are happy with this solution, you can save it to your shell's interactive startup file.

A problem with the pipe to less is that it will mask the exit status of the actual kubectl command. In Bash, you could add return ${PIPESTATUS[0]} to the end of the function, before the closing brace.