From 2bed591dbe9324e91e59f2835d683f3ea2aa1d21 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 8 May 2020 08:52:26 -0500 Subject: Fix -r flag --- mrgrctrnl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mrgrctrnl b/mrgrctrnl index b516596..aa6016c 100755 --- a/mrgrctrnl +++ b/mrgrctrnl @@ -12,6 +12,7 @@ main() { _RUN=true _LOG=true _USE_CONFIG=true + _RESTART=false # options __CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/$PRGN/config" __PIDF="/tmp/$PRGN.pid" @@ -19,9 +20,6 @@ main() { __SSH="$(command -v autossh || command -v ssh)" __SSH_ARGS="-nT -N \"\$user@\$machine\" -L \"\$local:\$remote\"" - # save command invocation (for -r) - printf '%s %s\n' "$PRGN" "$*" >"$__CMDF" - # parse options while getopts hkrnqSAc:s: OPT; do case "$OPT" in @@ -34,10 +32,7 @@ main() { pkill -x "$PRGN" exit "$?" ;; - r) - untunnel - exec "$(cat "$__CMDF")" - ;; + r) _RESTART=true ;; n) _RUN=false ;; q) _LOG=false ;; S) __SSH='ssh' ;; @@ -52,6 +47,14 @@ main() { done shift $((OPTIND - 1)) + # save command invocation (for -r) + if $_RESTART; then + untunnel + exec "$PRGN" $(cat "$__CMDF") + else + printf '%s\n' "$*" >"$__CMDF" + fi + # make sure ssh is installed if ! command -v "$__SSH" >/dev/null; then log "Not installed: $__SSH" -- cgit 1.4.1-21-gabe81