Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions scripts/create-github-repo-function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# Shell function to create a new directory, initialize git, and create a GitHub repository
# This function keeps you in the newly created directory after completion
#
# To use this function, add to your .zshrc or .bashrc:
# source ~/dotfiles/scripts/create-github-repo-function.sh
#
# Usage: create-github-repo <repo-name> [description]

create-github-repo() {
# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed"
echo "Install it from: https://cli.github.com/"
return 1
fi

# Check if repo name is provided
if [ -z "$1" ]; then
echo "Usage: create-github-repo <repo-name> [description]"
echo "Example: create-github-repo my-new-project 'A cool new project'"
return 1
fi

local REPO_NAME="$1"
local REPO_DESC="${2:-}"

# Check if directory already exists
if [ -d "$REPO_NAME" ]; then
echo "Error: Directory '$REPO_NAME' already exists"
return 1
fi

echo "Creating new repository: $REPO_NAME"

# Create directory and cd into it
mkdir "$REPO_NAME" || return 1
cd "$REPO_NAME" || return 1

# Initialize git repository
git init -b main || { cd ..; rm -rf "$REPO_NAME"; return 1; }
echo "# $REPO_NAME" > README.md

# Create initial commit
git add README.md
git commit -m "Initial commit" || { cd ..; rm -rf "$REPO_NAME"; return 1; }

# Create GitHub repository (public)
echo "Creating public GitHub repository..."
if [ -n "$REPO_DESC" ]; then
gh repo create "$REPO_NAME" --public --source=. --remote=origin --description "$REPO_DESC" || { cd ..; rm -rf "$REPO_NAME"; return 1; }
else
gh repo create "$REPO_NAME" --public --source=. --remote=origin || { cd ..; rm -rf "$REPO_NAME"; return 1; }
fi

# Push to GitHub (this also sets up tracking)
git push -u origin main || { cd ..; rm -rf "$REPO_NAME"; return 1; }

echo ""
echo "✓ Repository created successfully!"
echo " Local path: $(pwd)"
echo " Remote URL: $(git remote get-url origin)"
echo ""
}
71 changes: 71 additions & 0 deletions scripts/create-github-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

# Script to create a new directory, initialize git, and create a GitHub repository
# Usage: create-github-repo.sh <repo-name> [description]

set -e # Exit on error

# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed"
echo "Install it from: https://cli.github.com/"
exit 1
fi

# Check if repo name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <repo-name> [description]"
echo "Example: $0 my-new-project 'A cool new project'"
exit 1
fi

REPO_NAME="$1"
REPO_DESC="${2:-}"

# Check if directory already exists
if [ -d "$REPO_NAME" ]; then
echo "Error: Directory '$REPO_NAME' already exists"
exit 1
fi

echo "Creating new repository: $REPO_NAME"

# Create directory and cd into it
mkdir "$REPO_NAME"
cd "$REPO_NAME"

# Initialize git repository
# Check git version and use appropriate init syntax
GIT_VERSION=$(git --version | awk '{print $3}')
# Function to compare versions: returns 0 if $1 >= $2
version_ge() {
[ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ]
}
if version_ge "$GIT_VERSION" "2.28.0"; then
git init -b main
else
git init
git branch -m main
fi
echo "# $REPO_NAME" > README.md

# Create initial commit
git add README.md
git commit -m "Initial commit"

# Create GitHub repository (public)
echo "Creating public GitHub repository..."
if [ -n "$REPO_DESC" ]; then
gh repo create "$REPO_NAME" --public --source=. --remote=origin --description "$REPO_DESC"
else
gh repo create "$REPO_NAME" --public --source=. --remote=origin
fi

# Push to GitHub (this also sets up tracking)
git push -u origin main

echo ""
echo "✓ Repository created successfully!"
echo " Local path: $(pwd)"
echo " Remote URL: $(git remote get-url origin)"
echo ""
3 changes: 3 additions & 0 deletions zsh/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,7 @@ alias pylist='pyenv versions'
# Show current Python version
alias pyversion='python --version'

# GitHub repository creation function
[ -f "$HOME/dotfiles/scripts/create-github-repo-function.sh" ] && source "$HOME/dotfiles/scripts/create-github-repo-function.sh"

. "$HOME/.turso/env"