Skip to content

Commit

Permalink
auto_show support for zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
doekman committed Jun 30, 2022
1 parent ca17341 commit 037d753
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ For per-user use, add something like this to the `~/.bashrc`¹:

Bash is supported, starting with version 3.2, which is installed on macOS, and up (most Linux installations).

Zsh is also supported, but with limited options for now:
Zsh is also supported, but some notes:

* 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)
* when running `./ok.sh` as a script, zsh needs bash to execute the script, because of the `env`-construct.
* and you have to consider a bit of different behaviour you get with bash:
- when sourcing ok.sh in the current folder, a path is needed (`. ok.sh` fails, but `. ./ok.sh` works)
- when running `./ok.sh` as a script, zsh needs bash to execute the script, because of the `env`-construct.


## Development
Expand Down
15 changes: 11 additions & 4 deletions ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ environment variables (for internal use):
read -r prompt_input
if [[ $prompt_input =~ $re_num_begin ]]; then
#save command to history first
if [[ $(which print || echo "") = "print: shell built-in command" ]]; then
if [ ! -z ${ZSH_VERSION+x} ]; then
# The Zsh way to do it
print -s "$args $prompt_input"
builtin print -s "$args $prompt_input"
else
# The Bash way to do it
history -s "$args $prompt_input"
builtin history -s "$args $prompt_input"
fi
#execute command
eval _ok_cmd_run "$prompt_input" || return $?
Expand Down Expand Up @@ -296,7 +296,14 @@ else
comment_align) if [[ $# -ge 2 ]]; then export _OK_COMMENT_ALIGN=$2; shift; else >&2 echo "the comment_align argument needs a number (0..3) as 2nd argument"; fi;;
verbose) export _OK_VERBOSE=2;;
quiet) export _OK_VERBOSE=0;;
auto_show) if [[ ! $PROMPT_COMMAND =~ $re_list_once ]]; then export PROMPT_COMMAND="${PROMPT_COMMAND}"$'\n'"${re_list_once}"; fi;;
auto_show) if [ ! -z ${ZSH_VERSION+x} ]; then
function _zsh_list_once {
ok list-once
}
precmd_functions+=( _zsh_list_once )
else
if [[ ! $PROMPT_COMMAND =~ $re_list_once ]]; then export PROMPT_COMMAND="${PROMPT_COMMAND}"$'\n'"${re_list_once}"; fi
fi;;
*) >&2 echo "Ignoring unknown argument '$1'";;
esac
shift
Expand Down

0 comments on commit 037d753

Please sign in to comment.