Skip to content

Instantly share code, notes, and snippets.

View alemagio's full-sized avatar
💭
🧙‍♂️

Alessandro Magionami alemagio

💭
🧙‍♂️
View GitHub Profile
@danydev
danydev / zsh_history.sh
Created May 21, 2020 09:01
Store commands in history only if successful
# README: This allows you to store in your history file only commands
# with a successful status (or forced exited by you with signal 2).
# Put this content in your .zhsrc
# CREDITS: inspired by https://scarff.id.au/blog/2019/zsh-history-conditional-on-command-success/
# This function will be hooked to zshaddhistory.
# zshaddhistory is called before a history line is saved. See zshmisc(1).
function my_zshaddhistory() {
# Prevent the command from being written to history before it's
# executed; save it to LASTHIST instead. Write it to history