Skip to content

Instantly share code, notes, and snippets.

@mauriciabad
Last active October 30, 2020 19:40
Show Gist options
  • Save mauriciabad/199dbb0fd786a179eb30135922ca75eb to your computer and use it in GitHub Desktop.
Save mauriciabad/199dbb0fd786a179eb30135922ca75eb to your computer and use it in GitHub Desktop.
Git clone repository here and open with vs code mac macos repo folder automator service
#!/usr/bin/env bash
# Use this to quickly create a git repo in a Mac Finder folder
#
# You need to create an Automator service:
# - Open Automator, choose to create a new Service
# - At the top, select Service receives selected "Folders" in "Finder"
# - From the list at the left, choose Library/Utilities, then drag the
# Run Shell Script action to the workarea
# - Paste the script below into the script area
# - Make sure you set the 'Pass input:' selection to "as arguments"
# - Save the service with an easy to find name, I used "Git Clone Here"
#
# To use:
# - Copy the repo path to your clipboard, like from a Github repo page (https or ssh)
# - Right click on the folder where you want to store the repo
# - Choose Service from the menu, then "Git Clone Here" to clone the repo into the folder
#
# - It will notify you when done if you have the terminal-notifier app installed
# https://github.com/alloy/terminal-notifier
# Once you install terminal-notifier, you should check the location and update the
# NOTIFIERAPP value below appropriately
cd "$@"
REPO=`pbpaste`
REGEX="/([^/]+)\.git$"
NOTIFIERAPP="/usr/local/bin/terminal-notifier"
if [[ "$REPO" =~ $REGEX ]]
then
FOLDER="${BASH_REMATCH[1]}"
git clone $REPO
if [ -e $NOTIFIERAPP ]
then
$NOTIFIERAPP -title "Cloned $FOLDER" -message "Click to open with VS Code" -open vscode://file$@/$FOLDER -appIcon https://cdn3.iconfinder.com/data/icons/social-media-2169/24/social_media_social_media_logo_git-512.png
fi
else
if [ -e $NOTIFIERAPP ]
then
$NOTIFIERAPP -title 'Copied text is not a repo' -message "Clipboard: \"$REPO\"" -sound "Funk" -appIcon https://cdn3.iconfinder.com/data/icons/social-media-2169/24/social_media_social_media_logo_git-512.png
fi
# osascript -e "display notification \"Clipboard: \\\"$REPO\\\"\" with title \"Copied text is not a repo\" sound name \"Funk\""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment