matryer / xbar-plugins

Plugin repository for xbar (the BitBar reboot)
https://xbarapp.com
2.46k stars 1.04k forks source link

re: SSH open in iterm2 (instead of Mac terminal)? #262

Closed drewda closed 8 years ago

drewda commented 8 years ago

Using the SSH plug-in (https://getbitbar.com/plugins/Network/ssh.sh ) would it be possible to open sessions in iTerm2, rather than the default Mac terminal?

FAO: (@thameera)

iosdeveloper commented 8 years ago

See matryer/bitbar#175

drewda commented 8 years ago

Thanks @iosdeveloper

iosdeveloper commented 8 years ago

In the short term, you can set iTerm to handle ssh:// URLs. You can then use open.

From https://www.iterm2.com/faq.html :

Q: How do I set iTerm2 as the handler for ssh:// links?

A: Two steps:

Create a new profile called "ssh". In the General tab, select the Command: button and enter $$ as the command. In Preferences->Profiles->General, select "ssh" for "Select URL Schemes...."

iosdeveloper commented 8 years ago

So

print $2" | bash=ssh param1="$2

becomes

print $2" | bash=open param1=ssh://"$2" terminal=false".

loneops commented 8 years ago

With terminal=false, you need to invoke open with its absolute path.

bash=/usr/bin/open param1=ssh://"$2" terminal=false"

freeyland commented 5 years ago

Hi,

This does not seems to work anymore. It first opens terminal and the Iterm

gingerbeardman commented 5 years ago

@freeyland please post your full script here

freeyland commented 5 years ago

Please forget about it. Code for other people:

if [[ "$2" = "sshconnect" ]]; then
osascript - "ssh $1" <<EOF
on run argv
tell application "iTerm2"
  tell current session of current window
    split horizontally with default profile command argv
  end tell
  tell current session
    set name to "Console"
  end tell
end tell
end run
EOF
    exit
fi

echo " SSH |"
echo "---"

function hosts() {
    awk '
        $1 == "Host" {
            host = $2;
            next;
        }
        $1 == "HostName" {
            print host;
        }
    ' "$1"
}

for h in $(hosts ~/.ssh/config); do

    A="$(cut -d'/' -f2 <<<"${h}")"
    B="$(cut -d'/' -f1 <<<"${h}")"
    C="$(cut -d'/' -f3 <<<"${h}")"
    if [[ "$C" != "" ]]; then
        if [[ "$B" != "$prevB" ]]; then
            echo "$B"
        fi
        if [[ "$A" != "$prevA" ]]; then
            echo "-- $A"
        fi
        echo "---- $C | bash='$0' param1=${h} param2='sshconnect' param3='$C' terminal=false"
        prevA=$A
        prevB=$B
    else
        if [[ "$B" != "$prevB" ]]; then
            echo "$B"
        fi
        echo "-- $A | bash='$0' param1=${h} param2='sshconnect' param3='$A' terminal=false"
        prevA=$A
        prevB=$B
    fi
done