diff options
Diffstat (limited to 'scp.sh')
-rwxr-xr-x | scp.sh | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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 |