Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: shell-like combinators for conditional computation and sending several commands to server in a single batch #278

Open
nikitabobko opened this issue Jun 15, 2024 · 0 comments

Comments

@nikitabobko
Copy link
Owner

nikitabobko commented Jun 15, 2024

Currently it's impossible to consume stdout and exit codes of commands in toml config. One has to use exec-and-forget

alt-w = 'exec-and-forget aerospace workspace W || aerospace workspace-back-and-forth'
atl-tab = 'exec-and-forget aerospace list-workspaces --all | aerospace workspace next'

It's slow. Communicating with the server back and forth from CLI client can take additional 100ms which becomes noticeable. Even if we fix the slowness somehow, annoying flickering will still remain an issue

It'd be cool if AeroSpace supported basic shell combinators (||, &&, ;, ( ), !)

alt-w = 'workspace W || workspace-back-and-forth'
atl-tab = 'list-workspaces --all | workspace next'

That's a big feature that lays the foundation for a lot of things (basically the combinators allow programming custom logic):

  • It becomes possible to send a batch of commands from CLI to server at once, resulting in reduced flickering (because server already implements "double buffering" to reduce flickering)
    https://nikitabobko.github.io/AeroSpace/goodness#use-trackpad-gestures-to-switch-workspaces
    aerospace eval - <<< 'list-workspaces --monitor mouse --visible | xargs workspace; aerospace workspace next'
  • It fixes the ugliness of on-window-detected TOML callback. The new syntax is much more compact and powerful. It remains readable for people familiar with shell:
    on-window-detected = '''
        test %{app-bundle-id} == com.jetbrains.intellij && move-workspace-to-monitor I \
            || test %{app-bundle-id} == com.google.Chrome && move-node-to-workspace W \
            || test %{app-bundle-id} == com.apple.dt.Xcode && (move-node-to-workspace X; exec-async 'echo hi!')
    '''
  • It opens up a possibility for even more powerful conditional gaps [Feature Request] Large Monitor, Single App Window Size Concern #60:
    [gaps]
    outer.left = 'test %{workspace-tiling-windows-count} -le 2 && echo 100'
    outer.right = 'test %{workspace-tiling-windows-count} -le 2 && echo 100'
  • It makes everything more universal and reusable. E.g. there won't be need to fix Add command to programatically run all on-window-detected callbacks  #107 if config command allows to query on-window-detected command:
    aerospace eval - <<< 'config --get on-window-detected | eval -'

Other subcommands that AeroSpace has to implement to make the feature complete:

Overall a lot issues can be fixed: #264 #60 #54 #174 (partially) #104 (partially) #107 (kinda) #150

Open question: doesn't it open a pandora box of own script programming language? It kinda does. I hope that people will never ask for loops

nikitabobko added a commit that referenced this issue Jun 16, 2024
…instead of using JSON array

Reason: it better fits into a future with built-in shell-like combinators #278

Before:

    $ aerospace config --get mode.service.binding --json
    {
      "alt-shift-k" : [
        "join-with up",
        "mode main"
      ],
      "backspace" : [
        "close-all-windows-but-current",
        "mode main"
      ],
      ...
    }

After:

    $ aerospace config --get mode.service.binding --json
    {
      "alt-shift-h" : "join-with left; mode main",
      "esc" : "mode main; reload-config",
      "alt-shift-k" : "join-with up; mode main",
      "r" : "flatten-workspace-tree; mode main",
      "backspace" : "close-all-windows-but-current; mode main",
      "alt-shift-j" : "join-with down; mode main",
      "f" : "layout floating tiling; mode main",
      "alt-shift-l" : "join-with right; mode main"
    }

Raycast extension doesn't depend on this API yet, so it should be fine
to break it #215
nikitabobko added a commit that referenced this issue Jun 16, 2024
It's a more detailed name. %{app-id} wasn't yet released, so it's fine
to rename it. `--app-id` remains supported in `list-windows`

The biggest usage of "app-id" term is going to be renamed in
`on-window-detected` callback with the introduction of shell-like
combinators #278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant