Skip to content

Instantly share code, notes, and snippets.

@agross
Created June 22, 2014 16:58
Show Gist options
  • Save agross/84a6677cd196e56692af to your computer and use it in GitHub Desktop.
Save agross/84a6677cd196e56692af to your computer and use it in GitHub Desktop.
# Write the history entry ourselves, as we empty $BUFFER it won't be written
# by zsh.
zle && [[ $HISTNO -eq $HISTCMD ]] && print -sr -- "$PREBUFFER$BUFFER"
# Save what would have been executed by .accept-line and empty out what zsh
# knows about the command entered.
EXEC=$BUFFER
BUFFER=
zle .accept-line
# Write newline.
echo
# Create a file descriptor that will receive the command output.
exec 9>>/tmp/output.txt
# Write the command that will be executed to the log.
echo $EXEC 1>&9 2>&9
# Write command output to the log.
eval $EXEC 1>/dev/tty 2>/dev/tty 1>&9 2>&9
# Close file descriptor.
exec 9>&-
# Issues:
# - Does not work with interactive programs like vim or git add --patch
# - Due to redirection in line 22 we lose colors for ls and git commands unless
# git config --get color.ui returns always.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment