summaryrefslogtreecommitdiff
path: root/sshclip
blob: ebabcf1bd89377daf17652e2c2a0bbb08f9ef1c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

# Open a SSH session to the hostname in the clipboard
# Requires the xclip package to be installed.

getSelection() {
    HOSTNAME=$(xclip -out -selection $1|sed -re 's/(.*[[:space:]]|)([A-Za-z0-9][A-Za-z0-9.-]+\.[A-Za-z0-9.-]*[A-Za-z0-9]).*/\2/')
}

getSelection 'primary'
if [ -z "$HOSTNAME" ]; then
    getSelection 'secondary'
fi

if [ -n "$HOSTNAME" ]; then
    i3-sensible-terminal -e ssh $HOSTNAME &
else
    notify-send "No hostname in clipboard"
    exit 1
fi