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