From bb9bd2f72fe00adbffb275f6998e31aa3088b57c Mon Sep 17 00:00:00 2001 From: maudin Date: Mon, 21 Nov 2022 17:38:39 +0100 Subject: [PATCH] ssh-menu initial release --- .gitignore | 1 + README.md | 13 +++++++++++++ install | 22 ++++++++++++++++++++++ rofi-config | 8 ++++++++ rofi-forge-cache | 7 +++++++ ssh-menu | 12 ++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 install create mode 100644 rofi-config create mode 100755 rofi-forge-cache create mode 100755 ssh-menu diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93a5f70 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +rofi-forge-cache-own \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bca70e8 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +ssh-menu +======== + +SSH menu using rofi and forging cache file. By default, it will search for host files named after target hosts in `$INFRA/host/` directory. + +You can: +- copy `rofi-forge-cache` as `rofi-forge-cache-own` and adapt to your needs +- copy `rofi-config` as `rofi-config-own` and adapt to your needs +- install with `./install` (will only act on `~/.ssh-menu/` directory) and run with `./ssh-menu`. + +Tips: +- you can add ssh options by setting SSH_OPTIONS variable (for example `SSH_OPTIONS=-A ./ssh-menu` will forward SSH agent) +- SSH agent is not loaded by default, I use `keychain` variables set in `~/.keychain/$(hostname)-sh`, adapt to your agent handling method diff --git a/install b/install new file mode 100755 index 0000000..0d6268e --- /dev/null +++ b/install @@ -0,0 +1,22 @@ +#! /bin/bash + +if [ ! -e /usr/bin/rofi ]; then + echo "error: rofi doesn't seem to be installed" + exit 1 +fi + +mkdir -p ~/.ssh-menu + +# Install rofi-config-own or default rofi-config +if [ -e rofi-config-own ]; then + cp rofi-config-own ~/.ssh-menu/rofi-config +else + cp rofi-config ~/.ssh-menu/rofi-config +fi + +# Install rofi-forge-cache-own script or default rofi-forge-cache +if [ -e rofi-forge-cache-own ]; then + cp rofi-forge-cache-own ~/.ssh-menu/rofi-forge-cache +else + cp rofi-forge-cache ~/.ssh-menu/rofi-forge-cache +fi diff --git a/rofi-config b/rofi-config new file mode 100644 index 0000000..e9dfd88 --- /dev/null +++ b/rofi-config @@ -0,0 +1,8 @@ +configuration { + font: "DejaVu Sans Mono 10"; + terminal: "kitty"; + ssh-client: "ssh ${SSH_OPTIONS}"; + ssh-command: "{terminal} -e sh -c \". ~/.keychain/$(hostname)-sh && {ssh-client} {host}\""; + sidebar-mode: true; +} +@theme "sidebar" diff --git a/rofi-forge-cache b/rofi-forge-cache new file mode 100755 index 0000000..74ceeb1 --- /dev/null +++ b/rofi-forge-cache @@ -0,0 +1,7 @@ +#! /bin/bash + +# Clean cache +echo -n > ~/.cache/rofi-2.sshcache + +# Look for hostfiles named after target names in $INFRA/host/ +ls ${INFRA}/host/ | sed "s/^/1 root@/" >> ~/.cache/rofi-2.sshcache diff --git a/ssh-menu b/ssh-menu new file mode 100755 index 0000000..1683a3f --- /dev/null +++ b/ssh-menu @@ -0,0 +1,12 @@ +#! /bin/bash + +# Generate ~/.cache/rofi-2.sshcache +if [ -x ~/.ssh-menu/rofi-forge-cache ]; then + ~/.ssh-menu/rofi-forge-cache +else + echo "error: ~/.ssh-menu/rofi-forge-cache doesn't exist or can't be executed" + exit 1 +fi + +# Launch rofi +rofi -lines 50 -modi ssh -show ssh -config ~/.ssh-menu/rofi-config