summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xxsh21
1 files changed, 16 insertions, 5 deletions
diff --git a/xsh b/xsh
index 081d471..c655c57 100755
--- a/xsh
+++ b/xsh
@@ -6,6 +6,18 @@ usage() {
echo "Usage: $SCRIPT [--x] [--verbose] [su|sudo] [[{user}]@{host}] [[--] command...]"
}
+# origin: http://stackoverflow.com/a/34515468
+quote_args() {
+ local sq="'"
+ local dq='"'
+ local space=""
+ local arg
+ for arg; do
+ echo -n "$space'${arg//$sq/$sq$dq$sq$dq$sq}'"
+ space=" "
+ done
+}
+
# Initial setup
SU=''
SUDO=''
@@ -31,16 +43,15 @@ done
[ $# -gt 0 ] || set -- /bin/bash
-# FIXME: needs shell wrapper (provided by SSH but not in local use)
-[ -z "$SU" ] || set -- "echo -n 'Changing to root...: '; su -c \"cd; "$@"\""
+[ -z "$SU" ] || set -- su -c "cd; $(quote_args "$@")"
+[ -z "$SU" ] || set -- sh -c "echo -n 'Changing to root...: '; $(quote_args "$@")"
[ -z "$SUDO" ] || set -- sudo -i -- "$@"
# Pause for a moment if verbose
-# FIXME: needs shell wrapper (provided by SSH but not in local use)
-[ -z "$V" ] || set -- "$@"\; sleep 4
+[ -z "$V" ] || set -- sh -c "$(quote_args "$@"); sleep 4"
-[ -z "$HOST" ] || set -- ssh -t${X:+ -X}${V:+ -v}${PORT:+ -p "$PORT"} $HOST "$@"
+[ -z "$HOST" ] || set -- ssh -t${X:+ -X}${V:+ -v}${PORT:+ -p "$PORT"} $HOST "$(quote_args "$@")"
[ -z "$V" ] || echo "$@"
[ -z "$V" ] || sleep 4