How to add SSH menu to Unity launcher

I am currently using latest Ubuntu on Dell XPS 13. It works great and using it is a real pleasure. However, after a while I got an idea to add simple SSH menu to Unity launcher for enhanced usability.

Shell script

Create shell script to generate and display list of available SSH servers using zenity utility and ~/.ssh/config user configuration file.

#!/bin/sh
# Create menu for SSH servers using zenity utility

# get SSH servers
ssh_servers=$(awk '/^Host / {print $2}' ~/.ssh/config)

# print SSH menu
server=$(echo "$ssh_servers" | zenity --list --title "Quick SSH menu" --text "Choose SSH server"  --column "Server" 2>/dev/null)

# execute action
gnome-terminal --command "ssh $server"

Store it as ~/bin/create_ssh_menu.sh file and set executable bit.

Desktop file

Create desktop entry file to use above-mentioned shell script and define additional quickly accessible menu.

[Desktop Entry]
Version=1.0
Type=Application
Name=SSH servers 
Icon=application-x-remote-connection
Exec=/home/milosz/bin/create_ssh_menu.sh
Terminal=false
Categories=Network;
Actions=ServerA;ServerB;ServerC;ServerD;

[Desktop Action ServerA]
Name=Connect to router at home
Exec=gnome-terminal -e "ssh -l root 192.168.0.254"
OnlyShowIn=Unity;

[Desktop Action ServerB]
Name=Connect to knowledge base at home
Exec=gnome-terminal -e "ssh 192.168.0.200"
OnlyShowIn=Unity;

[Desktop Action ServerC]
Name=Connect to OSMC at home
Exec=gnome-terminal -e "ssh -l pi 192.168.0.201"
OnlyShowIn=Unity;

[Desktop Action ServerD]
Name=Connect to web server
Exec=gnome-terminal -e "ssh blog.sleeplessbeastie.eu"
OnlyShowIn=Unity;

Store it as ~/.local/share/ssh_menu.desktop file and use desktop-file-validate command to validate its contents.

Do not forget to update path to the shell script.

Unity launcher

The last step is to add created desktop entry file to the Unity launcher. You can do this by hand (drag file to launcher) or just execute following command.

$ gsettings set com.canonical.Unity.Launcher favorites \
  "$(gsettings get com.canonical.Unity.Launcher favorites | \
     sed "s|\]|,'application://ssh_menu.desktop'&|")"

References

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu