Skip to content

Commit

Permalink
Universal binary
Browse files Browse the repository at this point in the history
- Build universal binary
- Codesigning
- Option to use project file path instead of project directory
- Toggles in config screen for VSCODE and ACTION_PROJECT_PATH
  • Loading branch information
deanishe committed Nov 12, 2021
1 parent 29cf973 commit 6ef9239
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 56 deletions.
8 changes: 0 additions & 8 deletions .autoenv.zsh

This file was deleted.

12 changes: 0 additions & 12 deletions .autoenv_leave.zsh

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/.autoenv*.zsh
# build and dist directories
/build
/dist
Expand Down
Binary file modified Alfred Sublime Text.afdesign
Binary file not shown.
37 changes: 25 additions & 12 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,9 @@ <h2>Usage</h2>
<ul>
<li><code>Workflow Is Up To Date</code> / <code>Workflow Update Available</code> — Install update or check for update</li>
<li><code>Rescan Projects</code> — Reload list of projects</li>
<li><code>Edit Config File</code> — Open workflow&rsquo;s config file in Sublime Text</li>
<li><code>Edit Config File</code> — Open workflow&rsquo;s configuration file</li>
<li><code>Editor: Sublime Text</code> / <code>Editor: VS Code</code> — Which editor is selected</li>
<li><code>Action Project File</code> — Whether copying/actioning a search result should use the path of the project file instead of that of the first project directory</li>
<li><code>View Help File</code> — Open README in your browser</li>
<li><code>Report Issue</code> — Open GitHub issue tracker in your browser</li>
<li><code>Visit Forum Thread</code> — Open workflow&rsquo;s thread on <a href="https://www.alfredforum.com">alfredforum.com</a></li>
Expand Down Expand Up @@ -803,32 +805,43 @@ <h2>Configuration</h2>
<table>
<thead>
<tr>
<th> Variable </th>
<th> Usage </th>
<th> Variable </th>
<th> Type </th>
<th> Usage </th>
</tr>
</thead>
<tbody>
<tr>
<td> <code>INTERVAL_FIND</code> </td>
<td> How long to cache <code>find</code> search results for </td>
<td> <code>INTERVAL_FIND</code> </td>
<td> <code>duration</code> </td>
<td> How long to cache <code>find</code> search results for </td>
</tr>
<tr>
<td> <code>INTERVAL_LOCATE</code> </td>
<td> How long to cache <code>locate</code> search results for </td>
<td> <code>INTERVAL_LOCATE</code> </td>
<td> <code>duration</code> </td>
<td> How long to cache <code>locate</code> search results for </td>
</tr>
<tr>
<td> <code>INTERVAL_MDFIND</code> </td>
<td> How long to cache <code>mdfind</code> search results for </td>
<td> <code>INTERVAL_MDFIND</code> </td>
<td> <code>duration</code> </td>
<td> How long to cache <code>mdfind</code> search results for </td>
</tr>
<tr>
<td> <code>VSCODE</code> </td>
<td> Set to <code>1</code> or <code>true</code> to switch to Visual Studio Code mode </td>
<td> <code>ACTION_PROJECT_FILE</code> </td>
<td> <code>boolean</code> </td>
<td> Copying/actioning a search result uses project file path </td>
</tr>
<tr>
<td> <code>VSCODE</code> </td>
<td> <code>boolean</code> </td>
<td> Switch to Visual Studio Code mode </td>
</tr>
</tbody>
</table>


<p>The interval values should be of the form <code>10m</code> or <code>2h</code>. Set to <code>0</code> to disable a particular scanner.</p>
<p><code>duration</code> values should be of the form <code>10m</code> or <code>2h</code>. Set to <code>0</code> to disable a particular scanner.
<code>boolean</code> values should be of the form <code>true</code> and <code>false</code> or <code>1</code> and <code>0</code>.</p>

<p>The workflow should work &ldquo;out of the box&rdquo;, but if you have project files in directories that <code>mdfind</code> doesn&rsquo;t see (hidden directories, network shares), you may have to explicitly add some search paths to the <code>sublime.toml</code> configuration file in the workflow&rsquo;s data directory. The file is created on first run, and you can use <code>.st config &gt; Workflow Settings &gt; Edit Config File</code> to open it.</p>

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ There is one keyword, `.st`, which works as follows:
- `.st config` — Show the current settings
- `Workflow Is Up To Date` / `Workflow Update Available` — Install update or check for update
- `Rescan Projects` — Reload list of projects
- `Edit Config File` — Open workflow's config file in Sublime Text
- `Edit Config File` — Open workflow's configuration file
- `Editor: Sublime Text` / `Editor: VS Code` — Which editor is selected
- `Action Project File` — Whether copying/actioning a search result should use the path of the project file instead of that of the first project directory
- `View Help File` — Open README in your browser
- `Report Issue` — Open GitHub issue tracker in your browser
- `Visit Forum Thread` — Open workflow's thread on [alfredforum.com][forum]
Expand Down Expand Up @@ -105,14 +107,16 @@ Configuration

Scan intervals are configured in the [workflow's configuration sheet in Alfred Preferences][confsheet]:

| Variable | Usage |
|-------------------|-----------------------------------------------------------|
| `INTERVAL_FIND` | How long to cache `find` search results for |
| `INTERVAL_LOCATE` | How long to cache `locate` search results for |
| `INTERVAL_MDFIND` | How long to cache `mdfind` search results for |
| `VSCODE` | Set to `1` or `true` to switch to Visual Studio Code mode |
| Variable | Type | Usage |
|-----------------------|----------|----------------------------------------------------------|
| `INTERVAL_FIND` | `duration` | How long to cache `find` search results for |
| `INTERVAL_LOCATE` | `duration` | How long to cache `locate` search results for |
| `INTERVAL_MDFIND` | `duration` | How long to cache `mdfind` search results for |
| `ACTION_PROJECT_FILE` | `boolean` | Copying/actioning a search result uses project file path |
| `VSCODE` | `boolean` | Switch to Visual Studio Code mode |

The interval values should be of the form `10m` or `2h`. Set to `0` to disable a particular scanner.
`duration` values should be of the form `10m` or `2h`. Set to `0` to disable a particular scanner.
`boolean` values should be of the form `true` and `false` or `1` and `0`.

The workflow should work "out of the box", but if you have project files in directories that `mdfind` doesn't see (hidden directories, network shares), you may have to explicitly add some search paths to the `sublime.toml` configuration file in the workflow's data directory. The file is created on first run, and you can use `.st config > Workflow Settings > Edit Config File` to open it.

Expand Down
58 changes: 55 additions & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type options struct {
Open bool
OpenFolders bool
Rescan bool
SetConfig string

// Options
Force bool
Expand All @@ -66,6 +67,7 @@ func init() {
cli.BoolVar(&opts.OpenFolders, "folders", false, "open specified project")
cli.BoolVar(&opts.Rescan, "rescan", false, "re-scan for projects")
cli.BoolVar(&opts.Force, "force", false, "force rescan")
cli.StringVar(&opts.SetConfig, "set", "", "set a configuration value")
cli.Usage = func() {
fmt.Fprint(os.Stderr, `usage: alfred-sublime [options] [arguments]
Expand All @@ -79,6 +81,7 @@ Usage:
alfred-sublime -open <path>
alfred-sublime -folders <project file>
alfred-sublime -rescan [-force]
alfred-sublime -set <key> <value>
alfred-sublime -h|-help
Options:
Expand Down Expand Up @@ -228,6 +231,34 @@ func runConfig() {
Icon(iconSettings).
Var("hide_alfred", "true")

v := "true"
editor := "Sublime Text"
other := "VS Code"
icon := iconSublime
if conf.VSCode {
v = "false"
icon = iconVSCode
editor, other = other, editor
}
wf.NewItem("Editor: "+editor).
Subtitle("↩ to switch to "+other).
Valid(true).
Arg("-set", "VSCODE", v).
Icon(icon).
Var("notification", "Using "+other)

v = "true"
icon = iconOff
if conf.ActionProjectFile {
v = "false"
icon = iconOn
}
wf.NewItem("Action Project File").
Subtitle("Action path of project file instead of first project directory").
Valid(true).
Arg("-set", "ACTION_PROJECT_FILE", v).
Icon(icon)

wf.NewItem("View Help File").
Subtitle("Open workflow help in your browser").
Arg("-open", "README.html").
Expand Down Expand Up @@ -296,6 +327,23 @@ func runOpen() {
}
}

// Save a config value and re-open settings view.
func runSetConfig() {
wf.Configure(aw.TextErrors(true))

var (
key = opts.SetConfig
value = opts.Query
)
if err := wf.Config.Set(key, value, false).Do(); err != nil {
wf.Fatalf("set config %q to %q: %v", key, value, err)
}
log.Printf("set %q to %q", key, value)
if err := wf.Alfred.RunTrigger("config", ""); err != nil {
wf.Fatalf("run trigger config: %v", err)
}
}

// Filter Sublime projects in Alfred
func runSearch() {
var (
Expand Down Expand Up @@ -340,15 +388,19 @@ func runSearch() {
}

for _, proj := range projs {
path := proj.Folder()
if conf.ActionProjectFile {
path = proj.Path
}
it := wf.NewItem(proj.Name()).
Subtitle(util.PrettyPath(proj.Path)).
Subtitle(util.PrettyPath(path)).
Valid(true).
// Arg("-project", "--", proj.Path).
Arg(proj.Path).
IsFile(true).
UID(proj.Path).
Copytext(proj.Folder()).
Action(proj.Folder()).
Copytext(path).
Action(path).
Icon(icon).
Var("hide_alfred", "true")

Expand Down
9 changes: 5 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ func init() {

type config struct {
// From workflow environment variables
FindInterval time.Duration `toml:"-"`
MDFindInterval time.Duration `toml:"-"`
LocateInterval time.Duration `toml:"-"`
VSCode bool `toml:"-" env:"VSCODE"`
FindInterval time.Duration `toml:"-"`
MDFindInterval time.Duration `toml:"-"`
LocateInterval time.Duration `toml:"-"`
VSCode bool `toml:"-" env:"VSCODE"`
ActionProjectFile bool `toml:"-" env:"ACTION_PROJECT_FILE"`

// From config file
Excludes []string `toml:"excludes"`
Expand Down
2 changes: 2 additions & 0 deletions icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var (
iconHelp = &aw.Icon{Value: "icons/help.png"}
iconIssue = &aw.Icon{Value: "icons/issue.png"}
iconReload = &aw.Icon{Value: "icons/reload.png"}
iconOn = &aw.Icon{Value: "icons/toggle-on.png"}
iconOff = &aw.Icon{Value: "icons/toggle-off.png"}
iconSettings = &aw.Icon{Value: "icons/settings.png"}
iconSublime = &aw.Icon{Value: "icons/sublime.png"}
iconUpdateAvailable = &aw.Icon{Value: "icons/update-available.png"}
Expand Down
Binary file added icons/toggle-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/toggle-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ variables={allvars}
<key>relatedApps</key>
<array>
<string>com.apple.finder</string>
<string>com.sublimetext.4</string>
<string>com.cocoatech.PathFinder</string>
</array>
<key>relatedAppsMode</key>
Expand Down Expand Up @@ -845,6 +846,8 @@ You can disable a specific scanner by setting its INTERVAL_* setting to 0.
Set VSCODE to 1 (or true) to find VSCode projects instead of Sublime ones.
By default, copying or calling Universal Actions on a search result uses the first project directory. Set ACTION_PROJECT_FILE to 1 (or true) to pass the path of the project file instead.
To add additional directories to scan, use `.stconfig &gt; Edit Config File`.</string>
<key>uidata</key>
<dict>
Expand Down Expand Up @@ -929,7 +932,7 @@ To add additional directories to scan, use `.stconfig &gt; Edit Config File`.</s
<key>56EDA9A1-C8C3-4549-B3C3-6AA5DE031A82</key>
<dict>
<key>xpos</key>
<integer>1070</integer>
<integer>1065</integer>
<key>ypos</key>
<integer>570</integer>
</dict>
Expand Down Expand Up @@ -1027,6 +1030,8 @@ To add additional directories to scan, use `.stconfig &gt; Edit Config File`.</s
</dict>
<key>variables</key>
<dict>
<key>ACTION_PROJECT_FILE</key>
<string>false</string>
<key>INTERVAL_FIND</key>
<string>30m</string>
<key>INTERVAL_LOCATE</key>
Expand All @@ -1036,6 +1041,11 @@ To add additional directories to scan, use `.stconfig &gt; Edit Config File`.</s
<key>VSCODE</key>
<string>false</string>
</dict>
<key>variablesdontexport</key>
<array>
<string>ACTION_PROJECT_FILE</string>
<string>VSCODE</string>
</array>
<key>version</key>
<string>3.3.0</string>
<key>webaddress</key>
Expand Down
38 changes: 34 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ const (
)

var (
info *build.Info
workDir string
info *build.Info
workDir string
archs = []string{"amd64", "arm64"}
codeSignID = os.Getenv("CODESIGN_ID")
)

func init() {
Expand Down Expand Up @@ -57,9 +59,29 @@ func Build() error {
mg.Deps(cleanBuild)
fmt.Println("building ...")

if err := sh.RunWith(info.Env(), "go", "build", "-o", "./build/alfred-sublime", "."); err != nil {
var bins []string
for _, arch := range archs {
env := info.Env()
env["GOOS"] = "darwin"
env["GOARCH"] = arch
bin := fmt.Sprintf("%s/alfred-sublime.%s", buildDir, arch)
bins = append(bins, bin)
if err := sh.RunWith(env, "go", "build", "-o", bin, "."); err != nil {
return err
}
}

// build fat binary
args := []string{"-create", "-output", filepath.Join(buildDir, "alfred-sublime")}
if err := sh.Run("/usr/bin/lipo", append(args, bins...)...); err != nil {
return err
}
// delete arch-specific binaries
for _, bin := range bins {
if err := sh.Rm(bin); err != nil {
return err
}
}

// files to include in workflow
globs := build.Globs(
Expand Down Expand Up @@ -87,9 +109,17 @@ func Run() error {
return sh.RunWith(info.Env(), "./alfred-sublime", "-h")
}

func codeSign() error {
if codeSignID == "" {
fmt.Println("skipping signing: CODESIGN_ID unset")
return nil
}
return sh.Run("codesign", "-f", "-s", codeSignID, "-i", info.BundleID, filepath.Join(buildDir, "alfred-sublime"))
}

// create an .alfredworkflow file in ./dist
func Dist() error {
mg.SerialDeps(Clean, Build)
mg.SerialDeps(Clean, Build, codeSign)
p, err := build.Export(buildDir, distDir)
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func run() {
fileExtension = ".code-workspace"
}

if opts.Config {
if opts.SetConfig != "" {
runSetConfig()
} else if opts.Config {
runConfig()
} else if opts.Rescan {
runScan()
Expand Down
6 changes: 4 additions & 2 deletions modd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ magefile_*.go {

modd.conf
README.*
*.png
**/*.png
*.js
icons/*.png
**/*.go
!mage*.go
!**/*_test.go {
!**/*_test.go
!build/**
!dist/** {
prep +onchange: go test . && mage -v run
}

0 comments on commit 6ef9239

Please sign in to comment.