Skip to content

Commit

Permalink
feat: docs-alfred 直接跳转docs url
Browse files Browse the repository at this point in the history
  • Loading branch information
xbpk3t committed Jul 24, 2024
1 parent 165da1e commit 4e5d2d8
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 68 deletions.
146 changes: 90 additions & 56 deletions .workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>18D6F575-4589-45B7-827B-B182C18E240A</string>
<key>modifiers</key>
<integer>131072</integer>
<key>modifiersubtext</key>
<string>打开Docs中该Repo的qs</string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>B53BF6E6-F247-47F7-976E-2AB8E78A683E</string>
<key>modifiers</key>
<integer>262144</integer>
<key>modifiersubtext</key>
<string>打开文档</string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
Expand Down Expand Up @@ -370,6 +390,48 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>skipqueryencode</key>
<false/>
<key>skipvarencode</key>
<false/>
<key>spaces</key>
<string></string>
<key>url</key>
<string></string>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>18D6F575-4589-45B7-827B-B182C18E240A</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>skipqueryencode</key>
<false/>
<key>skipvarencode</key>
<false/>
<key>spaces</key>
<string></string>
<key>url</key>
<string></string>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>B53BF6E6-F247-47F7-976E-2AB8E78A683E</string>
<key>version</key>
<integer>1</integer>
</dict>
</array>
<key>readme</key>
<string></string>
Expand All @@ -378,7 +440,7 @@
<key>04D6D214-AEBC-4782-BC3F-E2EB3AED641C</key>
<dict>
<key>xpos</key>
<real>775</real>
<real>820</real>
<key>ypos</key>
<real>15</real>
</dict>
Expand All @@ -389,6 +451,13 @@
<key>ypos</key>
<real>365</real>
</dict>
<key>18D6F575-4589-45B7-827B-B182C18E240A</key>
<dict>
<key>xpos</key>
<real>730</real>
<key>ypos</key>
<real>720</real>
</dict>
<key>526CF41F-8FC3-49B8-85F8-BDE912B219B5</key>
<dict>
<key>xpos</key>
Expand Down Expand Up @@ -428,6 +497,13 @@
<key>ypos</key>
<real>505</real>
</dict>
<key>B53BF6E6-F247-47F7-976E-2AB8E78A683E</key>
<dict>
<key>xpos</key>
<real>1075</real>
<key>ypos</key>
<real>745</real>
</dict>
<key>E90320D8-B030-405D-A597-184E2218A0BA</key>
<dict>
<key>note</key>
Expand All @@ -440,48 +516,6 @@
</dict>
<key>userconfigurationconfig</key>
<array>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>ff</string>
<key>placeholder</key>
<string></string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Keyword</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>qs</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>fc</string>
<key>placeholder</key>
<string></string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Keyword</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>qs2</string>
</dict>
<dict>
<key>config</key>
<dict>
Expand All @@ -507,7 +541,7 @@
<key>config</key>
<dict>
<key>default</key>
<string>gh</string>
<string>https://docs.hxha.xyz/x/gh/</string>
<key>placeholder</key>
<string></string>
<key>required</key>
Expand All @@ -516,19 +550,19 @@
<true/>
</dict>
<key>description</key>
<string></string>
<string>Docs URL</string>
<key>label</key>
<string></string>
<string>Docs URL</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>gh</string>
<string>docs</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>ch</string>
<string>gh</string>
<key>placeholder</key>
<string></string>
<key>required</key>
Expand All @@ -537,19 +571,19 @@
<true/>
</dict>
<key>description</key>
<string></string>
<string>Custom Key for gh.yml</string>
<key>label</key>
<string></string>
<string>gh.yml</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>ch</string>
<string>gh</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>goods</string>
<string>ch</string>
<key>placeholder</key>
<string></string>
<key>required</key>
Expand All @@ -558,17 +592,17 @@
<true/>
</dict>
<key>description</key>
<string></string>
<string>Custom Key for ws.yml</string>
<key>label</key>
<string></string>
<string>ws.yml</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>goods</string>
<string>ch</string>
</dict>
</array>
<key>version</key>
<string>1.1.0</string>
<string>1.4.0</string>
<key>webaddress</key>
<string>https://github.com/91go/docs-alfred</string>
</dict>
Expand Down
23 changes: 11 additions & 12 deletions cmd/f.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ const (
)

// ghCmd represents the repo command
// Enter 直接打开URL
// CMD + Enter Markdown View
// Ctrl + Enter Copy URL
// Shift + Enter 打开在docs项目对应heading的URL
// Enter 直接打开URL
// CMD + Enter Markdown View
// Option + Enter Copy URL
// Ctrl + Enter 打开文档
// Shift + Enter 打开在docs项目对应heading的URL
var ghCmd = &cobra.Command{
Use: "gh",
Short: "Searching from starred repositories and my repositories",
Expand All @@ -96,19 +97,13 @@ var ghCmd = &cobra.Command{
}

ghs := gh.NewConfigRepos(data).ToRepos()

repos = append(ghs, repos...)

if len(args) > 0 && strings.HasPrefix(args[0], "#") {
tags := repos.ExtractTags()

// if hit tag
ptag := strings.TrimPrefix(args[0], "#")
if slices.Contains(tags, ptag) {
// for _, tagRepo := range {
// name := tagRepo.FullName()
// wf.NewItem(name).Title(name).Valid(false).Autocomplete(name)
// }
repos = repos.QueryReposByTag(ptag)
RenderRepos(repos)
} else {
Expand Down Expand Up @@ -288,8 +283,12 @@ func RenderRepos(repos gh.Repos) (item *aw.Item) {
Valid(true).
Autocomplete(name).Icon(&aw.Icon{Value: iconPath})

item.Cmd().Subtitle(fmt.Sprintf("Open URL: %s", repoURL)).Arg(remark.String())
item.Opt().Subtitle(fmt.Sprintf("Copy URL: %s", repoURL)).Arg(repoURL)
docsURL := fmt.Sprintf("%s#%s", wf.Config.GetString("docs"), strings.ToLower(repo.Tag))

item.Cmd().Subtitle(fmt.Sprintf("Quicklook: %s", repoURL)).Arg(remark.String())
item.Opt().Subtitle(fmt.Sprintf("复制URL: %s", repoURL)).Arg(repoURL)
item.Ctrl().Subtitle(fmt.Sprintf("打开文档: %s", repo.Doc)).Arg(repo.Doc)
item.Shift().Subtitle(fmt.Sprintf("打开该Repo在Docs中gh.md的URL: %s", docsURL)).Arg(docsURL)
}
return item
}
Expand Down

0 comments on commit 4e5d2d8

Please sign in to comment.