From 26abe6efdbbf598528e272dd1eeb92084bb3d76d Mon Sep 17 00:00:00 2001 From: ewin Date: Fri, 28 Mar 2025 07:50:46 -0400 Subject: [PATCH] zsh: add mkrepo helper --- zsh/.config/zsh/config.d/10_aliases.zsh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/zsh/.config/zsh/config.d/10_aliases.zsh b/zsh/.config/zsh/config.d/10_aliases.zsh index 8cb8df1..a769305 100644 --- a/zsh/.config/zsh/config.d/10_aliases.zsh +++ b/zsh/.config/zsh/config.d/10_aliases.zsh @@ -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