Skip to content

Instantly share code, notes, and snippets.

@maxchang3
Created February 19, 2023 07:10
Show Gist options
  • Save maxchang3/db8eda44d03c070e380a414dc736f48c to your computer and use it in GitHub Desktop.
Save maxchang3/db8eda44d03c070e380a414dc736f48c to your computer and use it in GitHub Desktop.
gitcc (Git Clone Code), a cli simplifies `git clone <repo_url> && code <repo_name>`
#!/bin/bash
SCRIPT_NAME=$(basename "$0")
VERSION="1.0.0"
function usage() {
cat <<EOF
Usage: $SCRIPT_NAME [-d] <repository>
-d Perform a shallow clone with a depth of 1
EOF
}
function version() {
cat <<EOF
$SCRIPT_NAME version $VERSION
EOF
}
if [[ $1 == "--help" || $1 == "-h" ]]; then
usage
exit 0
elif [[ $1 == "--version" || $1 == "-v" ]]; then
version
exit 0
elif [[ -z $1 ]]; then
echo "Error: Repository is not specified."
usage
exit 1
fi
if [[ $1 == "-d" ]]; then
clone_option="--depth 1"
shift
fi
if git clone "$1" $clone_option; then
repo_name=$(basename "$1" .git)
code "$repo_name"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment