-
This command will run a script called install-github-cli.sh.
-
The script will install the GitHub command line interface (CLI) onto the user's computer.
-
The CLI will allow the user to interact with the GitHub repository from the command line.
-
The script will download the latest version of the CLI from GitHub and install it on the user's computer.
-
Once the installation is complete, the user will be able to use the CLI to manage their GitHub repositories.
#!/bin/bash
set -Eeuo pipefail
# Create a log file
LOG_FILE="install_gh.log"
touch "$LOG_FILE"
# Function to handle errors
error_handler() {
echo "An error occurred during the installation process. Please check the log file for details." | tee -a "$LOG_FILE"
}
# Register the error handler
trap error_handler ERR
# Check if GitHub CLI (gh) is installed
if ! command -v gh &>/dev/null; then
echo "GitHub CLI not found, installing..." | tee -a "$LOG_FILE"
# Detect operating system
OS=$(uname)
if [ "$OS" == "Darwin" ]; then
# macOS
if ! command -v brew &>/dev/null; then
echo "Homebrew not found, installing..." | tee -a "$LOG_FILE"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | tee -a "$LOG_FILE"
fi
brew install gh | tee -a "$LOG_FILE"
elif [ "$OS" == "MINGW64_NT-10.0" ] || [ "$OS" == "MSYS_NT-10.0" ]; then
# Windows (Git Bash)
if ! command -v choco &>/dev/null; then
echo "Chocolatey not found, installing..." | tee -a "$LOG_FILE"
/bin/bash -c "$(curl -fsSL https://chocolatey.org/install.ps1)" | tee -a "$LOG_FILE"
fi
choco install gh | tee -a "$LOG_FILE"
else
echo "Unsupported operating system. Please install GitHub CLI manually." | tee -a "$LOG_FILE"
exit 1
fi
echo "GitHub CLI installed successfully!" | tee -a "$LOG_FILE"
else
echo "GitHub CLI is already installed." | tee -a "$LOG_FILE"
fi
This command line runs a script to pull all of the repositories from a given GitHub organization.
- The command is running the pull-github-repos-org.sh script.
- This script will pull all the repositories from a GitHub organization and clone them onto the local machine.
- It will first authenticate with the GitHub organization using the credentials provided.
- It will then loop through the list of repositories in the organization and clone each one to the local machine.
- Once the cloning is complete, the script will finish and the repositories will be available on the local machine.
Here's a script that finds all Java repositories in a GitHub organization, clones them using SSH in the current directory, and is compatible with macOS Zsh and Windows Git Bash:
#!/bin/bash
# Set the organization name
ORG_NAME="nats-io"
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if gh and jq are installed
if ! command_exists gh; then
echo "gh command not found. Please install GitHub CLI."
exit 1
elif ! command_exists jq; then
echo "jq command not found. Please install jq."
exit 1
fi
# Create a log file
LOG_FILE="clone_repos.log"
touch "$LOG_FILE"
# Function to handle errors
error_handler() {
echo "An error occurred during the cloning process. Please check the log file for details." | tee -a "$LOG_FILE"
}
# Register the error handler
trap error_handler ERR
# Clone Java repositories in the organization
gh api "orgs/${ORG_NAME}/repos" --paginate | jq -r '.[] | select(.language == "Java") | .ssh_url' | while read -r repo_url; do
echo "Cloning repository: ${repo_url}" | tee -a "$LOG_FILE"
git clone --depth 1 "${repo_url}" | tee -a "$LOG_FILE"
done
echo "Finished cloning Java repositories." | tee -a "$LOG_FILE"
This script checks if gh and jq are installed, sets up a log file, and uses error handling to provide feedback if an issue occurs during the cloning process. It should run on macOS with Zsh and on Windows using Git Bash.
Please ensure that you have the necessary SSH keys set up for your GitHub account before running this script, as it uses SSH for cloning repositories. You might also need to authenticate with GitHub using gh auth login before running this script if you haven't done so already.