diff --git a/.autoenv.zsh b/.autoenv.zsh
deleted file mode 100644
index 9544f64..0000000
--- a/.autoenv.zsh
+++ /dev/null
@@ -1,8 +0,0 @@
-
-test -f alfredenv.sh && {
- source alfredenv.sh
-} || {
- echo ./alfredenv.sh not found >&2
-}
-
-export GO111MODULE=on
diff --git a/.autoenv_leave.zsh b/.autoenv_leave.zsh
deleted file mode 100644
index f479559..0000000
--- a/.autoenv_leave.zsh
+++ /dev/null
@@ -1,12 +0,0 @@
-
-unset alfred_workflow_bundleid
-unset alfred_workflow_version
-unset alfred_workflow_name
-unset alfred_workflow_data
-unset alfred_workflow_cache
-
-unset INTERVAL_FIND
-unset INTERVAL_MDFIND
-unset INTERVAL_LOCATE
-
-unset GO111MODULE
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 1931e4b..fbac57e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-
+/.autoenv*.zsh
# build and dist directories
/build
/dist
diff --git a/Alfred Sublime Text.afdesign b/Alfred Sublime Text.afdesign
index f742458..a2f273b 100644
Binary files a/Alfred Sublime Text.afdesign and b/Alfred Sublime Text.afdesign differ
diff --git a/README.html b/README.html
index 4c82776..0de731f 100644
--- a/README.html
+++ b/README.html
@@ -723,7 +723,9 @@
Usage
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
@@ -803,32 +805,43 @@ Configuration
- Variable |
- Usage |
+ Variable |
+ Type |
+ Usage |
- INTERVAL_FIND |
- How long to cache find search results for |
+ INTERVAL_FIND |
+ duration |
+ How long to cache find search results for |
- INTERVAL_LOCATE |
- How long to cache locate search results for |
+ INTERVAL_LOCATE |
+ duration |
+ How long to cache locate search results for |
- INTERVAL_MDFIND |
- How long to cache mdfind search results for |
+ INTERVAL_MDFIND |
+ duration |
+ How long to cache mdfind search results for |
- VSCODE |
- Set to 1 or true to switch to Visual Studio Code mode |
+ 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.
diff --git a/README.md b/README.md
index c415ecb..46e0e4b 100644
--- a/README.md
+++ b/README.md
@@ -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]
@@ -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.
diff --git a/cli.go b/cli.go
index 0bae9c3..ff5d861 100644
--- a/cli.go
+++ b/cli.go
@@ -51,6 +51,7 @@ type options struct {
Open bool
OpenFolders bool
Rescan bool
+ SetConfig string
// Options
Force bool
@@ -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]
@@ -79,6 +81,7 @@ Usage:
alfred-sublime -open
alfred-sublime -folders
alfred-sublime -rescan [-force]
+ alfred-sublime -set
alfred-sublime -h|-help
Options:
@@ -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").
@@ -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 (
@@ -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")
diff --git a/config.go b/config.go
index 240991c..868498a 100644
--- a/config.go
+++ b/config.go
@@ -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"`
diff --git a/icons.go b/icons.go
index 8709213..dd78913 100644
--- a/icons.go
+++ b/icons.go
@@ -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"}
diff --git a/icons/toggle-off.png b/icons/toggle-off.png
new file mode 100644
index 0000000..1b494e3
Binary files /dev/null and b/icons/toggle-off.png differ
diff --git a/icons/toggle-on.png b/icons/toggle-on.png
new file mode 100644
index 0000000..d2bb0e8
Binary files /dev/null and b/icons/toggle-on.png differ
diff --git a/info.plist b/info.plist
index f17ca16..de2decb 100644
--- a/info.plist
+++ b/info.plist
@@ -803,6 +803,7 @@ variables={allvars}
relatedApps
com.apple.finder
+ com.sublimetext.4
com.cocoatech.PathFinder
relatedAppsMode
@@ -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 > Edit Config File`.
uidata
@@ -929,7 +932,7 @@ To add additional directories to scan, use `.stconfig > Edit Config File`.56EDA9A1-C8C3-4549-B3C3-6AA5DE031A82
xpos
- 1070
+ 1065
ypos
570
@@ -1027,6 +1030,8 @@ To add additional directories to scan, use `.stconfig > Edit Config File`.
variables
+ ACTION_PROJECT_FILE
+ false
INTERVAL_FIND
30m
INTERVAL_LOCATE
@@ -1036,6 +1041,11 @@ To add additional directories to scan, use `.stconfig > Edit Config File`.VSCODE
false
+ variablesdontexport
+
+ ACTION_PROJECT_FILE
+ VSCODE
+
version
3.3.0
webaddress
diff --git a/magefile.go b/magefile.go
index 5f9e7a9..3f2ca2a 100644
--- a/magefile.go
+++ b/magefile.go
@@ -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() {
@@ -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(
@@ -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
diff --git a/main.go b/main.go
index c0deb71..5a382b6 100644
--- a/main.go
+++ b/main.go
@@ -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()
diff --git a/modd.conf b/modd.conf
index e62fc21..a12a87c 100644
--- a/modd.conf
+++ b/modd.conf
@@ -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
}