scripts and gitignore

This commit is contained in:
Belal Elsabbagh
2025-03-05 10:16:02 +02:00
parent 31bad7d3a4
commit 71032c5dd6
4 changed files with 50 additions and 0 deletions

35
scripts/project.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/zsh
# Check if a directory path is provided
if [ -z "$1" ]; then
echo "Usage: $0 <directory_path>"
exit 1
fi
# Resolve the absolute path and directory name
DIR_PATH=$(realpath "$1")
DIR_NAME=$(basename "$DIR_PATH")
# Check if the directory exists
if [ ! -d "$DIR_PATH" ]; then
echo "Error: Directory '$DIR_PATH' does not exist."
exit 1
fi
# Create or attach to a tmux session named after the directory
SESSION_NAME="$DIR_NAME"
tmux new-session -d -s "$SESSION_NAME" -c "$DIR_PATH"
# Window 1: Open nvim
tmux rename-window -t "$SESSION_NAME:1" "nvim"
tmux send-keys -t "$SESSION_NAME:1" "nvim" C-m
# Window 2: Terminal in the directory
tmux new-window -t "$SESSION_NAME:2" -n "terminal" -c "$DIR_PATH"
# Window 3: Lazygit
tmux new-window -t "$SESSION_NAME:3" -n "lazygit" -c "$DIR_PATH"
tmux send-keys -t "$SESSION_NAME:3" "lazygit" C-m
# Attach to the session
tmux attach-session -t "$SESSION_NAME"

12
scripts/refresh-minecraft.sh Executable file
View File

@@ -0,0 +1,12 @@
#back up
cp -r .minecraft .minecraft-backup
#delete
rm -rf .minecraft
mkdir -p .minecraft
#restore saves
cp -r .minecraft-backup/saves .minecraft/saves
cp -r .minecraft-backup/options.txt .minecraft/options.txt

37
scripts/rollback-pacman.sh Executable file
View File

@@ -0,0 +1,37 @@
# get date YYYY-MM-DD from first arg
date=$1
verbose=$2
# check date not exists or is not valid
if [[ ! $date =~ ^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$ ]]; then
echo "Usage: $0 YYYY-MM-DD"
exit 1
fi
if [ -z "$verbose" ]; then
verbose=false
fi
grep -a upgraded /var/log/pacman.log| grep "$date" > /tmp/lastupdates.txt
if [ "$verbose" = true ]; then
echo "Last updates:"
cat /tmp/lastupdates.txt
fi
awk '{print $4}' /tmp/lastupdates.txt > /tmp/lines1;awk '{print $5}' /tmp/lastupdates.txt | sed 's/(/-/g' > /tmp/lines2
if [ "$verbose" = true ]; then
echo "Lines 1:"
cat /tmp/lines1
echo "Lines 2:"
cat /tmp/lines2
fi
paste /tmp/lines1 /tmp/lines2 > /tmp/lines
if [ "$verbose" = true ]; then
echo "Lines:"
cat /tmp/lines
fi
tr -d "[:blank:]" < /tmp/lines > /tmp/packages
if [ "$verbose" = true ]; then
echo "Packages:"
cat /tmp/packages
fi
cd /var/cache/pacman/pkg/
for i in $(cat /tmp/packages); do sudo pacman --noconfirm -U "$i"*; done