Intro
Scripts, CLI automation, and custom tools for Linux, WSL2, and other environments
Prepare environment
Create Scripts Directory
- Create
~/bindirectory for user-specific scripts 1 andcdinto it
mkdir -p ~/bin && cd ~/bin- Add
~/bintoPATH(so scripts can be run from anywhere)
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc- Reload shell
source ~/.bashrcMaking Scripts Executable
- Make the script executable
chmod +x example_script.sh- Run the script
example_script.shBash Scripts
Git, GitHub, and SSH Configuration
setup-git-ssh.sh#!/usr/bin/env bash set -euo pipefail # ============================ # Git + GitHub SSH Setup Script # ============================ SSH_KEY="$HOME/.ssh/id_ed25519" REPO_URL="https://github.com/settings/ssh/new" echo "Git configuration" echo "-----------------" # Check existing Git credentials EXISTING_NAME=$(git config --global user.name || true) EXISTING_EMAIL=$(git config --global user.email || true) if [[ -n "$EXISTING_NAME" ]]; then echo "Git user.name already set: $EXISTING_NAME" else read -rp "Enter your Git user name: " GIT_NAME git config --global user.name "$GIT_NAME" fi if [[ -n "$EXISTING_EMAIL" ]]; then echo "Git user.email already set: $EXISTING_EMAIL" else read -rp "Enter your Git email address: " GIT_EMAIL git config --global user.email "$GIT_EMAIL" fi echo "" echo "Verifying Git configuration..." echo "Name : $(git config --get user.name)" echo "Email: $(git config --get user.email)" echo "" echo "Setting up SSH key for GitHub..." # Ensure ~/.ssh exists mkdir -p "$HOME/.ssh" chmod 700 "$HOME/.ssh" if [[ -f "$SSH_KEY" ]]; then echo "Existing SSH key found at $SSH_KEY. Using this key." else read -rp "No SSH key found. Press ENTER to generate a new SSH key..." ssh-keygen -t ed25519 -C "$(git config --get user.email)" -f "$SSH_KEY" -N "" fi # Start ssh-agent and add key if not already loaded eval "$(ssh-agent -s)" >/dev/null ssh-add -l >/dev/null 2>&1 || ssh-add "$SSH_KEY" echo "" echo "Your public SSH key:" echo "-------------------------------------------" cat "${SSH_KEY}.pub" echo "-------------------------------------------" # --- Check if key is already on GitHub --- echo "Checking if SSH key is already registered with GitHub..." SSH_TEST=$(ssh -o BatchMode=yes -T git@github.com 2>&1 || true) if [[ "$SSH_TEST" == *"successfully authenticated"* ]]; then echo "SSH key is already registered with GitHub. No need to add it." else echo "SSH key not yet added to GitHub." # --- Auto-open in browser --- echo "Opening GitHub 'New SSH Key' page in your browser..." if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null; then # WSL → open in Windows browser explorer.exe "$REPO_URL" elif command -v xdg-open &> /dev/null; then # Linux GUI xdg-open "$REPO_URL" elif command -v open &> /dev/null; then # macOS open "$REPO_URL" else echo "Please manually open: $REPO_URL" fi read -rp "Press ENTER once you've added the key to GitHub..." fi echo "" echo "Testing SSH connection to GitHub..." ssh -T git@github.com || true echo "" echo "Setup complete!"
Auto-repo creation
- Install GitHub CLI
sudo apt install gh
gh --version- Authenticate
gh auth login- Create
init-repo.shscript in~/bin
init-repo.sh#!/usr/bin/env bash # usage: ./init-repo.sh <repo-name> [private] REPO_NAME="$1" VISIBILITY="$2" # optional: private or public (default public) if [ -d ".git" ]; then echo "⚠️ This folder is already a Git repository" echo "Please run this script in an empty folder or a new folder." exit 1 fi if [ -z "$REPO_NAME" ]; then echo "Usage: ./init-repo.sh <repo-name> [private]" exit 1 fi # Determine visibility flag if [ "$VISIBILITY" = "private" ]; then VIS_FLAG="--private" else VIS_FLAG="--public" fi # Only create README if it doesn't exist [ -f README.md ] || echo "# $REPO_NAME" > README.md # Initialize git git init git add README.md git commit -m "Initial commit" # Create GitHub repo and push gh repo create "$REPO_NAME" $VIS_FLAG --source=. --remote=origin --push # Get new repo URL REPO_URL=$(gh repo view "$REPO_NAME" --json url --jq .url) echo "Opening repo URL in browser: $REPO_URL" # --- Auto-open in browser --- if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null; then # WSL explorer.exe "$REPO_URL" elif command -v xdg-open &> /dev/null; then # Linux GUI xdg-open "$REPO_URL" elif command -v open &> /dev/null; then # macOS open "$REPO_URL" fi
- Usage: Create a public repo
./init-repo.sh my-project- Create a private repo
./init-repo.sh my-project private



