diff --git a/plugins/nohup/README.md b/plugins/nohup/README.md new file mode 100644 index 00000000..e56b7d6b --- /dev/null +++ b/plugins/nohup/README.md @@ -0,0 +1,10 @@ +## bbedit + +Plugin to prefix the current command with `nohup` using the `Ctrl+H` shortcut + + +### Usage + + * If them corrent termina line is `test 1 2 3` it will be transformed to `nohup test 1 2 3 &> test.out` and vice-versa + + * If no command is existing, the last submitted command will be recalled diff --git a/plugins/nohup/nohup.plugin.zsh b/plugins/nohup/nohup.plugin.zsh new file mode 100644 index 00000000..4cc032bf --- /dev/null +++ b/plugins/nohup/nohup.plugin.zsh @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# nohup will be inserted before the command and a redirect will be appended +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Michele Renda +# +# ------------------------------------------------------------------------------ + +nohup-command-line() { + [[ -z $BUFFER ]] && zle up-history + if [[ $BUFFER == nohup\ * ]]; then + LBUFFER="${LBUFFER#nohup }" + LBUFFER="${LBUFFER%\ &\>*}" + else + tokens=("${(@s/ /)LBUFFER}") + i=1 + if [[ $tokens[1] == sudo ]]; then + (( i++ )) + fi + + LBUFFER="nohup $LBUFFER &> $tokens[$i].out &" + fi +} +zle -N nohup-command-line +# Defined shortcut keys: [Ctrl] [h] +bindkey "\Ch" nohup-command-line