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

How to command-prompt from a shell script? #2499

Closed
mohkale opened this issue Dec 11, 2020 · 7 comments
Closed

How to command-prompt from a shell script? #2499

mohkale opened this issue Dec 11, 2020 · 7 comments

Comments

@mohkale
Copy link

mohkale commented Dec 11, 2020

Issue description

I'm currently trying to write a script to interactively pipe-panes. Part of this involves asking the user which direction they want the pipe to go (in, out, both), followed by the command name and confirming whether they'd like to kill an open pipe.

command-prompt by itself doesn't have a flag to output the result to stdout so I've been trying to do indirectly through display-message but It seems to me that the command-prompt command implicitly runs a subshell which captures the output preventing my script from recieving it.

For example I have a script ~/tmux-pipe-ctrl which I've bound to | (bind | $HOME/tmux-pipe-ctrl) containing this:

choice=$(tmux command-prompt -1 -p "Direction (i|o|b):" "display-message -p '%%'")

How do I access the command-prompt result from within my script?

If there's no way (as of yet) I'd like to propose a flag that dumps the prompts result to stdout.

Required information

Please provide the following information:

  • tmux version (tmux -V). tmux next-3.3
  • Platform (uname -sp). Linux unknown
  • $TERM inside and outside of tmux (echo $TERM). screen-256color
  • Logs from tmux (tmux kill-server; tmux -vv new).
@nicm
Copy link
Member

nicm commented Dec 11, 2020

You could either 1) write the result into a file and either use wait-for or poll for the file appearing or 2) write your script in two parts and have command-prompt run the second part when it finishes (or run the same script with some argument saying it should continue).

@nicm
Copy link
Member

nicm commented Dec 11, 2020

An option to print result to stdout would be good but I don't know how hard it would be offhand.

@mohkale
Copy link
Author

mohkale commented Dec 11, 2020

@nicm

write the result into a file and either use wait-for or poll for the file appearing.
write your script in two parts and have command-prompt run the second part when it finishes

I considered the second option before opening the issue but my main concern is the quoting of shell characters. Seeing as I'll be using command prompt to read shell commands how can I properly escape them before they get passed to display-message or run-shell before being redirected into a file?.

@nicm
Copy link
Member

nicm commented Dec 12, 2020

You can try the q format modifier.

@nicm
Copy link
Member

nicm commented Dec 12, 2020

It may be difficult to use it with the result of command-prompt however. You may be best to use a popup to prompt the user instead.

@nicm
Copy link
Member

nicm commented Dec 28, 2020

I have added this to todo list but I wouldn't expect it anytime soon.

@nicm nicm closed this as completed Dec 28, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants