Files
.dotfiles/zsh/gitclone.sh
Jacob Bohanon c03ee8019e Changes returning to solo.io (#1)
1. Add ghostty config
2. Revise the nvim-lsp config to remedy deprecation warnings
3. Add back solo.zsh with enhancements

Reviewed-on: #1
Co-authored-by: Jacob Bohanon <jacobbohanon@gmail.com>
Co-committed-by: Jacob Bohanon <jacobbohanon@gmail.com>
2026-06-01 12:05:40 -04:00

44 lines
941 B
Bash
Executable File

#!/bin/bash
url=$1
# make sure we have a valid git url. only works with http/s
regex='^https?://[^/]+/[^/]+/[^/]+(\.git)?$'
if [[ ! "$url" =~ $regex ]]; then
echo "echo \"$url does not match regex\""
exit 1
fi
# turn our url into a repo path
repo="${url#"http://"}"
repo="${repo#"https://"}"
repo="${repo%".git"}"
# get the location where we will clone this repo
repodir="$HOME/src/${repo}"
# get th directory we will need to be in to call the git clone
dir="${repodir%/*}"
# check for existence of git command
if [[ -z $(which git) ]]; then
echo "echo 'git executable not found'"
exit 1
fi
mkdir -p "$dir"
pushd $dir > /dev/null
# perform the git clone and check output
output="$(git clone $url)"
if [[ $? > 0 ]]; then
popd > /dev/null
(rmdir $repodir && rmdir $dir) || true
echo "echo 'git clone operation failed'"
exit 1
fi
# return our pushd command to the calling shell
echo "pushd ${repodir}"