feat: migrate ssh menu to Bun/TypeScript

Replace the Bash implementation and jq/yq dependency chain with a Bun-based TypeScript script, add Bun/TypeScript project files, and update docs and sample config notes to match the new CLI and behavior.
This commit is contained in:
2026-06-04 01:45:53 +02:00
parent ba79cedcb1
commit ce563186cb
7 changed files with 315 additions and 203 deletions
+57 -24
View File
@@ -1,6 +1,6 @@
# mtm-ssh-menu
A Bash SSH target picker built around `fzf` and YAML configuration.
A Bun/TypeScript SSH target picker built around `fzf` and YAML configuration.
## What it does
@@ -14,10 +14,9 @@ A Bash SSH target picker built around `fzf` and YAML configuration.
## Requirements
- `bun`
- `ssh`
- `fzf`
- `jq`
- `yq`
## Usage
@@ -25,11 +24,14 @@ A Bash SSH target picker built around `fzf` and YAML configuration.
./mtm-ssh-menu [--config-dir DIR] [-k [user]]
```
The usage shown by the script is `sshm [--config-dir DIR] [-k [user]]`.
Options:
- `-h`, `--help`: show help
- `--config-dir DIR`: use a custom configuration directory
- `-k`, `--known-hosts [user]`: include hosts from `~/.ssh/known_hosts`
- `-c`, `--config-dir DIR`: use a custom configuration directory
- `-k`, `--known-hosts [user]`: include hosts from `~/.ssh/known_hosts` and optionally set the user
- When `-k` is used without a user, the selected entry uses `root`
By default, the script reads configuration from:
@@ -47,14 +49,56 @@ ssh:
default_options: ""
jump_hosts:
office: "user@192.168.10.11"
office-alt: "user@192.168.10.11:2222"
dev: "user@192.168.10.11:2222"
backup: "admin@10.0.0.5:2200"
```
### `hosts/01_prod.yaml`
```yaml
group: prod
servers:
- name: web-1
aliases:
- frontend
- web
host: web-1.prod.internal
jump_host: office
- name: db-1
aliases:
- database
- sql
host: 10.0.0.20
jump_host: office
```
### `hosts/02_staging.yaml`
```yaml
group: staging
servers:
- name: app-1
aliases:
- app
- application
host: staging-app.example.com
user: ubuntu
port: 22
ssh_options: ""
- name: worker-1
aliases:
- worker
host: 10.20.0.15
user: ubuntu
port: 22
```
### `hosts/03_dev.yaml`
```yaml
group: dev
servers:
- name: api-1
aliases:
@@ -73,22 +117,9 @@ servers:
port: 22
```
### `hosts/03_dev.yaml`
```yaml
group: dev
servers:
- name: web-1
aliases:
- frontend
- web
host: web-1.prod.internal
jump_host: office
```
The file name does not need to match the `group` value. The script reads the `group` from the YAML content and uses the file path internally to load the selected host.
The sample configuration now uses numbered file names such as `01_prod.yaml`, `02_staging.yaml`, and `03_dev.yaml`.
The sample configuration uses numbered file names: `01_prod.yaml`, `02_staging.yaml`, and `03_dev.yaml`.
Each host entry can define:
@@ -108,11 +139,13 @@ A complete sample configuration is available in `sample-config/`.
- `jump_host` values are resolved by name from `global.yaml`.
- Jump hosts support `user@host` and `user@host:port`; if the port is omitted, `22` is used.
- If a host does not define a user or port, global defaults are used.
- `default_options` is present in the config but not consumed by the current script.
- The sample config includes `ssh_options` in one file, but the current script does not consume it yet.
- `default_options` is consumed for hosts that do not define their own `options`, and is appended as raw SSH options.
- `ssh_options` appears in the sample config but is not used by the current script; only `options` is read.
- Sample host examples are stored as `sample-config/hosts/01_prod.yaml`, `02_staging.yaml`, and `03_dev.yaml`.
- The `group` key is required for each host config file; the file name is only an internal storage detail.
- When `-k` is used, entries from `known_hosts` are shown with the selected user or `root` by default.
- Known-host entries always use port `22`.
- `known_hosts` entries use port `22`.
- The script uses strict Bash mode (`set -euo pipefail`).
- The script is implemented in Bun and launches `fzf` plus `ssh` from a parsed YAML configuration.
- The current implementation builds the final SSH command as a string and executes it through Bun.
- The script name shown in usage is `sshm`, while the repository file is `mtm-ssh-menu`.