Compare commits
4
Commits
334d2cbcaf
...
0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0fcd67312 | ||
|
|
b8aa1aaa8d | ||
|
|
dc886c91cc | ||
|
|
7166a8c3dd |
@@ -0,0 +1,10 @@
|
|||||||
|
# Project Memory
|
||||||
|
|
||||||
|
- Project: mtm-ssh-menu
|
||||||
|
- Type: Bash SSH target picker using `fzf` and YAML config.
|
||||||
|
- 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/`.
|
||||||
|
- Documentation language: English.
|
||||||
|
- Current task focus: keep README aligned with the working script and sample configuration.
|
||||||
@@ -1,2 +1,88 @@
|
|||||||
# mtm-ssh-menu
|
# mtm-ssh-menu
|
||||||
|
|
||||||
|
A small Bash utility to browse SSH targets from YAML configuration and connect to them with `fzf`.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- `bash`
|
||||||
|
- `ssh`
|
||||||
|
- `fzf`
|
||||||
|
- `jq`
|
||||||
|
- `yq`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./mtm-ssh-menu [--config-dir DIR]
|
||||||
|
```
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
- `--help`: show help
|
||||||
|
- `--config-dir DIR`: use a custom configuration directory
|
||||||
|
|
||||||
|
By default, the script reads configuration from:
|
||||||
|
|
||||||
|
- `~/.config/mtm-ssh-menu/global.yaml`
|
||||||
|
- `~/.config/mtm-ssh-menu/hosts/*.yaml`
|
||||||
|
|
||||||
|
## Configuration format
|
||||||
|
|
||||||
|
### `global.yaml`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
ssh:
|
||||||
|
default_user: root
|
||||||
|
default_port: 22
|
||||||
|
default_options: ""
|
||||||
|
jump_hosts:
|
||||||
|
office: "user@192.168.10.11"
|
||||||
|
```
|
||||||
|
|
||||||
|
### `hosts/dev.yaml`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
group: dev
|
||||||
|
servers:
|
||||||
|
- name: api-1
|
||||||
|
aliases:
|
||||||
|
- api
|
||||||
|
- backend
|
||||||
|
host: 192.168.10.11
|
||||||
|
user: dev
|
||||||
|
port: 2222
|
||||||
|
```
|
||||||
|
|
||||||
|
Each host entry can define:
|
||||||
|
|
||||||
|
- `name`
|
||||||
|
- `aliases`
|
||||||
|
- `host`
|
||||||
|
- `user`
|
||||||
|
- `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`.
|
||||||
|
- If a host does not define a user or port, global defaults are used.
|
||||||
|
|||||||
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}"
|
||||||
+1
-1
@@ -94,7 +94,7 @@ load_config() {
|
|||||||
SSH_SERVER_ALIASES=$(jq -r '.'"[$i]"'.aliases // ""' <<<"$GROUP_SERVERS")
|
SSH_SERVER_ALIASES=$(jq -r '.'"[$i]"'.aliases // ""' <<<"$GROUP_SERVERS")
|
||||||
SSH_SERVER_HOST=$(jq -r '.'"[$i]"'.host // ""' <<<"$GROUP_SERVERS")
|
SSH_SERVER_HOST=$(jq -r '.'"[$i]"'.host // ""' <<<"$GROUP_SERVERS")
|
||||||
SSH_SERVER_PORT=$(jq -r '.'"[$i]"'.port // "'"$DEFAULT_SSH_PORT"'"' <<<"$GROUP_SERVERS")
|
SSH_SERVER_PORT=$(jq -r '.'"[$i]"'.port // "'"$DEFAULT_SSH_PORT"'"' <<<"$GROUP_SERVERS")
|
||||||
SSH_SERVER_USER=$(jq -r '.'"[$i]"'.port // "'"$DEFAULT_SSH_USER"'"' <<<"$GROUP_SERVERS")
|
SSH_SERVER_USER=$(jq -r '.'"[$i]"'.user // "'"$DEFAULT_SSH_USER"'"' <<<"$GROUP_SERVERS")
|
||||||
if [ "$SSH_SERVER_ALIASES" != "" ]; then
|
if [ "$SSH_SERVER_ALIASES" != "" ]; then
|
||||||
# shellcheck disable=SC2027
|
# shellcheck disable=SC2027
|
||||||
ALIASES="("$(echo "$SSH_SERVER_ALIASES" | jq -r 'join(", ")')")"
|
ALIASES="("$(echo "$SSH_SERVER_ALIASES" | jq -r 'join(", ")')")"
|
||||||
|
|||||||
Reference in New Issue
Block a user