Created
June 14, 2019 10:19
-
-
Save jnaskali/104cc00d8e9dfc63cac1d9534ebc00a2 to your computer and use it in GitHub Desktop.
Script to handle SSH links from Firefox in Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Script that opens ssh:// links from Firefox - CC0 by Juhani, www.naskali.fi | |
# extract the protocol | |
proto="$(echo $1 | grep -oP '^[a-z]*')" # first letters | |
# extract the user (if any) | |
user="$(echo $1 | grep -oP '(?<=:\/\/)(.*)(?=@)')" # text in between :// and @ | |
# extract the host | |
host="$(echo $1 | grep -oP '(?<=:\/\/|@)([a-z0-9\.]+)(?!.*@)')" # alphanumerals preceded by :// or @, not followed by text@ | |
# extract the port | |
port="$(echo $1 | grep -oP '(?<=:)\d*')" # numbers after : | |
command="$proto " | |
if [ -n "$port" ] | |
then | |
command="${command}-p $port " | |
fi | |
if [ -n "$user" ] | |
then | |
command="${command}${user}@" | |
fi | |
command="${command}$host" | |
/usr/bin/gnome-terminal -q -- zsh -c "$command" | |
# You also need the boolean 'network.protocol-handler.expose.ssh':false in Firefox's about:config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 9 should be
host="$(echo $1 | grep -oP '(?<=:\/\/|@)([a-z0-9\.\-]+)(?!.*@)')" […]
Its regex includes the "-" sign to allow stuff like
ssh://my-supreme-host.my-domain.de
, otherwise the resulting host would be, for example, only "my".