-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Feature: shell-like combinators for conditional computation and sending several commands to server in a single batch #278
Comments
…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
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
Draft:
|
Since it's a custom language (unfortunately), it'd be good to be able to print AST (Abstract Syntax Tree) for better discoverability and debugging
|
I think this sounds like it would be an incredible addition to the project. Have you thought about using existing embeddable scripting languages such as lua? I think this would be great for several reasons: (I'll use lua as an example here, but there other options)
This of course would come with some cons, too:
Edit: I've just found some incredibly well documented and up to date bindings for lua. Shocked it has so few stars. https://github.com/tomsci/LuaSwift Edit 2: I don't know how I didn't think of this at first, but macos provides a great embeddable language in the form of JavaScriptCore. Part of apples webkit. It requires no third party dependencies and has a very easy to use swift/obj-c api. Here's a very simple working code example, demonstrating just how easy it is to use. import Foundation
import JavaScriptCore
let context = JSContext()
let addTwoNumbers: @convention(block) (Int, Int) -> Int = { num1, num2 in
print("Adding two numbers: \(num1) + \(num2)")
return num1 + num2
}
context?.setObject(addTwoNumbers, forKeyedSubscript: "addTwoNumbers" as NSString)
let jsScript = "addTwoNumbers(2, 3)"
if let result = context?.evaluateScript(jsScript) {
print(result.toString() ?? "No result")
} |
There is also a sketchybar lua plugin 🙂 |
…instead of using JSON array Reason: it better fits into a future with built-in shell-like combinators nikitabobko#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 nikitabobko#215
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 nikitabobko#278
Just wanted up this I currently use the following shortcuts, and the delay due to
As far as I've read here and in #264, this is supposed to help with that, no? |
… CmdResult This commit lays out the foundation for the following issues - #186 - #278 - #20 Also the commit changes how focused window is tracked throught the chain of executed commands. - CommandMutableState was a mutable state that tracked the focused window, and the track had to be updated throught the chain of executed commands (for example, take a look at the `focus` command) - CmdEnv is simplier. It just forces a particular window to be percieved as "focused". CmdEnv approach makes things easier to understand and describe in the docs (which I'm going to do later, CmdEnv will be exposed as AEROSPACE_FOCUSED_WORKSPACE and AEROSPACE_FOCUSED_WINDOW_ID environment variables) Unlike CommandMutableState, CmdEnv approach disallows to change focused window in on-window-detected, on-focus-changed, and other callbacks. Which I think is not an issue at all. It maybe even considered a safety mechanism. If a user uses `close` in one of the mentioned callbacks, previously, a random window could become focused and it would receive all the following commands. Now, all the commands that go after `close` will fail with "Invalid <window-id> \(windowId) specified in AEROSPACE_FOCUSED_WINDOW_ID env variable" - This commit is not a breaking change for on-window-detected thanks to limitations in #20 - But this commit is technically a breaking change for other mentioned callbacks, since no limitations were impoosed on those callbacks. But I don't believe that anyone in sane mind relied on it. And the docs are explicit that changing focus in those callbacks is a bad idea: > Changing the focus within these callbacks is a bad idea anyway, and the way it’s handled will probably change in future versions. Currently, the "force focused state" in CmdEnv is immutable, and I hope it will stay so. But hypothetically, it can be mutable in future versions if we decide that the embedded language #278 should allow chaning environment variables.
+1 to the lua idea and just adding something (possibly obvious) but several very powerful tiling wms in the linux space (i3 and awesomewm) have I was around in the pre-lua awesome wm days and the syntax included shelling things out as described here - it was hairy stuff. Lua's syntax for a basic aerospace config would be arguably simple than the current toml. |
Hi there, noob question: Why not give the user opportunity to write a swift function instead? |
@karadnik-flutterint you can already do this by creating a fork |
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 nikitabobko/AeroSpace#278
… CmdResult This commit lays out the foundation for the following issues - nikitabobko/AeroSpace#186 - nikitabobko/AeroSpace#278 - nikitabobko/AeroSpace#20 Also the commit changes how focused window is tracked throught the chain of executed commands. - CommandMutableState was a mutable state that tracked the focused window, and the track had to be updated throught the chain of executed commands (for example, take a look at the `focus` command) - CmdEnv is simplier. It just forces a particular window to be percieved as "focused". CmdEnv approach makes things easier to understand and describe in the docs (which I'm going to do later, CmdEnv will be exposed as AEROSPACE_FOCUSED_WORKSPACE and AEROSPACE_FOCUSED_WINDOW_ID environment variables) Unlike CommandMutableState, CmdEnv approach disallows to change focused window in on-window-detected, on-focus-changed, and other callbacks. Which I think is not an issue at all. It maybe even considered a safety mechanism. If a user uses `close` in one of the mentioned callbacks, previously, a random window could become focused and it would receive all the following commands. Now, all the commands that go after `close` will fail with "Invalid <window-id> \(windowId) specified in AEROSPACE_FOCUSED_WINDOW_ID env variable" - This commit is not a breaking change for on-window-detected thanks to limitations in #20 - But this commit is technically a breaking change for other mentioned callbacks, since no limitations were impoosed on those callbacks. But I don't believe that anyone in sane mind relied on it. And the docs are explicit that changing focus in those callbacks is a bad idea: > Changing the focus within these callbacks is a bad idea anyway, and the way it’s handled will probably change in future versions. Currently, the "force focused state" in CmdEnv is immutable, and I hope it will stay so. But hypothetically, it can be mutable in future versions if we decide that the embedded language #278 should allow chaning environment variables.
Currently
it's impossible to consume stdout and exit codes of commands in toml config. One has to useexec-and-forget
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 (
||
,&&
,;
,( )
)That's a big feature that lays the foundation for a lot of things (basically the combinators allow programming custom logic):
https://nikitabobko.github.io/AeroSpace/goodness#use-trackpad-gestures-to-switch-workspaces
xargs
:on-window-detected
TOML callback. The new syntax is much more compact and powerful. It remains readable for people familiar with shell:config
command allows to queryon-window-detected
command:Other subcommands that AeroSpace has to implement to make the feature complete:
test
as in CLI but with possibility to interpolate AeroSpace special variables like%{window-title}
,%{window-name}
,%{app-bundle-id}
,%{workspace-tiling-windows-count}
, etc Implement test-regex command so users could more interactively test regexes the way they are implemented in AeroSpace #150UPD: stop turning it into a programming language. It's better to provide single dashxargs
as in CLI-
to a bunch of commands as in "consume stdin convention".xargs
and interpolation (which is another idea, that I discard right now) have a downside that it becomes impossible to statically parse all commands in "AeroSpace script"echo
as in CLI. (use case: Creating a new Workspace next to the current Workspace, send the current node / App to and focus it? #842)exec-async
as a replacement forexec-and-forget
. The problem withexec-and-forget
that it's not parsed as real CLI command, making it impossible to use the command with combinatorseval
to evaluate "AeroSpace script" fromargv[1]
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.
The text was updated successfully, but these errors were encountered: