Skip to content

Instantly share code, notes, and snippets.

@belenaj
Last active September 9, 2020 09:07
Show Gist options
  • Save belenaj/da0d2974d950b4172312ec1ae42912bf to your computer and use it in GitHub Desktop.
Save belenaj/da0d2974d950b4172312ec1ae42912bf to your computer and use it in GitHub Desktop.
[iterm-backup-history.sh] Utility to easily backup your iTerm command history #bash #iterm
#!/bin/bash
###################################################################
# Script Name : iterm-backup-history.sh
# Description : Utility to easily backup your iTerm command history
# before a meeting, for example
# Args : clean || restore
# Author : belenaj
###################################################################
ACTION=$1
TMP_FILE=~/.zsh_history.tmp
if [[ ("$ACTION" != "clean") && ("$ACTION" != "restore") ]]; then
echo "Invalid argument"
elif [[ ("$ACTION" == "clean") && (! -f "$TMP_FILE") ]]; then
cp -f ~/.zsh_history ~/.zsh_history.bkp
mv -f ~/.zsh_history $TMP_FILE
echo "Sucessfully saved iterm command history"
exec zsh
elif [[ ("$ACTION" == "restore") && (-f "$TMP_FILE") ]]; then
mv -f $TMP_FILE ~/.zsh_history
echo "Successfully restored iterm command history"
exec zsh
else
echo "Not able to clean. Please restore first"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment