~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.config/fish/functions/detach.fish -rw-r--r-- 762 bytes
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# detach — run a command fully free of the terminal.
# New session (setsid), stdio to /dev/null, backgrounded, disowned.
# Closing the terminal will not kill the process or print its logs.
#
# Usage:
#   detach brave
#   detach gimp ~/pic.png
# Escape hatch (run attached): command brave   OR   DETACH_OFF=1 brave

function detach --description 'Run command fully detached from the terminal'
    if test (count $argv) -eq 0
        echo 'usage: detach <command> [args...]' >&2
        return 1
    end

    # setsid: new session, no controlling TTY
    # </dev/null >/dev/null 2>&1: no terminal I/O, no SIGHUP-on-close noise
    # & + disown: fish will not job-control or SIGHUP the process on exit
    setsid $argv </dev/null >/dev/null 2>&1 &
    disown
end