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

Add ability to run commands in the current session via external scripts #3581

Open
pauschuu opened this issue Sep 1, 2024 · 4 comments
Open

Comments

@pauschuu
Copy link

pauschuu commented Sep 1, 2024

Disclaimer:
I know this is a tmux comparison, but it's (in my opinion) not some special feature, rather a core functionality that Zellij should have.

In tmux, I frequently run actions or commands in the current session using external scripts. For
example:

# in some script that could be run from anywhere on the machine

# creates a new pane in the last active tmux session (the session with the most recent client activity)
tmux split-window

or

# sends the keys "foobar" to the last active pane
tmux send-keys foobar

Zellij can do this, but as soon as I have more than one session it wants me to explicitly state the session name in my command. That's a significant limitation for scripting around zellij.

I assume Zellij already internally tracks session activity, so it should be relatively straightforward to add an option like --in-current-session (or something like that) to the zellij command.

Implementing this feature would greatly enhance Zellij's usability for users who rely on external scripts to manage their terminal sessions.

@Zykino
Copy link
Contributor

Zykino commented Sep 1, 2024

Zellij set the env var ZELLIJ_SESSION_NAME. So you can use that ;)

@pauschuu
Copy link
Author

pauschuu commented Sep 1, 2024

Zellij set the env var ZELLIJ_SESSION_NAME. So you can use that ;)

How should this help when running an external script that does not run in any Zellij context? The point is to that the script doesn't know the current active session (the one with the latest client interaction) so it has to rely on Zellij giving the option to say zellij --current-session action <some_action> so that Zellij would then take care of applying the action to the current session / pane.

@Zykino
Copy link
Contributor

Zykino commented Sep 1, 2024

How should this help when running an external script that does not run in any Zellij context?

How does --in-current-session know the "current session" if it is not in it?
Should it use the last created?
You say "the one with the latest client interaction", but is this even reliable? Some peoples use zellij inside their IDE (vscodium among other). Some peoples use sessions for mid to long running command a bit like daemon (even if it is not the correct tool for it). We can’t know everyone’s setups.
If you connect by SSH, then come back on your DE, which is the "current"?
If no session is active does it create one?
If no session is active and there are resurrect, does it pick one to resurrect? Which one?
If 2 peoples are connected as the same user and both use a different session, the "current" session change at each keystroke by one or the other?
…?

Most importantly, does your answers apply only to you or to every workflow?

To me the best zellij can provide is a way to specify the session. You can list all with zellij ls. You can also name your sessions. So you know you have "work", "personal", …

If you describe a bit more what you want this script do outside of zellij to a specific session I would be happy to brainstorm with you. For starter I don’t understand the need for this script to be run from outside of zellij. Is it run as a cron job?

@pauschuu
Copy link
Author

pauschuu commented Sep 2, 2024

Use case:

In tmux I had some keyboard shortcuts (defined outside of tmux) that run some scripts and also call some command or print some characters into the current tmux session.

Regarding reliability:

Worked pretty stable in tmux, only case where it didn't work was:
Bringing a terminal window up front (with mouse-click on titlebar i.e.).
This terminal wasn't the "last used" because tmux itself didn't see any action yet, since the mouse-click on some terminal window isn't recognizable by tmux itself. But apart from that it works fine. Type one letter, or perform any action at all (even mouse actions) and this session will be the last recent one.

Zellij kitty protocol support:

I guess the kitty protocol support (hopefully coming soon with the next release of Zellij) also makes these use-cases quite possible, since more keyboard combinations will (hopefully, think Ctrl+Shift+Super+p) be supported.

Conclusion:

To enhance scriptability, it would be a valuable addition to Zellij if users could send actions without specifying a particular session, allowing Zellij to automatically target the most recently used session.

Note:

To clear up: Last recent used should only be determined by last recent user interaction. Not any command output or other stuff that happens in the background.

franckrasolo added a commit to franckrasolo/dotfiles.nix that referenced this issue Sep 3, 2024
When multiple sessions are active, Zellij requires the name of a session to send actions to.

Alas a WezTerm pane does not inherit a shell's environment and therefore cannot use the ZELLIJ_SESSION_NAME environment variable.

wez/wezterm#5906
zellij-org/zellij#3581
zellij-org/zellij#2100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants