diff --git a/plugins/re-type-on-error/LICENSE b/plugins/re-type-on-error/LICENSE new file mode 100644 index 000000000..5d5dca557 --- /dev/null +++ b/plugins/re-type-on-error/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Gernot Feichter + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/re-type-on-error/README.md b/plugins/re-type-on-error/README.md new file mode 100644 index 000000000..64fc90142 --- /dev/null +++ b/plugins/re-type-on-error/README.md @@ -0,0 +1,26 @@ +# re-type-on-error + +## description +A plugin for [oh-my-zsh](#https://github.com/ohmyzsh/ohmyzsh/) that watches for + failed commands(=commands with a non-zero exit code). If a command failed in t +he interactive shell, it get immediately re-typed, or maybe call it re-displaye +d to the user for possible corrections. + +## showcase +![showcase](showcase.gif) + +## installation + +1. install [oh-my-zsh](#https://github.com/ohmyzsh/ohmyzsh/) +2. make sure that the plugins array is included in your .zshrc file: \ +`plugins=(... re-type-on-error)` + +## configuration + +### environment variables +`ZSH_RETYPE_ON_ERROR_SHOW_DISCLAIMER=true` \ +This setting shows a string before the re-typed failed command that indicates: ++ that the previous command failed ++ the exit code of the previous command ++ the default of this setting is true as indicated above, simply set to false + if this is not desired diff --git a/plugins/re-type-on-error/re-type-on-error.plugin.zsh b/plugins/re-type-on-error/re-type-on-error.plugin.zsh new file mode 100644 index 000000000..03be6e107 --- /dev/null +++ b/plugins/re-type-on-error/re-type-on-error.plugin.zsh @@ -0,0 +1,28 @@ +zle-line-init() { + re-type-on-error + return 0 +} + +re-type-on-error() { + local last_command_exit_code=${?} + readonly last_command_exit_code + if [ ${last_command_exit_code} != 0 ]; then + # disclaimer + [ "${ZSH_RETYPE_ON_ERROR_SHOW_DISCLAIMER}" = true ] && + echo -n "(re-typing last command as exit code " && + echo "${last_command_exit_code} was non-zero)" + + # populating exit code into $? variable so that + # it does not get obfuscated by this plugin + (exit ${last_command_exit_code}) + + # re-type failed command + zle up-history + fi + return 0 +} + +ZSH_RETYPE_ON_ERROR_SHOW_DISCLAIMER=\ +"${ZSH_RETYPE_ON_ERROR_SHOW_DISCLAIMER:-true}" + +zle -N re-type-on-error diff --git a/plugins/re-type-on-error/showcase.gif b/plugins/re-type-on-error/showcase.gif new file mode 100644 index 000000000..3cfc6a129 Binary files /dev/null and b/plugins/re-type-on-error/showcase.gif differ