#!/usr/bin/env bash ## Run a command as a background process. ## ## Usage: background [...] ## ## Dependencies: GNU coreutils, GNU sed ## ## I use this script to run GUI apps via aliases and window manager key bindings ## (I don't use an application launcher). This script isn't needed to run apps ## via my window manager, but without this script, those apps will be ## subprocesses of the window manager; whereas, after `background ` has ## run, the process is orphaned and becomes a child of the init ## process, which I prefer for GUI apps. set -euo pipefail shopt -s inherit_errexit die() { echo -e "$(basename "$0"): $1" >&2; exit 1; } [[ " $* " =~ ' --help ' ]] && sed -n 's/^## *//p' "$0" && exit (( $# >= 1 )) || die 'missing argument' cmd=$1; type "$cmd" &> /dev/null || die "command not found: $cmd" cmd_args=("${@:2}") $cmd "${cmd_args[@]}" &> /dev/null &