Closed DLFW closed 4 months ago
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 keymap.toml
, a script joshtest.sh
like
#!/usr/bin/env bash
echo $(cat /home/dude/test-bookmarks | dmenu)
somewhere in the path, and a list of directories in /home/dude/test-bookmarks
like
/home/dude/Downloads
~/music
~/sandbox/joshuto
Then, e-t
will open a dmenu where one can choose a directory from the list, and Joshuto will jump to there.
It's just a first, simple example for these two new commands.
Just did a rebase and fmt
Thanks! Might take a while for me go through the PR
Just rebased and resolved conflicts
Interesting design. It seems a little messy to have these commands do all this, but I can't think of a better solution at the moment and I'm curious to see where this goes.
Interesting design. It seems a little messy to have these commands do all this, but I can't think of a better solution at the moment and I'm curious to see where this goes.
“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 clap
to have a real command/option/argument parser (which would have enabled me to implement my initial idea), or introducing something like a socket from where Joshuto can read commands (in parallel to stdout) to allow “remote controlling” of Joshuto. That could have also been used by shell
-commands to issue certain reaction. Both these alternatives were too much effort/risky for me right now.
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.