File: 10-autoexec

package info (click to toggle)
shellex 0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 208 kB
  • sloc: ansic: 44; makefile: 35; sh: 10
file content (28 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
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