diff --git a/ForkLift-Favourites-0.1.1.alfredworkflow b/ForkLift-Favourites-0.1.1.alfredworkflow new file mode 100644 index 0000000..ecc6ce3 Binary files /dev/null and b/ForkLift-Favourites-0.1.1.alfredworkflow differ diff --git a/ForkLift-Favourites-0.1.alfredworkflow b/ForkLift-Favourites-0.1.alfredworkflow deleted file mode 100644 index edc6a8c..0000000 Binary files a/ForkLift-Favourites-0.1.alfredworkflow and /dev/null differ diff --git a/build-workflow.sh b/build-workflow.sh index eff3db6..f9a654f 100755 --- a/build-workflow.sh +++ b/build-workflow.sh @@ -19,6 +19,7 @@ log "copying assets to ./build ..." mkdir -vp ./build cp -v icon.png ./build/ +cp -v update-available.png ./build/ cp -v info.plist ./build/ cp -v README.md ./build/ cp -v LICENCE.txt ./build/ diff --git a/forklift.go b/forklift.go index b8b6bad..d55f8fa 100644 --- a/forklift.go +++ b/forklift.go @@ -35,24 +35,31 @@ Filter ForkLift favourites in Alfred 3. Usage: forklift [] forklift --help | --version - forklift --datadir | --cachedir | --distname | --logfile + forklift --distname + forklift --logfile + forklift --update Options: - --datadir Print path to workflow's data directory and exit. - --cachedir Print path to workflow's cache directory and exit. - --logfile Print path to workflow's log file and exit. --distname Print filename of distributable .alfredworkflow file (for the build script). -h, --help Show this message and exit. + --logfile Print path to workflow's log file and exit. + -u, --update Check if an update is available. ` - favesFile = os.ExpandEnv("$HOME/Library/Application Support/ForkLift/Favorites/Favorites.json") -) - -var ( connectionTypes = []string{"Local", "SFTP", "NFS", "Rackspace", "S3", "Search", "FTP", "Sync", "VNC", "WebDAV", "Workspace"} - iconDefault = &aw.Icon{Value: "icon.png", Type: aw.IconTypeImageFile} connectionIcons map[string]*aw.Icon + iconDefault = &aw.Icon{Value: "icon.png", Type: aw.IconTypeImageFile} + iconUpdate = &aw.Icon{Value: "update-available.png", Type: aw.IconTypeImageFile} + favesFile = os.ExpandEnv("$HOME/Library/Application Support/ForkLift/Favorites/Favorites.json") + // workflow configuration + repo = "deanishe/alfred-forklift" + wf *aw.Workflow + // CLI options + query string + doLogfile bool + doDist bool + doUpdate bool ) func init() { @@ -61,6 +68,7 @@ func init() { path := fmt.Sprintf("/Applications/ForkLift.app/Contents/Resources/Connection%s.icns", s) connectionIcons[s] = &aw.Icon{Value: path, Type: aw.IconTypeImageFile} } + wf = aw.NewWorkflow(&aw.Options{GitHub: repo}) } type faves struct { @@ -160,62 +168,101 @@ func loadFavourites(path string) ([]*Favourite, error) { return favourites, nil } -// run starts the workflow -func run() { - var query string - - vstr := fmt.Sprintf("%s/%v (awgo/%v)", aw.Name(), aw.Version(), aw.AwGoVersion) - args, err := docopt.Parse(usage, nil, true, vstr, false) +func parseArgs() error { + vstr := fmt.Sprintf("%s/%v (awgo/%v)", wf.Name(), wf.Version(), aw.AwGoVersion) + args, err := docopt.Parse(usage, wf.Args(), true, vstr, false) if err != nil { - log.Fatalf("error parsing CLI options: %s", err) + return err } log.Printf("args=%+v", args) - // ================ Alternate actions ==================== + if args["--logfile"] == true { + doLogfile = true + } - if args["--datadir"] == true { - fmt.Println(aw.DataDir()) - return + if args["--distname"] == true { + doDist = true } - if args["--cachedir"] == true { - fmt.Println(aw.CacheDir()) - return + if args["--update"] == true { + doUpdate = true } - if args["--logfile"] == true { - fmt.Println(aw.LogFile()) + if args[""] != nil { + query = args[""].(string) + } + return nil +} + +// run starts the workflow +func run() { + // ================ Alternate actions ==================== + + if err := parseArgs(); err != nil { + panic(fmt.Sprintf("error parsing arguments: %s", err)) + } + + if doLogfile == true { + fmt.Println(wf.LogFile()) return } - if args["--distname"] == true { + if doDist == true { name := strings.Replace( - fmt.Sprintf("%s-%s.alfredworkflow", aw.Name(), aw.Version()), + fmt.Sprintf("%s-%s.alfredworkflow", wf.Name(), wf.Version()), " ", "-", -1) fmt.Println(name) return } + if doUpdate == true { + wf.TextErrors = true + log.Printf("checking for update...") + if err := wf.CheckForUpdate(); err != nil { + wf.FatalError(err) + } + return + } + // ================ Script Filter ==================== - if args[""] != nil { - query = fmt.Sprintf("%v", args[""]) - } + var noUID bool log.Printf("query=%s", query) + // Notify updates + if wf.UpdateCheckDue() == true { + log.Printf("update check due") + wf.Var("check_update", "1") + } + + if wf.UpdateAvailable() == true { + log.Printf("update available") + wf.NewItem("An update is available"). + Subtitle("↩ or ⇥ to install update"). + Valid(false). + Autocomplete("workflow:update"). + Icon(iconUpdate) + noUID = true + } + // Load favourites faves, err := loadFavourites(favesFile) if err != nil { panic(fmt.Sprintf("couldn't load favourites: %s", err)) } - log.Printf("%d favourites", len(faves)) + log.Printf("%d favourite(s)", len(faves)) for _, f := range faves { + var uid string + if noUID == false { + uid = f.UUID + } log.Printf("%s (%s)", f.Name, f.Type) - it := aw.NewItem(f.Name). + it := wf.NewItem(f.Name). Subtitle(f.Server). Arg(f.UUID). + UID(uid). SortKey(fmt.Sprintf("%s %s", f.Name, f.Server)). Icon(f.Icon()). Valid(true) @@ -224,16 +271,16 @@ func run() { } if query != "" { - res := aw.Filter(query) - log.Printf("%d favourites match '%s'", len(res), query) + res := wf.Filter(query) + log.Printf("%d favourite(s) match '%s'", len(res), query) } - aw.WarnEmpty("No matching favourites", "Try a different query?") + wf.WarnEmpty("No favourite found", "Try a different query?") - aw.SendFeedback() + wf.SendFeedback() } // main calls run via aw.Run() func main() { - aw.Run(run) + wf.Run(run) } diff --git a/info.plist b/info.plist index 1c471e6..75093ee 100644 --- a/info.plist +++ b/info.plist @@ -6,6 +6,19 @@ net.deanishe.alfred.forklift connections + 24E248A5-4469-4931-8B6B-1C0564F9CDEF + + + destinationuid + 4784A8CD-774A-4916-AC0D-2C32C0F711D8 + modifiers + 0 + modifiersubtext + + vitoclose + + + BC70CD57-DACE-4F66-A7F5-758FBEA3A948 @@ -18,6 +31,16 @@ vitoclose + + destinationuid + 24E248A5-4469-4931-8B6B-1C0564F9CDEF + modifiers + 0 + modifiersubtext + + vitoclose + + createdby @@ -94,6 +117,48 @@ version 1 + + config + + concurrently + + escaping + 102 + script + ./forklift --update + scriptargtype + 1 + scriptfile + + type + 0 + + type + alfred.workflow.action.script + uid + 4784A8CD-774A-4916-AC0D-2C32C0F711D8 + version + 2 + + + config + + inputstring + {var:check_update} + matchcasesensitive + + matchmode + 0 + matchstring + 1 + + type + alfred.workflow.utility.filter + uid + 24E248A5-4469-4931-8B6B-1C0564F9CDEF + version + 1 + readme @@ -101,13 +166,39 @@ 0C7F2339-51B3-4C59-A4E6-D134D8F91FD0 + colorindex + 3 xpos 240 ypos 40 + 24E248A5-4469-4931-8B6B-1C0564F9CDEF + + colorindex + 8 + note + check_update == 1 + xpos + 280 + ypos + 240 + + 4784A8CD-774A-4916-AC0D-2C32C0F711D8 + + colorindex + 8 + note + Check for update + xpos + 410 + ypos + 210 + BC70CD57-DACE-4F66-A7F5-758FBEA3A948 + colorindex + 3 xpos 50 ypos @@ -115,7 +206,7 @@ version - 0.1 + 0.1.1 webaddress diff --git a/update-available.png b/update-available.png new file mode 100644 index 0000000..21e3a15 Binary files /dev/null and b/update-available.png differ