alfy 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -20,6 +20,30 @@ export type OutputOptions = {
20
20
  The script will only be re-run if the script filter is still active and the user hasn't changed the state of the filter by typing and triggering a re-run. For example, it could be used to update the progress of a particular task:
21
21
  */
22
22
  readonly rerunInterval?: number;
23
+
24
+ /**
25
+ Variables passed out of the script filter and accessible throughout the current session as environment variables.
26
+
27
+ These are session-level variables that persist for the duration of the user action. Individual items can also have their own `variables` which override these when selected.
28
+
29
+ @example
30
+ ```
31
+ import alfy from 'alfy';
32
+
33
+ alfy.output(
34
+ [
35
+ {
36
+ title: 'Unicorn',
37
+ arg: 'unicorn',
38
+ }
39
+ ],
40
+ {
41
+ variables: {animal: 'unicorn'}
42
+ }
43
+ );
44
+ ```
45
+ */
46
+ readonly variables?: Record<string, string>;
23
47
  };
24
48
 
25
49
  export type CacheConfGetOptions = {
package/index.js CHANGED
@@ -43,9 +43,9 @@ alfy.alfred = {
43
43
 
44
44
  alfy.input = process.argv[2];
45
45
 
46
- alfy.output = (items, {rerunInterval} = {}) => {
46
+ alfy.output = (items, {rerunInterval, variables} = {}) => {
47
47
  hasOutput = true;
48
- console.log(JSON.stringify({items, rerun: rerunInterval}, null, '\t'));
48
+ console.log(JSON.stringify({items, rerun: rerunInterval, variables}, null, '\t'));
49
49
  };
50
50
 
51
51
  alfy.matches = (input, list, item) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alfy",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Create Alfred workflows with ease",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/alfy",
package/readme.md CHANGED
@@ -234,6 +234,28 @@ alfy.output(
234
234
 
235
235
  <img src="media/screenshot-output.png" width="694">
236
236
 
237
+ ###### variables
238
+
239
+ Type: `object`
240
+
241
+ Variables passed out of the script filter and accessible throughout the current session as environment variables. These are session-level variables that persist for the duration of the user action. Individual items can also have their own `variables` which override these when selected.
242
+
243
+ ```js
244
+ import alfy from 'alfy';
245
+
246
+ alfy.output(
247
+ [
248
+ {
249
+ title: 'Unicorn',
250
+ arg: 'unicorn',
251
+ }
252
+ ],
253
+ {
254
+ variables: {animal: 'unicorn'}
255
+ }
256
+ );
257
+ ```
258
+
237
259
  #### log(value)
238
260
 
239
261
  Log `value` to the [Alfred workflow debugger](https://www.alfredapp.com/help/workflows/advanced/debugger/).
package/run-node.sh CHANGED
@@ -13,7 +13,25 @@ PATH_CACHE="$alfred_workflow_cache"/node_path
13
13
 
14
14
  get_user_path() {
15
15
  eval $(/usr/libexec/path_helper -s)
16
- echo "$($SHELL -i -l -c 'echo -e "\n"PATH=\"$PATH:\$PATH\""\n"' 2>/dev/null | grep "^PATH=")" > "$PATH_CACHE"
16
+
17
+ # Use delimiters to reliably extract PATH from shell startup noise (inspired by `shell-env`).
18
+ # Disable Oh My Zsh plugins that can block the process.
19
+ local delimiter="_ALFY_ENV_DELIMITER_"
20
+ local raw_env
21
+ raw_env="$(DISABLE_AUTO_UPDATE=true ZSH_TMUX_AUTOSTARTED=true ZSH_TMUX_AUTOSTART=false $SHELL -ilc "echo -n $delimiter; command env; echo -n $delimiter; exit" 2>/dev/null)"
22
+
23
+ # Extract the env output between the delimiters.
24
+ local env_output="${raw_env#*"$delimiter"}"
25
+ env_output="${env_output%%"$delimiter"*}"
26
+
27
+ # Extract PATH from the env output.
28
+ local user_path
29
+ user_path="$(echo "$env_output" | sed -n 's/^PATH=//p')"
30
+
31
+ # Only write cache if we got a non-empty result.
32
+ if [[ -n "$user_path" ]]; then
33
+ echo "PATH=\"${user_path}:\$PATH\"" > "$PATH_CACHE"
34
+ fi
17
35
  }
18
36
 
19
37
  set_path() {