Skip to content

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

@nikitabobko

Description

@nikitabobko

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 --fail-if-noop || 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 --fail-if-noop 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'
    Or alternatively without xargs:
    aerospace eval 'list-workspaces --monitor mouse --visible | workspace -; 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] Better support for ultrawide monitors #60:
    [gaps]
    outer.left = 'test %{workspace-tiling-windows-count} --lessThan 2 && echo 100'
    outer.right = 'test %{workspace-tiling-windows-count} --lessThan 2 && echo 100'
    UPD: this particular suggestion was discarded
  • 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.

Related: #1454

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions