如何使用 oh-my-zsh 配置 zsh 以在按下“q”后保持 git 历史记录可见?

如何使用 oh-my-zsh 配置 zsh 以在按下“q”后保持 git 历史记录可见?

我每天都会将 zsh 与 oh-my-zsh 一起使用,但有一件小事让我很困扰。如果我使用git log或任何其他类似命令,则输出会占据整个终端窗口。按下后,输出q会被清除,我又回到了我的提示符。

我希望输出保留在屏幕上。我可以配置什么来实现这一点?

一张图片胜过千言万语,下面是当前行为的 gif:

在此处输入图片描述

这是我的.zshrc:

plugins=(
  gitfast docker osx web-search cp
)
ZSH_THEME="powerlevel9k/powerlevel9k"

答案1

查看 core.pager 下配置的内容。您可能less-X设置标志就将其设置为了该状态。设置该标志less后,退出时屏幕不会清空。

如果是这种情况,请转到部分下~/.gitconfig并进行编辑。我已将其设置为。pager[core]-FRSX

$ git config --get core.pager
less -FRSX

为了您的方便,这是less手册页中对每个标志的含义的描述:

   -F or --quit-if-one-screen
          Causes less to automatically exit if the entire file can be displayed on the first screen.

   -R or --RAW-CONTROL-CHARS
          Like -r, but only ANSI "color" escape sequences are output in "raw" form.  Unlike -r, the screen appearance is maintained correctly in most cases.  ANSI "color" escape sequences are sequences of the form:

               ESC [ ... m

          where  the "..." is zero or more color specification characters For the purpose of keeping track of screen appearance, ANSI color escape sequences are assumed to not move the cursor.  You can make less think that characters other than "m" can end ANSI
          color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end a color escape sequence.  And you can make less think that characters other than the standard ones may appear between the ESC and the m
          by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.

   -S or --chop-long-lines
          Causes lines longer than the screen width to be chopped (truncated) rather than wrapped.  That is, the portion of a long line that does not fit in the screen width is not shown.  The default is to wrap long lines; that is, display the remainder on the
          next line.

   -X or --no-init
          Disables sending the termcap initialization and deinitialization strings to the terminal.  This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.

答案2

默认情况下,根据您的~/.gitconfig文件,git 将使用分页器来输出git loggit diff

要禁用此行为,您可以使用以下--no-pager选项:

git --no-pager log

答案3

只需按照以下说明操作即可。

  1. vi ~/.gitconfig只需在终端中输入即可。
  2. 粘贴LESS="-F -X $LESS"線。
  3. 按下:wq并输入。
  4. 重新启动你的终端。

相关内容