Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save underlow/d3ae12c36817d5fc0755c26eec2b0136 to your computer and use it in GitHub Desktop.
Save underlow/d3ae12c36817d5fc0755c26eec2b0136 to your computer and use it in GitHub Desktop.
Script for alfred workflow to git clone opened github repo in safari tab
set gitUrl to ""
-- set to directory for code
set projectPath to ""
set nameOfActiveApp to (path to frontmost application as text)
-- console command to run ide
set ideName to "idea"
-- split with defined separator (googled)
on theSplit(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to theDelimiter
-- create the array
set theArray to every text item of theString
-- restore the old setting
set AppleScript's text item delimiters to oldDelimiters
-- return the result
return theArray
end theSplit
if "Safari" is in nameOfActiveApp then
tell application "Safari"
set gitUrl to the URL of the current tab of the front window
end tell
else if "Chrome" is in nameOfActiveApp then
tell application "Google Chrome"
set gitUrl to the URL of the active tab of the front window
end tell
else
tell application "Safari"
set gitUrl to the URL of the current tab of the front window
end tell
end if
set gitUrl to "https://github.com/InfoWings/Knowledge-Net"
if (gitUrl starts with "https://github.com") then
set urlArray to my theSplit(gitUrl, "/")
set projectName to last item of urlArray
-- remove last item (???)
set theRest to reverse of rest of reverse of urlArray
set userName to last item of theRest
set projectFullPath to projectPath & projectName
-- http
-- do shell script "git clone " & myURL & ".git " & projectFullPath
-- git
do shell script "git clone git@github.com:" & userName & "/" & projectName & ".git " & projectFullPath
-- open in ide
-- do shell script "export PATH=\"/usr/local/bin:$PATH\"; " & ideName & " " & projectFullPath
end if
#display dialog (splitUrlZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment