diff --git a/.local/bin/scripts/shutdown.sh b/.local/bin/scripts/shutdown.sh new file mode 100755 index 0000000..7c65a61 --- /dev/null +++ b/.local/bin/scripts/shutdown.sh @@ -0,0 +1,38 @@ +#!/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'" +gitf u + +# Empty the .bash_history file for next session +: > $HOME/.bash_history + +# Shut down the system +sudo poweroff diff --git a/Makefile b/Makefile index dd38dd1..d049ad3 100644 --- a/Makefile +++ b/Makefile @@ -15,3 +15,6 @@ code-extensions: # Install dev programs and configuration files programs: ~/.local/bin/scripts/install_programs.sh + +shutdown: + ~/.local/bin/scripts/shutdown.sh