From 7c2dab07b51336a671750871f78c3f1c42c35743 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Wed, 2 Nov 2022 16:20:50 +0100 Subject: Fixed scp.sh --- scp.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'scp.sh') diff --git a/scp.sh b/scp.sh index 6365187..bf05ce0 100755 --- a/scp.sh +++ b/scp.sh @@ -2,13 +2,18 @@ # Allows to select a host to send files to through scp hostsfile="$HOME/.hosts" -hostnames="$(sed '/^#.*$/d; /^$/d' < "$hostsfile" | cut -d'#' -f1 | fzf)" || exit 0 -host="$(grep "$hostnames" < "$hostsfile")" -hostname="$(echo "$host" | cut -d'#' -f1)" -hostaddress="$(echo "$host" | cut -d'#' -f2)" -hostport="$(echo "$host" | cut -d'#' -f3)" -hostpass="$(echo "$host" | cut -d'#' -f4)" -targetPath="$(echo "$host" | cut -d'#' -f5)" +host="$(sed '/^#/d; /^\s*$/d' "$hostsfile" | cut -d'#' -f1 | fzf)" || exit 0 +hostline="$(grep "^${host}" "$hostsfile")" +hostname="$(echo "$hostline" | cut -d'#' -f1)" +hostaddress="$(echo "$hostline" | cut -d'#' -f2)" +hostport="$(echo "$hostline" | cut -d'#' -f3)" +hostpass="$(echo "$hostline" | cut -d'#' -f4)" +targetPath="$(echo "$hostline" | cut -d'#' -f5)" + echo "Sending to $hostname" [ "$hostpass" ] && pass -c "$hostpass" -[ "$hostport" ] && scp -r -P $hostport "$@" $hostaddress:$targetPath || scp -r "$@" $hostaddress:$targetPath # No quotes here! +if [ -n "$hostport" ]; then + scp -r -P "$hostport" "$@" "${hostaddress}:${targetPath}" +else + scp -r "$@" "${hostaddress}:${targetPath}" # No quotes here! +fi -- cgit v1.2.1