Compare commits
5
Commits
dc886c91cc
..
0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8650b71c3c | ||
|
|
59f37d8455 | ||
|
|
ccd38c5e31 | ||
|
|
c0fcd67312 | ||
|
|
b8aa1aaa8d |
+2
-2
@@ -5,6 +5,6 @@
|
||||
- Main entry point: `mtm-ssh-menu`
|
||||
- Configuration: `~/.config/mtm-ssh-menu/global.yaml` and `hosts/*.yaml` by default.
|
||||
- Dependencies: `bash`, `ssh`, `fzf`, `jq`, `yq`.
|
||||
- Sample config is stored in `sample-config/`.
|
||||
- Sample config is stored in `sample-config/` and mirrors current script behavior.
|
||||
- Documentation language: English.
|
||||
- Current task focus: keep README aligned with the working script and sample configuration.
|
||||
- Current task focus: keep README and memory aligned with the working script and sample configuration.
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
# mtm-ssh-menu
|
||||
|
||||
A small Bash utility to browse SSH targets from YAML configuration and connect to them with `fzf`.
|
||||
A Bash SSH target picker built around `fzf` and YAML configuration.
|
||||
|
||||
## Features
|
||||
## What it does
|
||||
|
||||
- Interactive selection with `fzf`
|
||||
- Global defaults for SSH user, port, and jump hosts
|
||||
- Per-host overrides in grouped YAML files
|
||||
- Support for jump hosts via named aliases
|
||||
- Simple, dependency-light Bash script
|
||||
- Lists SSH targets from grouped YAML files
|
||||
- Supports global defaults for user, port, and jump hosts
|
||||
- Supports per-host overrides
|
||||
- Can also browse entries from `~/.ssh/known_hosts`
|
||||
- Launches `ssh` directly from the selected entry
|
||||
|
||||
## Requirements
|
||||
|
||||
- `bash`
|
||||
- `ssh`
|
||||
- `fzf`
|
||||
- `jq`
|
||||
@@ -21,13 +20,14 @@ A small Bash utility to browse SSH targets from YAML configuration and connect t
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
./mtm-ssh-menu [--config-dir DIR]
|
||||
./mtm-ssh-menu [--config-dir DIR] [-k [user]]
|
||||
```
|
||||
|
||||
Options:
|
||||
|
||||
- `--help`: show help
|
||||
- `-h`, `--help`: show help
|
||||
- `--config-dir DIR`: use a custom configuration directory
|
||||
- `-k`, `--known-hosts [user]`: include hosts from `~/.ssh/known_hosts`
|
||||
|
||||
By default, the script reads configuration from:
|
||||
|
||||
@@ -59,6 +59,27 @@ servers:
|
||||
host: 192.168.10.11
|
||||
user: dev
|
||||
port: 2222
|
||||
|
||||
- name: web-1
|
||||
aliases:
|
||||
- frontend
|
||||
- ui
|
||||
host: 192.168.10.12
|
||||
user: dev
|
||||
port: 22
|
||||
```
|
||||
|
||||
### `hosts/prod.yaml`
|
||||
|
||||
```yaml
|
||||
group: prod
|
||||
servers:
|
||||
- name: web-1
|
||||
aliases:
|
||||
- frontend
|
||||
- web
|
||||
host: web-1.prod.internal
|
||||
jump_host: office
|
||||
```
|
||||
|
||||
Each host entry can define:
|
||||
@@ -70,19 +91,17 @@ Each host entry can define:
|
||||
- `port`
|
||||
- `jump_host`
|
||||
|
||||
## Example workflow
|
||||
|
||||
1. Create the config directory.
|
||||
2. Add `global.yaml` and one or more files under `hosts/`.
|
||||
3. Run the script.
|
||||
4. Select a target in the menu and connect.
|
||||
|
||||
## Sample configuration
|
||||
|
||||
A complete sample configuration is available in `sample-config/`.
|
||||
|
||||
## Notes
|
||||
|
||||
- The script requires `yq`, `jq`, `ssh`, and `fzf` to be installed.
|
||||
- Jump hosts are resolved by name from `global.yaml`.
|
||||
- `jump_host` values are resolved by name from `global.yaml`.
|
||||
- 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.
|
||||
- When `-k` is used, entries from `known_hosts` are shown with the selected user or `root` by default.
|
||||
- `known_hosts` entries use port `22`.
|
||||
- The script uses strict Bash mode (`set -euo pipefail`).
|
||||
- The script name shown in usage is `sshm`, while the repository file is `mtm-ssh-menu`.
|
||||
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
declare -r VERSION=${1:-}
|
||||
declare -r MESSAGE=${2:-"Release ${VERSION}"}
|
||||
declare -r TAGBRANCH=main
|
||||
declare -r RELEASEBRANCH=dev
|
||||
declare CURRENTBRANCH=""
|
||||
|
||||
showHelp() {
|
||||
echo "Usage: ./_release.sh <version> [message]"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if [ -n "${CURRENTBRANCH}" ] && [ "${CURRENTBRANCH}" != "$(git rev-parse --abbrev-ref HEAD)" ]; then
|
||||
git checkout "${CURRENTBRANCH}" >/dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
if [ "${VERSION}" == "" ]; then
|
||||
showHelp
|
||||
echo ""
|
||||
echo "No version provided!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
if [ "${CURRENTBRANCH}" != "${RELEASEBRANCH}" ]; then
|
||||
echo "You are not on the ${RELEASEBRANCH} branch!"
|
||||
echo "Use ${RELEASEBRANCH} branch to make a release!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||
echo "Working tree is not clean. Commit or stash your changes first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if git rev-parse -q --verify "refs/tags/${VERSION}" >/dev/null; then
|
||||
echo "Tag ${VERSION} already exists."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git push
|
||||
git checkout "${TAGBRANCH}"
|
||||
git merge "${RELEASEBRANCH}"
|
||||
git push origin "${TAGBRANCH}"
|
||||
git tag -a "${VERSION}" -m "${MESSAGE}"
|
||||
git push origin "${VERSION}"
|
||||
+34
-4
@@ -2,14 +2,17 @@
|
||||
set -euo pipefail
|
||||
|
||||
CONFIG_DIR="$HOME/.config/mtm-ssh-menu"
|
||||
USE_KNOWN_HOSTS=0
|
||||
USE_KNOWN_HOSTS_USER="root"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: sshm [--config-dir DIR]
|
||||
Usage: sshm [--config-dir DIR] [-k [user]]
|
||||
|
||||
Options:
|
||||
--help Show this help message
|
||||
-h | --help Show this help message
|
||||
--config-dir DIR Use a custom config directory
|
||||
-k | --known-hosts [user] Include known_hosts
|
||||
|
||||
The config directory must contain:
|
||||
- global.yaml
|
||||
@@ -28,6 +31,16 @@ parse_args() {
|
||||
CONFIG_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--known-hosts|-k)
|
||||
USE_KNOWN_HOSTS=1
|
||||
if [ $# -eq 1 ]; then
|
||||
USE_KNOWN_HOSTS_USER="root"
|
||||
shift
|
||||
else
|
||||
USE_KNOWN_HOSTS_USER="$2"
|
||||
shift 2
|
||||
fi
|
||||
;;
|
||||
--help|-h)
|
||||
usage
|
||||
exit 0
|
||||
@@ -109,15 +122,27 @@ load_config() {
|
||||
done
|
||||
shopt -u nullglob
|
||||
}
|
||||
load_known_hosts() {
|
||||
local FILE_CONTENT GROUP_NAME
|
||||
FILE_CONTENT=$(cat "$HOME"/.ssh/known_hosts | awk -F ' ' '{print $1}' | sort | awk '!seen[$1]++')
|
||||
GROUP_NAME="Local"
|
||||
for host in $FILE_CONTENT; do
|
||||
if [ "$SERVERS" != "" ]; then
|
||||
SERVERS+="\n"
|
||||
fi
|
||||
SERVERS+="${GROUP_NAME} | ${host} | ${host} | ${host} | ${USE_KNOWN_HOSTS_USER} | 22"
|
||||
done
|
||||
}
|
||||
popup_menu() {
|
||||
local SERVER
|
||||
SERVER=$(echo -e "${SERVERS}" | column -t -s "|" -o "|" | fzf -e --tac --with-nth=1,3,4,5,6 --delimiter="|")
|
||||
SERVER=$(echo -e "${SERVERS}" | column -t -s "|" -o "|" | fzf -e --layout=reverse --with-nth=1,3,4,5,6 --delimiter="|")
|
||||
local GROUP_NAME HOST_INDEX
|
||||
GROUP_NAME=$(echo "$SERVER" | awk -F '|' '{print $1}' | xargs)
|
||||
HOST_INDEX=$(echo "$SERVER" | awk -F '|' '{print $2}' | xargs)
|
||||
ssh_connect "$GROUP_NAME" "$HOST_INDEX"
|
||||
}
|
||||
ssh_connect() {
|
||||
if [[ "$HOST_INDEX" != *"."* ]]; then
|
||||
local SERVER SSH_SERVER_USER SSH_SERVER_HOST SSH_SERVER_PORT SSH_SERVER_OPTIONS SSH_JUMP_HOST
|
||||
SERVER=$(cat "$HOSTS_DIR/$1.yaml" | yq -r '.servers'"[$2]")
|
||||
SSH_SERVER_USER=$(jq -r '.user // "'"$DEFAULT_SSH_USER"'"' <<<"$SERVER")
|
||||
@@ -132,13 +157,18 @@ ssh_connect() {
|
||||
SSH_SERVER_OPTIONS=""
|
||||
fi
|
||||
|
||||
#echo "ssh ${SSH_SERVER_OPTIONS} ${SSH_JUMP_HOST} ${SSH_SERVER_USER}@${SSH_SERVER_HOST}"
|
||||
# shellcheck disable=SC2086
|
||||
ssh ${SSH_SERVER_OPTIONS} ${SSH_JUMP_HOST} "${SSH_SERVER_USER}"@"${SSH_SERVER_HOST}"
|
||||
else
|
||||
ssh "${USE_KNOWN_HOSTS_USER}"@"${2}"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
load_config
|
||||
if [ "$USE_KNOWN_HOSTS" == 1 ]; then
|
||||
load_known_hosts
|
||||
fi
|
||||
popup_menu
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user