zsh: add mkrepo helper

This commit is contained in:
ewin 2025-03-28 07:50:46 -04:00
parent af2c65a03f
commit 26abe6efdb
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc

View file

@ -24,6 +24,24 @@ alias clip='xclip -selection clipboard'
alias copy='clip'
function mkcd { mkdir -p $1 && cd $1 }
function mkcode { mkcd $1 && code $1 }
function mkrepo {
setopt local_options err_return
if [[ "$1" == "https://"* ]]; then
# $1 is a remote URL, strip scheme and .git extension if any
repoPath="$HOME/src/${${1/#https\:\/\/}/%.git}"
repoRemoteURL="$1"
git clone "$repoRemoteURL" "$repoPath"
cd "$repoPath"
else
# $1 is a relative path within ~/src
repoPath="$HOME/src/$1"
repoRemoteURL="https://$1.git"
mkdir -p "$repoPath"
cd "$repoPath"
git init
git remote add origin "$repoRemoteURL"
fi
}
# Alias `code` to `code -r` if we're in the integrated terminal
if [ "$TERM_PROGRAM" = "vscode" ]; then