add plugin re-type-on-error

This commit is contained in:
Gernot Feichter
2021-03-21 22:05:48 +01:00
parent 95a06f3927
commit 2a3dabd12e
4 changed files with 75 additions and 0 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB