Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@ stackit config list

You can also edit the configuration file manually.

## Customization

### Pager

To specify a custom pager, use the `PAGER` environment variable.

If the variable is not set, STACKIT CLI uses the `less` as default pager.

When using `less` as a pager, STACKIT CLI will automatically pass following options
- -F, --quit-if-one-screen - Less will automatically exit if the entire file can be displayed on the first screen.
- -S, --chop-long-lines - Lines longer than the screen width will be chopped rather than being folded.
- -w, --hilite-unread - Temporarily highlights the first "new" line after a forward movement of a full page.
- -R, --RAW-CONTROL-CHARS - ANSI color and style sequences will be interpreted.

> These options will not be added automatically if a custom pager is defined.
>
> In that case, users can define the parameters by using the specific environment variable required by the `PAGER` (if supported).

>
> For example, if user sets the `PAGER` environment variable to `less` and would like to pass some arguments, `LESS` environment variable must be used as following:

>
> export PAGER="less"
>
> export LESS="-R"


## Autocompletion

If you wish to set up command autocompletion in your shell for the STACKIT CLI, please refer to our [autocompletion guide](./AUTOCOMPLETION.md).
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/print/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,15 @@ func (p *Printer) PagerDisplay(content string) error {
// -R: interprets ANSI color and style sequences
pagerCmd := exec.Command("less", "-F", "-S", "-w", "-R")

pager, pagerExists := os.LookupEnv("PAGER")
if pagerExists && pager != "nil" && pager != "" {
pagerCmd = exec.Command(pager) // #nosec G204
}

pagerCmd.Stdin = strings.NewReader(content)
pagerCmd.Stdout = p.Cmd.OutOrStdout()

p.Debug(DebugLevel, "using pager: %s", pagerCmd.Args[0])
err := pagerCmd.Run()
if err != nil {
p.Debug(ErrorLevel, "run pager command: %v", err)
Expand Down