| 1 |
# vim:ft=zsh |
| 2 |
# Make zsh automatically execute a command, when enter is hit |
| 3 |
# © 2013 Axel Wagner and contributors (see also: LICENSE) |
| 4 |
|
| 5 |
function shellex_preexec () { |
| 6 |
# In $1 the command-line is given |
| 7 |
# In $3 the command-line with expanded aliases and function-bodies is given |
| 8 |
|
| 9 |
# Execute the tempfile, then exit |
| 10 |
zsh -c $3 > /dev/null 2>&1 & disown |
| 11 |
|
| 12 |
exit |
| 13 |
} |
| 14 |
|
| 15 |
# We use preexec_functions, so that the user can decide to overwrite our choice |
| 16 |
# or ammend it by own functions |
| 17 |
preexec_functions=(shellex_preexec) |
| 18 |
|
| 19 |
# preexec doesn't get executed on empty lines, so employ zle to exit on empty lines |
| 20 |
# https://www.reddit.com/r/zsh/comments/s6t6d/is_there_an_alias_for_an_empty_line/ |
| 21 |
function empty-buffer-to-exit() { |
| 22 |
if [[ $#BUFFER == 0 ]]; then |
| 23 |
fc -P |
| 24 |
exit |
| 25 |
fi |
| 26 |
} |
| 27 |
# set special widget, see man zshzle |
| 28 |
zle -N zle-line-finish empty-buffer-to-exit |