-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add capture
and stdout
commands
#495
Conversation
This is a first step for #456. Reasons why have chosen this solution are outlines in my comment there. As mentioned in the commit message, this is currently not sufficient to solve the original requirement, but I thought this is a good first commit, also to have some agreement that this concept is a feasible way to go. I will provide ~two follow-up commits to get some of the other missing pieces and I will also provide some documentation then. To test the single working “stdout-command”, one can add something like { keys = ["e", "t"], commands = ["capture joshtest.sh", "stdout cd"] }, into #!/usr/bin/env bash
echo $(cat /home/dude/test-bookmarks | dmenu) somewhere in the path, and a list of directories in
Then, It's just a first, simple example for these two new commands. |
a30dcde
to
51dbc23
Compare
Just did a rebase and fmt |
Thanks! Might take a while for me go through the PR |
This adds two new commands as a base to enable users to use the output of scripts to do certain actions in Joshuto. The first command this adds is a third command to start a sub-process beside `shell` and `spawn`, called `capture`. Like `shell`, `capture` is running blocking but unlike `shell`, it does not release the terminal but captures the `stdout` of the sub-process and stores it in an `AppContext` attribute. The second command added by this commit is `stdout`. This command takes the output from the last `capture` run, stored in the `AppContext` attribute, and uses it for some action. The action has to be specified as a sub-command. As of now, only `stdout cd` is implemented. This checks that the last output of `capture` is a single line of an existing file or directory and then changes the working directory to that. To get significant value from these new commands, `capture` needs to be equipped with more variables to feed more information about Joshuto's state into external scripts, and `stdout` needs to get some more sub-commands.
Just rebased and resolved conflicts |
Interesting design. |
“A little messy” is a good description. 😇 In the end, I saw only two alternatives: Complete refactoring of the “command processing” in Joshuto and introducing something like Thanks for merging! |
This adds two new commands as a base to enable users to use the output of scripts to do certain actions in Joshuto.
The first command this adds is a third command to start a sub-process beside
shell
andspawn
, calledcapture
. Likeshell
,capture
is running blocking but unlikeshell
, it does not release the terminal but captures thestdout
of the sub-process and stores it in anAppContext
attribute.The second command added by this commit is
stdout
. This command takes the output from the lastcapture
run, stored in theAppContext
attribute, and uses it for some action. The action has to be specified as a sub-command. As of now, onlystdout cd
is implemented. This checks that the last output ofcapture
is a single line of an existing file or directory and then changes the working directory to that.To get significant value from these new commands,
capture
needs to be equipped with more variables to feed more information about Joshuto's state into external scripts, andstdout
needs to get some more sub-commands.