blob: bf05ce00e3ddb62913da3b0bc803b096d7f8960b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/bin/sh
# Allows to select a host to send files to through scp
hostsfile="$HOME/.hosts"
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"
if [ -n "$hostport" ]; then
scp -r -P "$hostport" "$@" "${hostaddress}:${targetPath}"
else
scp -r "$@" "${hostaddress}:${targetPath}" # No quotes here!
fi
|