Skip to content

Commit 191fabf

Browse files
authored
apply PR wojteklu#11
1 parent 2a96423 commit 191fabf

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

quick-actions/Copy GitHub link to clipboard.workflow/Contents/document.wflow

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<plist version="1.0">
44
<dict>
55
<key>AMApplicationBuild</key>
6-
<string>492</string>
6+
<string>444.42</string>
77
<key>AMApplicationVersion</key>
8-
<string>2.10</string>
8+
<string>2.9</string>
99
<key>AMDocumentVersion</key>
1010
<string>2</string>
1111
<key>actions</key>
@@ -51,7 +51,39 @@
5151
<key>ActionParameters</key>
5252
<dict>
5353
<key>source</key>
54-
<string>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 '" &amp; activeDocumentPath &amp; "'); 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 '" &amp; activeDocumentPath &amp; "'); git rev-parse --show-toplevel " set activeFilePathInRepository to replace_text(activeDocumentPath, pathToRepositoryDirLocation, "") set currentCommit to do shell script "cd $(dirname '" &amp; activeDocumentPath &amp; "'); git rev-parse HEAD" set githubUrl to repositoryUrl &amp; "/blob/" &amp; currentCommit &amp; activeFilePathInRepository &amp; "#L" &amp; startLine &amp; "-L" &amp; endLine set the clipboard to replace_text(githubUrl, " ", "%20") return inputend runon 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_textend replace_text</string>
54+
<string>on run {input, parameters}
55+
tell application "Xcode"
56+
set activeDocument to document 1 whose name ends with (word -1 of (get name of window 1))
57+
set activeDocumentPath to path of activeDocument
58+
set currentLines to selected paragraph range of activeDocument
59+
set startLine to get item 1 of currentLines
60+
set endLine to get item 2 of currentLines
61+
end tell
62+
63+
set repositoryUrl to do shell script "cd \"$(dirname '" &amp; activeDocumentPath &amp; "')\"; git remote -v | grep fetch | awk '{print $2}' | sed 's/ssh:\\/\\/git@/https:\\/\\//' | sed 's/git@/https:\\/\\//' | sed 's/com:/com\\//' | sed 's/\\.git//'"
64+
65+
set pathToRepositoryDirLocation to do shell script "cd \"$(dirname '" &amp; activeDocumentPath &amp; "')\"; git rev-parse --show-toplevel "
66+
67+
set activeFilePathInRepository to replace_text(activeDocumentPath, pathToRepositoryDirLocation, "")
68+
69+
set currentCommit to do shell script "cd \"$(dirname '" &amp; activeDocumentPath &amp; "')\"; git rev-parse HEAD"
70+
71+
set githubUrl to repositoryUrl &amp; "/blob/" &amp; currentCommit &amp; activeFilePathInRepository &amp; "#L" &amp; startLine &amp; "-L" &amp; endLine
72+
73+
set the clipboard to replace_text(githubUrl, " ", "%20")
74+
75+
return input
76+
end run
77+
78+
on replace_text(this_text, search_string, replacement_string)
79+
set prevTIDs to AppleScript's text item delimiters
80+
set AppleScript's text item delimiters to the search_string
81+
set the item_list to every text item of this_text
82+
set AppleScript's text item delimiters to the replacement_string
83+
set this_text to the item_list as string
84+
set AppleScript's text item delimiters to prevTIDs
85+
return this_text
86+
end replace_text</string>
5587
</dict>
5688
<key>BundleIdentifier</key>
5789
<string>com.apple.Automator.RunScript</string>
@@ -105,7 +137,7 @@ end run</string>
105137
<key>isViewVisible</key>
106138
<true/>
107139
<key>location</key>
108-
<string>649.000000:761.000000</string>
140+
<string>541.500000:805.000000</string>
109141
<key>nibPath</key>
110142
<string>/System/Library/Automator/Run AppleScript.action/Contents/Resources/Base.lproj/main.nib</string>
111143
</dict>

0 commit comments

Comments
 (0)