aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2019-12-15 23:01:28 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2019-12-15 23:01:28 +0100
commitb8d66986e9be6711ed42f0b75de3af2e1f4a632d (patch)
tree067c400b6fffa7022a021e3db6f9d80be7b9d9a6
parentc3ffbbe252e07d7dd4161039dcaf8cb02e05e202 (diff)
downloadscripts-b8d66986e9be6711ed42f0b75de3af2e1f4a632d.tar.gz
scripts-b8d66986e9be6711ed42f0b75de3af2e1f4a632d.zip
ssh.sh and scp.sh now don't show blank options.
-rwxr-xr-xscp.sh2
-rwxr-xr-xssh.sh7
2 files changed, 5 insertions, 4 deletions
diff --git a/scp.sh b/scp.sh
index ca6769b..6365187 100755
--- a/scp.sh
+++ b/scp.sh
@@ -2,7 +2,7 @@
# Allows to select a host to send files to through scp
hostsfile="$HOME/.hosts"
-hostnames="$(sed '/^#.*$/d' < "$hostsfile" | cut -d'#' -f1 | fzf)" || exit 0
+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)"
diff --git a/ssh.sh b/ssh.sh
index b020508..7d25618 100755
--- a/ssh.sh
+++ b/ssh.sh
@@ -1,10 +1,11 @@
#!/bin/sh
# Allows to select a host to connect to through ssh
-# Hosts are read from the file $hostsfile, in which each line should be a host in the form identifier#address#port#input for pass
+# Hosts are read from the file $hostsfile, in which each line should be a host
+# in the form identifier#address#port#input for pass
# Port and input for pass are optional
hostsfile="$HOME/.hosts"
-hostnames="$(sed '/^#.*$/d' < "$hostsfile" | cut -d'#' -f1 | fzf)" || exit 0
+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)"
@@ -12,5 +13,5 @@ hostport="$(echo "$host" | cut -d'#' -f3)"
hostpass="$(echo "$host" | cut -d'#' -f4)"
echo "Connecting to $hostname"
[ "$hostpass" ] && pass -c "$hostpass"
-[ "$hostport" ] && ssh $hostaddress -p $hostport || ssh $hostaddress # No quotes here!
+[ "$hostport" ] && ssh "$hostaddress" -p "$hostport" || ssh "$hostaddress" # No quotes here!
#$(echo "ssh $hostaddress -p $hostport") # Alternative to prev line