diff --git a/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Preview.png b/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Preview.png deleted file mode 100644 index 5671eab..0000000 Binary files a/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Preview.png and /dev/null differ diff --git a/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Thumbnail.png b/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Thumbnail.png index 45fb4b9..f5389e2 100644 Binary files a/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Thumbnail.png and b/quick-actions/Copy GitHub link to clipboard.workflow/Contents/QuickLook/Thumbnail.png differ diff --git a/quick-actions/Copy GitHub link to clipboard.workflow/Contents/document.wflow b/quick-actions/Copy GitHub link to clipboard.workflow/Contents/document.wflow index fa2b963..a83ccbe 100644 --- a/quick-actions/Copy GitHub link to clipboard.workflow/Contents/document.wflow +++ b/quick-actions/Copy GitHub link to clipboard.workflow/Contents/document.wflow @@ -51,7 +51,39 @@ ActionParameters source - on run {input, parameters} tell application "Xcode" set activeDocument to document 1 whose name ends with (word -1 of (get name of window 1)) set activeDocumentPath to path of activeDocument set currentLines to selected paragraph range of activeDocument set startLine to get item 1 of currentLines set endLine to get item 2 of currentLines end tell set repositoryUrl to do shell script "cd $(dirname '" & activeDocumentPath & "'); git remote -v | grep fetch | awk '{print $2}' | sed 's/ssh:\\/\\/git@/https:\\/\\//' | sed 's/git@/https:\\/\\//' | sed 's/com:/com\\//' | sed 's/\\.git//'" set pathToRepositoryDirLocation to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse --show-toplevel " set activeFilePathInRepository to replace_text(activeDocumentPath, pathToRepositoryDirLocation, "") set currentCommit to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse HEAD" set githubUrl to repositoryUrl & "/blob/" & currentCommit & activeFilePathInRepository & "#L" & startLine & "-L" & endLine set the clipboard to replace_text(githubUrl, " ", "%20") return input end run on replace_text(this_text, search_string, replacement_string) set prevTIDs to AppleScript's text item delimiters set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to prevTIDs return this_text end replace_text + on run {input, parameters} + tell application "Xcode" + set activeDocument to document 1 whose name ends with (word -1 of (get name of window 1)) + set activeDocumentPath to path of activeDocument + set currentLines to selected paragraph range of activeDocument + set startLine to get item 1 of currentLines + set endLine to get item 2 of currentLines + end tell + + set repositoryUrl to do shell script "cd $(dirname '" & activeDocumentPath & "'); git remote -v | grep fetch | awk '{print $2}' | sed -E -e 's,git@,https://,' -e 's,:([^/]),/\\1,' -e 's,.git$,,'" + + set pathToRepositoryDirLocation to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse --show-toplevel " + + set activeFilePathInRepository to replace_text(activeDocumentPath, pathToRepositoryDirLocation, "") + + set currentCommit to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse HEAD" + + set githubUrl to repositoryUrl & "/blob/" & currentCommit & activeFilePathInRepository & "#L" & startLine & "-L" & endLine + + set the clipboard to replace_text(githubUrl, " ", "%20") + + return input +end run + +on replace_text(this_text, search_string, replacement_string) + set prevTIDs to AppleScript's text item delimiters + set AppleScript's text item delimiters to the search_string + set the item_list to every text item of this_text + set AppleScript's text item delimiters to the replacement_string + set this_text to the item_list as string + set AppleScript's text item delimiters to prevTIDs + return this_text +end replace_text BundleIdentifier com.apple.Automator.RunScript diff --git a/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Preview.png b/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Preview.png deleted file mode 100644 index ac28b54..0000000 Binary files a/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Preview.png and /dev/null differ diff --git a/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Thumbnail.png b/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Thumbnail.png index 45fb4b9..f5389e2 100644 Binary files a/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Thumbnail.png and b/quick-actions/Open on GitHub.workflow/Contents/QuickLook/Thumbnail.png differ diff --git a/quick-actions/Open on GitHub.workflow/Contents/document.wflow b/quick-actions/Open on GitHub.workflow/Contents/document.wflow index cec64bb..a8cebc0 100644 --- a/quick-actions/Open on GitHub.workflow/Contents/document.wflow +++ b/quick-actions/Open on GitHub.workflow/Contents/document.wflow @@ -51,7 +51,38 @@ ActionParameters source - on run {input, parameters} tell application "Xcode" set activeDocument to document 1 whose name ends with (word -1 of (get name of window 1)) set activeDocumentPath to path of activeDocument set currentLines to selected paragraph range of activeDocument set startLine to get item 1 of currentLines set endLine to get item 2 of currentLines end tell set repositoryUrl to do shell script "cd $(dirname '" & activeDocumentPath & "'); git remote -v | grep fetch | awk '{print $2}' | sed 's/ssh:\\/\\/git@/https:\\/\\//' | sed 's/git@/https:\\/\\//' | sed 's/com:/com\\//' | sed 's/\\.git//'" set pathToRepositoryDirLocation to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse --show-toplevel " set activeFilePathInRepository to replace_text(activeDocumentPath, pathToRepositoryDirLocation, "") set currentCommit to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse HEAD" set githubUrl to repositoryUrl & "/blob/" & currentCommit & activeFilePathInRepository & "#L" & startLine & "-L" & endLine do shell script "open " & replace_text(githubUrl, " ", "%20") return input end run on replace_text(this_text, search_string, replacement_string) set prevTIDs to AppleScript's text item delimiters set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to prevTIDs return this_text end replace_text + on run {input, parameters} + tell application "Xcode" + set activeDocument to document 1 whose name ends with (word -1 of (get name of window 1)) + set activeDocumentPath to path of activeDocument + set currentLines to selected paragraph range of activeDocument + set startLine to get item 1 of currentLines + set endLine to get item 2 of currentLines + end tell + + set repositoryUrl to do shell script "cd $(dirname '" & activeDocumentPath & "'); git remote -v | grep fetch | awk '{print $2}' | sed -E -e 's,git@,https://,' -e 's,:([^/]),/\\1,' -e 's,.git$,,'" + + set pathToRepositoryDirLocation to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse --show-toplevel " + + set activeFilePathInRepository to replace_text(activeDocumentPath, pathToRepositoryDirLocation, "") + + set currentCommit to do shell script "cd $(dirname '" & activeDocumentPath & "'); git rev-parse HEAD" + + set githubUrl to repositoryUrl & "/blob/" & currentCommit & activeFilePathInRepository & "#L" & startLine & "-L" & endLine + + do shell script "open " & replace_text(githubUrl, " ", "%20") + return input +end run + +on replace_text(this_text, search_string, replacement_string) + set prevTIDs to AppleScript's text item delimiters + set AppleScript's text item delimiters to the search_string + set the item_list to every text item of this_text + set AppleScript's text item delimiters to the replacement_string + set this_text to the item_list as string + set AppleScript's text item delimiters to prevTIDs + return this_text +end replace_text BundleIdentifier com.apple.Automator.RunScript