-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
165 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/csv" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// doSearch makes a search for web submissions and returns results to Alfred. | ||
func doSearch() error { | ||
showUpdateStatus() | ||
|
||
log.Printf("query=%s", query) | ||
|
||
links := parseCSV() | ||
|
||
for key, value := range links { | ||
if strings.Contains(key, "r: ") { | ||
wf.NewItem(key).Valid(true).UID(key).Var("URL", value).Var("ARG", key).Icon(redditIcon) | ||
} else if strings.Contains(key, "s: ") { | ||
wf.NewItem(key).Valid(true).UID(key).Var("URL", value).Var("ARG", key).Icon(stackIcon) | ||
} else if strings.Contains(key, "g: ") { | ||
wf.NewItem(key).Valid(true).UID(key).Var("URL", value).Var("ARG", key).Icon(githubIcon) | ||
} else if strings.Contains(key, "f: ") { | ||
wf.NewItem(key).Valid(true).UID(key).Var("URL", value).Var("ARG", key).Icon(forumsIcon) | ||
} else if strings.Contains(key, "d: ") { | ||
wf.NewItem(key).Valid(true).UID(key).Var("URL", value).Var("ARG", key).Icon(docIcon) | ||
} else { | ||
wf.NewItem(key).Valid(true).UID(key).Var("URL", value).Var("ARG", key) | ||
} | ||
} | ||
|
||
if query != "" { | ||
wf.Filter(query) | ||
} | ||
|
||
wf.WarnEmpty("No matching items", "Try a different query?") | ||
wf.SendFeedback() | ||
return nil | ||
} | ||
|
||
// parseCSV parses CSV for links and arguments. | ||
func parseCSV() map[string]string { | ||
var err error | ||
|
||
// Load values from file to a hash map | ||
f, err := os.Open("ask-create-share.csv") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
r := csv.NewReader(f) | ||
|
||
records, err := r.ReadAll() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Holds user's search arguments and an appropriate search URL | ||
links := make(map[string]string) | ||
|
||
for _, record := range records { | ||
links[record[0]] = record[1] | ||
} | ||
|
||
return links | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
aw "github.com/deanishe/awgo" | ||
) | ||
|
||
// doUpdate checks for a newer version of the workflow. | ||
func doUpdate() error { | ||
log.Println("Checking for update...") | ||
return wf.CheckForUpdate() | ||
} | ||
|
||
// checkForUpdate runs "./alsf update" in the background if an update check is due. | ||
func checkForUpdate() error { | ||
if !wf.UpdateCheckDue() || aw.IsRunning("update") { | ||
return nil | ||
} | ||
cmd := exec.Command(os.Args[0], "update") | ||
return aw.RunInBackground("update", cmd) | ||
} | ||
|
||
// showUpdateStatus adds an "update available!" message to Script Filters if an update is available | ||
// and query is empty. | ||
func showUpdateStatus() { | ||
if query != "" { | ||
return | ||
} | ||
|
||
if wf.UpdateAvailable() { | ||
wf.Configure(aw.SuppressUIDs(true)) | ||
log.Println("Update available!") | ||
wf.NewItem("An update is available!"). | ||
Subtitle("⇥ or ↩ to install update"). | ||
Valid(false). | ||
Autocomplete("workflow:update"). | ||
Icon(&aw.Icon{Value: "icons/update-available.png"}) | ||
} | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters