Skip to content

Commit

Permalink
moved everything to new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Voloboev committed Oct 25, 2017
1 parent cc9310c commit 1d33c3b
Show file tree
Hide file tree
Showing 69 changed files with 21,450 additions and 105 deletions.
33 changes: 33 additions & 0 deletions gitbook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Package gitbook contains helper functions to parse GitBook summaries
package main

import (
"bufio"
"fmt"
"io/ioutil"
"regexp"
"strings"
)

// getAllLinks returns all links and their names from a given markdown file.
func getAllLinks(fileContent string) {
m := make(map[string]string)

// regex to extract link and text attached to link
re := regexp.MustCompile(`\[([^\]]*)\]\(([^)]*)\)`)

scanner := bufio.NewScanner(strings.NewReader(fileContent))
for scanner.Scan() {
matches := re.FindAllStringSubmatch(scanner.Text(), -1)
m[matches[0][1]] = matches[0][2]
}
}

// readFile Reads file.
func readFile(filename string) string {
b, err := ioutil.ReadFile(filename) // just pass the file name
if err != nil {
fmt.Print(err)
}
return string(b)
}
148 changes: 64 additions & 84 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,116 +1,96 @@
package main

import (
// "encoding/json"
"fmt"
"io/ioutil"
"log"
// "os"
"os/exec"

"git.deanishe.net/deanishe/awgo"
"git.deanishe.net/deanishe/awgo/update"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/docopt/docopt-go"
)

// name of the background job that checks for updates
// TODO: don't use docopt

// Name of the background job that checks for updates
const updateJobName = "checkForUpdate"

var (
app *kingpin.Application
var usage = `alfred-my-mind [search|check] [<query>]
Access notes, wiki and more
// app commands
updateMapsCmd, downloadMapsCmd, parseMapsCmd *kingpin.CmdClause
Usage:
alfred-web-searches search [<query>]
alfred-web-searches check
alfred-web-searches -h
mindnodeUrls []string // contains links to JSON of maps
Options:
-h, --help Show this message and exit.
`

query string // script options
repo = "nikitavoloboev/alfred-my-mind"
wf *aw.Workflow
var (
// icons
iconAvailable = &aw.Icon{Value: "icons/update.png"}

repo = "nikitavoloboev/alfred-web-searches"
wf *aw.Workflow
)

func init() {
wf = aw.New(update.GitHub(repo))

// set up kingpin
app = kingpin.New("alfred-my-mind", "search and query my personal interactive maps")
app.HelpFlag.Short('h')
app.Version(wf.Version())

updateMapsCmd = app.Command("update", "updates maps")
downloadMapsCmd = app.Command("download", "downloads maps")
// parseMapsCmd = app.Command("parse", "parses maps")

app.DefaultEnvars()
}

// _actions
func parseMaps(file string) error {
return nil
}

// updateMaps
func updateMaps() error {
wf.NewItem("hello")
wf.SendFeedback()
return nil
}

// parseUrls parses urls from maps.json
func parseUrls(filename string) {
// f, err := os.Open(filename)
// if err != nil {
// log.Fatal(err)
// }
// defer f.Close()

b, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
func run() {
// Pass wf.Args() to docopt because update logic relies on
// AwGo's magic actions.
args, _ := docopt.Parse(usage, wf.Args(), true, wf.Version(), false, true)

// alternate action: get available releases from remote
if args["check"] != false {
wf.TextErrors = true
log.Println("checking for updates...")
if err := wf.CheckForUpdate(); err != nil {
wf.FatalError(err)
}
return
}
fmt.Println(string(b))
}

// downloadMaps parses maps.json and downloads maps specified there to maps directory
func downloadMaps(filename string) error {
parseUrls(filename)

// f, err := os.Open(filename)
// if err != nil {
// panic(err)
// }
// defer f.Close()
// _, err = os.Stat("test.txt")
// if os.IsNotExist(err) { // file does not exist
// log.Fatal(err)
// }

// log.Printf("created file")
return nil
}

func run() {
var query string
if args["<query>"] != nil {
query = args["<query>"].(string)
}

var err error
log.Printf("query=%s", query)

cmd, err := app.Parse(wf.Args())
if err != nil {
wf.FatalError(err)
// call self with "check" command if an update is due and a
// check job isn't already running.
if wf.UpdateCheckDue() && !aw.IsRunning(updateJobName) {
log.Println("running update check in background...")
cmd := exec.Command("./alfred-web-searches", "check")
if err := aw.RunInBackground(updateJobName, cmd); err != nil {
log.Printf("error starting update check: %s", err)
}
}

switch cmd {
case updateMapsCmd.FullCommand():
err = updateMaps()
case downloadMapsCmd.FullCommand():
err = downloadMaps("maps.json")
case parseMapsCmd.FullCommand():
err = parseMaps("maps.json")
default:
err = fmt.Errorf("unknown command : %s", cmd)
if query == "" { // Only show update status if query is empty
// Send update status to Alfred
if wf.UpdateAvailable() {
wf.NewItem("update available!").
Subtitle("↩ to install").
Autocomplete("workflow:update").
Valid(false).
Icon(iconAvailable)
}
}

if err != nil {
wf.FatalError(err)
// _start
wf.NewItem("hello")

if query != "" {
wf.Filter(query)
}

wf.WarnEmpty("No matching items", "Try a different query?")
wf.SendFeedback()
}

func main() {
Expand Down
Binary file added media/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<h1 align="center">Alfred interface to my mind 🎗</h1>

<p align="center"><img src="http://i.imgur.com/4wvJNy6.png" alt="img" width="600"></p>

<h1 align="center"> Description 📕</h1>

You can read why this workflow exists [here](https://nikitavoloboev.gitbooks.io/knowledge/content/meta/my-mind.html).

Essentially you can search through entirety of [my wiki](https://nikitavoloboev.gitbooks.io/knowledge/content/), all of [my mind maps](https://my.mindnode.com/myLVaRLKytoTYBLshxGzzb75MN9cyGHbQBgaVVPp#618.3,-10.4,-1) which include super fast access to various books, courses, blogs, research papers, reddit subreddits, stack exchange sites and more that I use to move and learn things faster.

Since this workflow is geared for my own personal use and productivity and in many ways tries to act as an extension of my brain, it can at times be messy and is always in *work in progress* state.

As this workflow is focused and optimised for fast access to all the knowledge and references I have indexed. It would make sense to read through the wiki I made and maintain [here](https://nikitavoloboev.gitbooks.io/knowledge/content/).

My goals with sharing both this workflow and my wiki knowledge base is to extend my idea of of [knowledge bootstrapping](https://medium.com/@NikitaVoloboev/knowledge-bootstrapping-36c97e0dee19#.udmp9eotg) and tapping into a person's expertise in the most transparent way possible.

<h1 align="center"> Install 💎</h1>

Download the workflow from [GitHub releases](https://github.com/nikitavoloboev/alfred-my-mind/releases/latest).


<h1 align="center"> Contribute 💛</h1>

This workflow heavily leverages curated lists from Learn Anything that can be found [here](https://github.com/learn-anything). You can contribute directly to those lists so everyone benefits.

In the future, I hope to expose certain lists as CSV files that all can contribute and add to similar to [Web Searches workflow](https://github.com/nikitavoloboev/alfred-web-searches).

<h2 align="center"> Small Demo 🚀</h2>

<p align="center"><img src="media/demo.gif" alt="img" width="600"></p>

<h1 align="center"> Thanks 🍀</h1>

You can support what I do on [Patreon](https://www.patreon.com/nikitavoloboev) or look [into other repositories](https://my.mindnode.com/ZKGETDkUaQUsL3q8q9z788CxG84oEHgDiT79GuzX#-143.5,-902.6,0) I shared. Thank you. 💛
Binary file modified workflow/alfred-my-mind
Binary file not shown.
Loading

0 comments on commit 1d33c3b

Please sign in to comment.