summaryrefslogtreecommitdiff
path: root/xsh
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2016-10-22 19:01:41 +0200
committerJonas Smedegaard <dr@jones.dk>2016-10-22 23:59:09 +0200
commit6aa2a9af5e24ddfed681fd7f1d68013abb6c471f (patch)
treeffbf0f085b88f815353aaed7d630878f9cfd1c85 /xsh
parenta18858bcc1048d7c303f8d6c34f640713cfa489a (diff)
Fix shell-wrap as needed, singlequote-escaped.
Diffstat (limited to 'xsh')
-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