another real-world-example (with --interactive option) #390
Replies: 4 comments
-
Nice. Thanks for sharing.
|
Beta Was this translation helpful? Give feedback.
-
Alright. So here are my thoughts: Generic interactive terminalWhen I think about an interactive terminal, I think of something like the redis CLI or the Postgres CLI: In both, you enter their own "world" with their own commands. It is not a bash subshell. To create such an experience for any command, we can use #!/usr/bin/env bash
if [[ $# -eq 0 ]]; then
echo "Interactive shell"
echo " Usage: $0 COMMAND"
echo " Example: $0 git"
exit 1
fi
command="$1"
rlwrap \
--always-readline \
--complete-filenames \
--no-children \
--prompt-colour=Yellow \
--substitute-prompt "$command > " \
-t dumb \
bash -c "while read -e line; do "$command" \$line || true; done" running it with any command, will start a shell, where the specified command is pre-populated always. I called this script I am posting it here, thinking perhaps it would be helpful for your users, using your shell. Built in
|
Beta Was this translation helpful? Give feedback.
-
Sure, thanks a lot.
True, this is probably the much more common use case and user expectation. To illustrate the orcli use case: A full bash shell should indeed be available so that other unix tools can be used. The flow would be something like this:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi Danny,
We had a discussion on catch-all-advanced #199 some time ago and I would now like to report back that your advice to use repeatable args worked well. I used Bashly to create a command line client for OpenRefine: https://github.com/opencultureconsulting/orcli/blob/main/src/bashly.yml. The client has many commands and options and Bashly has helped a lot in keeping the code structured and maintainable.
Of general interest to the Bashly community might be the
--interactive
option. I'm not sure if my solution works well in all scenarios, but for now it seems to work fine. With./orcli run --interactive
the user gets a shell with autocompletion and alias without prior installation. Maybe this is an idea for another Bashly library?https://github.com/opencultureconsulting/orcli/blob/6c47e108f7b978a030e57bd05e7421fece5813ab/src/run_command.sh#L84-L96
https://github.com/opencultureconsulting/orcli/blob/56272613f2791e76aa890516ea84ca2a5c3adc47/src/lib/interactive.sh
Thanks again for your advice!
Beta Was this translation helpful? Give feedback.
All reactions