2017-04-06 07:02:28 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Description
|
|
|
|
# -----------
|
|
|
|
#
|
|
|
|
# nohup will be inserted before the command and a redirect will be appended
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Authors
|
|
|
|
# -------
|
|
|
|
#
|
|
|
|
# * Michele Renda <michele.renda@gmail.com>
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nohup-command-line() {
|
|
|
|
[[ -z $BUFFER ]] && zle up-history
|
|
|
|
if [[ $BUFFER == nohup\ * ]]; then
|
2017-04-06 07:44:07 +00:00
|
|
|
BUFFER="${BUFFER#nohup }"
|
|
|
|
BUFFER="${BUFFER%\ &\>*}"
|
2017-04-06 07:02:28 +00:00
|
|
|
else
|
2017-04-06 07:44:07 +00:00
|
|
|
tokens_slash=("${(@s|/|)BUFFER}")
|
|
|
|
tokens_space=("${(@s/ /)tokens_slash[-1]}")
|
2017-04-06 07:02:28 +00:00
|
|
|
i=1
|
2017-04-06 07:44:07 +00:00
|
|
|
if [[ $tokens_slash[1] == sudo ]]; then
|
2017-04-06 07:02:28 +00:00
|
|
|
(( i++ ))
|
|
|
|
fi
|
|
|
|
|
2017-04-06 07:44:07 +00:00
|
|
|
BUFFER="nohup $BUFFER &> $tokens_space[$i].out &"
|
2017-04-06 07:02:28 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
zle -N nohup-command-line
|
|
|
|
# Defined shortcut keys: [Ctrl] [h]
|
|
|
|
bindkey "\Ch" nohup-command-line
|