oh-my-zsh/plugins/nohup/nohup.plugin.zsh

32 lines
885 B
Bash
Raw Normal View History

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
BUFFER="${BUFFER#nohup }"
BUFFER="${BUFFER%\ &\>*}"
2017-04-06 07:02:28 +00:00
else
2017-04-07 10:18:46 +00:00
base="${BUFFER#sudo }"
tokens_slash=("${(@s|/|)base}")
tokens_space=("${(@s/ /)tokens_slash[-1]}")
2017-04-07 10:18:46 +00:00
command=("$tokens_space[1]")
2017-04-06 07:02:28 +00:00
2017-05-04 06:03:14 +00:00
BUFFER="nohup $BUFFER &> $command.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