2

My Oh-my-zsh does the following:

  1. When I run the git log --pretty --oneline command, it shows me a long list of commits, as expected.

  2. As soon as I hit q, it suddenly disappears with the below output:

    $ git log --pretty --oneline
    FAIL: 141
    

Why is this happening, and how do I fix it?

Kusalananda
  • 333,661
ritratt
  • 131
  • git failed because it was killed by the system when it tried to write to a broken pipe. It's good that you have configuration in place that notifies you when a command you run fails. – Stéphane Chazelas Apr 25 '23 at 15:23

1 Answers1

5

The number after “FAIL” is the process's exit status. A process's exit status, as reported by the shell, is generally¹:

  • 0 if the program exited normally and reported a success.
  • 1 to 125 if the program exited normally and reported an error.
  • 128+s if the program was killed by signal s, where s is a small integer.

141 means signal 13 which is SIGPIPE. Under the hood, the git command sets up a pipe between two subcommands: one subcommand gathers data and writes data to the pipe, and the other subcommand is the pager less. If you don't view the whole output, the pager exits without waiting for the first subcommand to exit. When the first subcommand next tries to write to the pipe, it is killed by SIGPIPE. This is normal behavior, to avoid having commands continue to calculate and write output that nothing is reading.

There's nothing to fix. But if you find this distracting, you can change your theme to not report a failure status when it's SIGPIPE. The way to do that depends on your oh-my-zsh theme, but from what I can see with a quick look (I don't use oh-my-zsh), the ones that have the word FAIL do it by setting the PROMPT variable, using a prompt expansion conditional to only print the FAIL stuff if the command's exit status is nonzero. So you'd need to change that to also take the “no-failure” branch if the exit status is 141. If you're using a theme bundled with oh-my-zsh, look for FAIL in the theme definition ~/.oh-my-zsh/themes/$ZSH_THEME.zsh-theme. Let's take the example of dst.zsh-theme: the definition is

PROMPT='%(?, ,%{$fg[red]%}FAIL%{$reset_color%}
)
%{$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}%m%{$reset_color%}: %{$fg_bold[blue]%}%~%{$reset_color%}$(git_prompt_info)
$(prompt_char) '

(Note that it spans multiple lines.) The general pattern is %(?,IFSUCCESS,IFFAILURE) to print IFSUCCESS on success ($? equals 0) and IFFAILURE on failure (including signals). So we'll add another condition if $? equals 141:

PROMPT='%(141?, ,%(?, ,%{$fg[red]%}FAIL%{$reset_color%}
))
%{$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}%m%{$reset_color%}: %{$fg_bold[blue]%}%~%{$reset_color%}$(git_prompt_info)
$(prompt_char) '

(Note that in addition to prepending %(141?, ,, there's a matching closing parenthesis on the second line.)

¹ The details are off-topic here.

  • Brilliant! thanks for the explanation. It no longer shows me the failure. It does, however, remove the log output when I hit q. Is this a git problem or ZSH problem? thanks – ritratt Apr 25 '23 at 19:55
  • Nevermind, it's a git thing. Found the solution here: https://serebrov.github.io/html/2014-01-04-git-log-and-less-keep-output.html – ritratt Apr 25 '23 at 20:02
  • @ritratt You mean the output of git is hidden when you exit the pager? Neither: it's the pager and to some extent the terminal, and it happens regardless of whether git was interrupted. See https://unix.stackexchange.com/questions/38634/is-there-any-way-to-exit-less-without-clearing-the-screen/38638#38638 – Gilles 'SO- stop being evil' Apr 25 '23 at 20:12