Skip to content

Instantly share code, notes, and snippets.

@ioggstream
Last active April 21, 2021 08:12
Show Gist options
  • Save ioggstream/dfeda32a29081a45f8fa677a140b6142 to your computer and use it in GitHub Desktop.
Save ioggstream/dfeda32a29081a45f8fa677a140b6142 to your computer and use it in GitHub Desktop.
Github bash aliases for /etc/profile.d
# gh alias
_git_base(){
local repo="$1"
if [[ "$repo" =~ '^https://' || "$repo" =~ 'git@' ]]; then
echo ''
return
fi
if [[ "$repo" =~ 'ioggstream' || "$repo" =~ 'teamdigitale' || "$repo" =~ 'par-tec' ]]; then
echo 'git@github.com:'
else
echo 'https://github.com/'
fi
}
clone(){
local repo="$1"
local gitbase=$(_git_base $repo)
git clone ${gitbase}${repo}.git
}
remote-add(){
local name="$1"
local repo="$2"
local gitbase=$(_git_base $repo)
git remote add $name ${gitbase}${repo}.git
}
git-get(){
# Download a specific directory from a git repo without cloning
# everything.
local repo="$1"
local dirpath="$2"
local gitbase=$(_git_base $repo)
local repodir=$(basename $repo)
local tmpdir_base="$(mktemp -d)"
local tmpdir="${tmpdir_base}/${repodir}"
git clone --no-checkout --filter=tree:0 "${gitbase}${repo}" "${tmpdir}"
(cd "${tmpdir}" && git sparse-checkout set "$dirpath")
cp -rp "${tmpdir}/${dirpath}" .
rm "${tmpdir_base}" -fr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment