39 lines
1.4 KiB
Markdown
Raw Normal View History

2023-03-03 03:54:46 +00:00
# heidisql-ssh-tunnel
2023-03-03 05:37:39 +01:00
Helper script to spawn SSH tunnels based on HeidiSQL settings
# What's this?
The script assumes you have HeidiSQL directory in `~/'.heidisql` where your `portable_settings.txt` file is living.
It peeks into that file and offers auto-completion based on saved sessions. It creates local SSH tunnels for these sessions.
# Setup
1. Git clone this repo
1. Add a symlink to bash completion script such as:
```
sudo ln -s <repo>/hs ~/.local/share/bash-completion/hs
```
1. Add symlink to script itself and make it executable:
```
sudo ln -s <repo>/hs.sh /usr/local/bin/hs
chmod +x <repo>/hs.sh
```
2023-03-03 05:48:55 +01:00
1. Run:
```
hs <TAB>
```
This will list all HeidiSQL sessions that have `NetType` set to `2` aka `MariaDB or MySQL (SSH tunnel)`. Select one and `hs` creates the necessary tunnel.
2023-03-03 05:37:39 +01:00
# What it looks like
Here with `fzf` as auto-completion helper (optional, is a personal preference):
![Screencast showing hs in action](https://i.imgur.com/FhVFtaR.gif)
2023-03-03 05:48:55 +01:00
> Here `hs` first attempts to set up an SSH tunnel for a HeidiSQL saved session and fails because something's already listening on the local port. We `kill` the connection in question - an SSH tunnel from a prior test - and try again. This time `hs` correctly creates our tunnel. With `set -xv` we see the actual command that gets executed.
2023-03-03 05:37:39 +01:00
>
> Once done we clean up after ourselves and kill SSH tunnels we no longer need.