為什麼 zsh 在查詢 (postgresql) 資料庫時表現較差?

為什麼 zsh 在查詢 (postgresql) 資料庫時表現較差?

情境

  • zsh殼,
  • oh-my-zsh框架,
  • 沒什麼特別的zsh配置postgresql

麻煩

我注意到一個惱人的行為:查詢資料庫時,例如:

SELECT * FROM mytable ;

它的行為與less(with (END)) 一樣,返回需要「關閉」less(使用q捷徑),這意味著我在鍵入下一個查詢時無法讀取上一個查詢的結果。

相反,bash這種行為不是嗎:查詢後,顯示結果,並且可以鍵入下一個查詢。

問題

我怎樣才能定制zsh它在這方面的表現bash

答案1

您可以通過評論完全關閉它

cat ~/.oh-my-zsh/lib/misc.zsh
...
#env_default 'PAGER' 'less'                                                        
#env_default 'LESS' '-R'                                                           
...

然後打開一個新終端再試一次;或者..

exec zsh (in the same terminal)

答案2

您的 shell 可能正在設定PAGER環境變數。

嘗試在運行 psql 之前取消設定:

user@host% unset PAGER

您也可以嘗試從 postgresql shell 將分頁器 pset 值設為“off”,如下所示:

user=> \pset pager off

這將會開啟或關閉尋呼機的使用。您也可以將其設定為使用特定尋呼機(如morelesscat等)。

psql 手冊頁中的更多資訊:

pager

    Controls use of a pager for query and psql help output. If the
environment variable PAGER is set, the output is piped to the
specified program. Otherwise a platform-dependent default (such as
more) is used.

    When the pager is off, the pager is not used. When the pager is on,
the pager is used only when appropriate, i.e. the output is to a
terminal and will not fit on the screen. (psql does not do a perfect
job of estimating when to use the pager.) \pset pager turns the pager
on and off. Pager can also be set to always, which causes the pager to
be always used.

相關內容