#!/bin/bash # Confirm that we want to shutdown without https://git.vlw.se/pastebin/history if [ ! -d "$XDG_DATA_HOME/history" ] ; then read -p "No history directory found at '$XDG_DATA_HOME/history'. Command history will not be saved. Answer 'y' to shutdown anyways: " confirm if [ "$confirm" != "y" ]; then echo "Shutdown aborted" exit fi # Shut down the system sudo poweroff exit fi if [ ! -f "$HOME/.bash_history" ]; then echo "No '.bash_history' file found" exit 1 fi file="$(date +"%Y-%m-%dT%H-%M-%S")-$(hostname).zip" # Move into history directory cd $XDG_DATA_HOME/history # Zip .bash_history file with maximum compression zip -9 $file $HOME/.bash_history # Add the file to git and upload to remote git add $file git -c commit.gpgsign=false commit -m "add($(hostname)): '$file'" git push origin master # Empty the .bash_history file for next session : > $HOME/.bash_history # Shut down the system sudo poweroff