Skip to content

Directly copy-paste GitHub repo url and clone the repo

Notifications You must be signed in to change notification settings

yxzwayne/zsh-gitclone-widget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

For my macOS users.

Features

  • Direct Git URL Handling: Paste SSH or HTTPS Git URLs directly into the terminal and clone repositories with a single Enter key press.
  • URL Validation: Checks if the Git URL is valid before attempting to clone.

The way I use it is to copy the content in the shell file (or just below) and paste into the .zshrc on my Mac.

Here's the shell content anyway.

function git_url_preprocess_widget() {
    local CMD_LINE="$BUFFER"
    if [[ $CMD_LINE =~ ^[email protected]:.+\/.+\.git$ || $CMD_LINE =~ ^https:\/\/github.com\/.+\/.+\.git$ ]]; then
        echo -e "\033[93m\nEncountered git url, checking validity...\033[0m"
        if git ls-remote "$CMD_LINE" &>/dev/null; then
            BUFFER="git clone $CMD_LINE"
        else
            echo "\nInvalid GitHub repository URL."
            BUFFER=""
        fi
    fi
    zle accept-line
}

zle -N git_url_preprocess_widget
bindkey '^M' git_url_preprocess_widget

I'm sure there are hackier ways to do this, but this sufficed.

About

Directly copy-paste GitHub repo url and clone the repo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages