mirror of
https://codeberg.org/vlw/dotfiles.git
synced 2026-04-12 23:29:39 +02:00
feat(bash): add shutdown script (save "~/.bash_history" to vlw-pastebin) (#118)
Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/118
This commit is contained in:
parent
d19f7002f7
commit
7cec26678b
2 changed files with 41 additions and 0 deletions
38
.local/bin/scripts/shutdown.sh
Executable file
38
.local/bin/scripts/shutdown.sh
Executable file
|
|
@ -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
|
||||
3
Makefile
3
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue