Skip to content

Commit

Permalink
list-prompt command now works with zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
doekman committed Jun 30, 2022
1 parent 015d8e2 commit ca17341
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ Zsh is also supported, but with limited options for now:
* when sourcing ok.sh in the current folder, a path is needed (`. ok.sh` fails, but `. ./ok.sh` works)
* autocomplete is not supported at the moment
* the `auto_show` helper does currently not work with zsh, because of [$PROMPT_COMMAND](https://superuser.com/questions/735660/whats-the-zsh-equivalent-of-bashs-prompt-command)
* the `list-prompt` command doesn't work (error: `ok:read:194: -p: no coprocess`)
* when running `./ok.sh` as a script, zsh needs bash to execute the script, because of the `env`-construct.


Expand Down
12 changes: 10 additions & 2 deletions ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,19 @@ environment variables (for internal use):
elif [[ $show_prompt == 1 && $list_result == 0 ]]; then #only show prompt, if there where commands printed
local prompt_input
local re_num_begin="${re_begins_with_cmd}($| )" # You can enter arguments at the ok-prompt too, hence different regex
# Show a prompt (read -p "XXX" fails in zsh)
echo -n "${c_prompt}${prompt}${c_nc}"
# The following read doesn't work in a sub-shell, so list-prompt fails when using it in a script
read -rp "${c_prompt}${prompt}${c_nc}" prompt_input
read -r prompt_input
if [[ $prompt_input =~ $re_num_begin ]]; then
#save command to history first
history -s "$args $prompt_input"
if [[ $(which print || echo "") = "print: shell built-in command" ]]; then
# The Zsh way to do it
print -s "$args $prompt_input"
else
# The Bash way to do it
history -s "$args $prompt_input"
fi
#execute command
eval _ok_cmd_run "$prompt_input" || return $?
else
Expand Down

0 comments on commit ca17341

Please sign in to comment.