XI62GRUV7UXWLGWBMPSDNMOTPPYPSP4XITW5UPT7PQLKW7V27K4AC
VR6IOKCA2J3I7OZDAD6LE43KBTPFBKII7SIYMWTFPAP2R4MPHTNAC
RXCY7LD6ZRIOIKZEYKLMCYPMQPXF4DOEEFBDLVR2B22BXLZJFFBQC
A3TVGLVHSVLMEHLHB3TPBSD3QGNVGX3DIK6BEBDTTHWBNW4ALMRAC
C4V5BR2KX2KLWSK4IH4CLSEUSJLVK6FDWM7Y43ZKGMI2BFNN3JEQC
TGD23KBV2V7J7FFX7FDBENYMGDIOMS2JNOIZAYNXGQ52E4CQNJYAC
MVGZ575CHTEYOYZJ22DZDSVSYWHW7U3BFUKSQIPDDQYWVASSUQLQC
DWJHLZWVL7RM2WQXN3ZJTJXXKUEUNQLL37TMMTPL7NL375M2QJCQC
6EQI7R3C5QAA3R4J2VMRSJDYAALLVAHSGLATPKCZ7C4YY5MOGWKAC
3CY6DZO4DKCQ2BPIA7R6K4GQ52QKMSLNIWURG5CRC7BBHEGR7V3QC
GIT_3DP_DIR="${GIT_3DP_DIR:-"$HOME/git_repos/3dp"}"
typeset -g -A FORGE_ALIASES
alias_usage="alias_forge <alias> <forge>"
function alias_forge() {
local alias=${1:?the first parameter to alias_forge should be the alias you want to set}
local forge=${2:?the first parameter to alias_forge should be the forge the alias points to}
if (( $# > 2 )); then
printf "%s" "$alias_usage"
else
FORGE_ALIASES[$alias]=$forge
fi
}
alias_forge gh github
alias_forge gl gitlab
GITHUB_USE_SSH=${GIT_USE_SSH:-${GITHUB_USE_SSH:-yes}}
function github_url() {
local git_spec="$package"
if [[ -n "$git_user" ]]; then
git_spec="$git_user/$package"
fi
if [[ "$GITHUB_USE_SSH" == "yes" ]]; then
printf "git@github.com:%s.git" "$git_spec"
else
printf "https://github.com/%s.git" "$git_spec"
fi
}
GITLAB_USE_SSH=${GIT_USE_SSH:-${GITLAB_USE_SSH:-yes}}
function gitlab_url() {
local git_spec="$package"
if [[ -n "$git_user" ]]; then
git_spec="$git_user/$package"
fi
if [[ "$GITLAB_USE_SSH" == "yes" ]]; then
printf "git@gitlab.com:%s.git" "$git_spec"
else
printf "https://gitlab.com/%s.git" "$git_spec"
fi
}
function git-forge-clone() {
if [[ ! -e "$(basename "$package")" ]]; then
git clone "$($1)"
else
echo "package already cloned"
fi
}
function get_forge_function() {
local forge="$1"
local aliased_forge="${forge_aliases[$1]}"
if [[ ! -z "$aliased_forge" ]]; then
forge="$aliased_forge"
fi
echo "${forge}_url"
}
function git-get() {
local git_user
local package
forge=${1?Need a forge spec}
shift
if [[ $# == 1 ]]; then
git_user=
package=$1
elif (( $# == 2 )); then
git_user=$1
package=$2
shift
else
echo 'usage: <forge> <user> <package> or <forge> <package>'
return 2
fi
package=${package%.git}
shift
cd "$GIT_3DP_DIR"
local forge_url_function="${$(get_forge_function "$forge"):?forge not recognized}"
git-forge-clone "$forge_url_function"
cd "$(basename "$package")"
}
if is-function "$POSSIBLE_CMD"; then
$POSSIBLE_CMD "${@[2,-1]}"
possible_cmd="${${$(expand-alias "git-$1")#'}%'}"
printf "%s" "$possible_cmd" | read -A cmdlets
if [[ "$GIT_DEBUG" != "0" ]]; then
echo "git: looking for: \"$possible_cmd\" command: \"${cmdlets[1]}\""
fi
if is-function "${cmdlets[1]}"; then
"${cmdlets[@]}" "${@[2,-1]}"
GIT_3DP_DIR="${GIT_3DP_DIR:-"$HOME/git_repos/3dp"}"
typeset -g -A FORGE_ALIASES
alias_usage="alias_forge <alias> <forge>"
function alias_forge() {
local alias=${1:?the first parameter to alias_forge should be the alias you want to set}
local forge=${2:?the first parameter to alias_forge should be the forge the alias points to}
if (( $# > 2 )); then
printf "%s" "$alias_usage"
else
FORGE_ALIASES[$alias]=$forge
fi
}
alias_forge gh github
alias_forge gl gitlab
GITHUB_USE_SSH=${GIT_USE_SSH:-${GITHUB_USE_SSH:-yes}}
function github_url() {
local git_spec="$package"
if [[ -n "$git_user" ]]; then
git_spec="$git_user/$package"
fi
if [[ "$GITHUB_USE_SSH" == "yes" ]]; then
printf "git@github.com:%s.git" "$git_spec"
else
printf "https://github.com/%s.git" "$git_spec"
fi
}
GITLAB_USE_SSH=${GIT_USE_SSH:-${GITLAB_USE_SSH:-yes}}
function gitlab_url() {
local git_spec="$package"
if [[ -n "$git_user" ]]; then
git_spec="$git_user/$package"
fi
if [[ "$GITLAB_USE_SSH" == "yes" ]]; then
printf "git@gitlab.com:%s.git" "$git_spec"
else
printf "https://gitlab.com/%s.git" "$git_spec"
fi
}
function git-forge-clone() {
if [[ ! -e "$(basename "$package")" ]]; then
git clone "$($1)"
else
echo "package already cloned"
fi
}
function get_forge_function() {
local forge="$1"
local aliased_forge="${forge_aliases[$1]}"
if [[ ! -z "$aliased_forge" ]]; then
forge="$aliased_forge"
fi
echo "${forge}_url"
}
function git-get() {
local git_user
local package
forge=${1?Need a forge spec}
shift
if [[ $# == 1 ]]; then
git_user=
package=$1
elif (( $# == 2 )); then
git_user=$1
package=$2
shift
else
echo 'usage: <forge> <user> <package> or <forge> <package>'
return 2
fi
package=${package%.git}
shift
cd "$GIT_3DP_DIR"
local forge_url_function="${$(get_forge_function "$forge"):?forge not recognized}"
git-forge-clone "$forge_url_function"
cd "$(basename "$package")"
}