A simple yet powerful UI overlay made for Wayland WMs built with Quickshell
wayland qs linux ui ux
at main 77 lines 2.0 kB view raw
1#!/usr/bin/env bash 2set -euo pipefail 3 4cmd="${1:-}" 5base_dir="${HOME}/.config/quickshell/m4.shell/ssh" 6conn_db="${base_dir}/connections.db" # name|host|user|port|keypath 7gen_dir="${base_dir}/keys" # generated keys directory 8 9have() { command -v "$1" >/dev/null 2>&1; } 10 11safe_name() { 12 local s="${1:-}" 13 s="$(printf '%s' "$s" | tr -d '\r' | sed -E 's/^[[:space:]]+|[[:space:]]+$//g; s/[[:space:]]+/_/g')" 14 printf '%s' "$s" 15} 16 17ensure_dirs() { 18 mkdir -p "$base_dir" "$gen_dir" >/dev/null 2>&1 || true 19 [ -f "$conn_db" ] || : >"$conn_db" 20} 21 22trim() { 23 printf '%s' "${1:-}" | sed -E 's/^[[:space:]]+|[[:space:]]+$//g' 24} 25 26# --- CONNECTIONS --- 27list_cmd() { 28 ensure_dirs 29 # stable order 30 awk -F'|' 'NF>=2 {print $0}' "$conn_db" 2>/dev/null | sort -t'|' -k1,1 || true 31} 32 33upsert_cmd() { 34 ensure_dirs 35 local name host user port key 36 name="$(safe_name "${1:-}")" 37 host="$(trim "${2:-}")" 38 user="$(trim "${3:-}")" 39 port="$(trim "${4:-}")" 40 key="$(trim "${5:-}")" 41 42 [ -n "$name" ] || { echo "name required" >&2; return 2; } 43 [ -n "$host" ] || { echo "host required" >&2; return 2; } 44 45 # normalize port 46 if [ -z "$port" ]; then port="22"; fi 47 if ! printf '%s' "$port" | grep -Eq '^[0-9]{1,5}$'; then 48 echo "invalid port" >&2 49 return 2 50 fi 51 52 # rewrite file without old entry, then append 53 local tmp 54 tmp="$(mktemp)" 55 awk -F'|' -v n="$name" 'NF==0 {next} $1!=n {print $0}' "$conn_db" >"$tmp" 2>/dev/null || true 56 printf '%s|%s|%s|%s|%s\n' "$name" "$host" "$user" "$port" "$key" >>"$tmp" 57 mv "$tmp" "$conn_db" 58} 59 60del_cmd() { 61 ensure_dirs 62 local name tmp 63 name="$(safe_name "${1:-}")" 64 [ -n "$name" ] || return 0 65 tmp="$(mktemp)" 66 awk -F'|' -v n="$name" 'NF==0 {next} $1!=n {print $0}' "$conn_db" >"$tmp" 2>/dev/null || true 67 mv "$tmp" "$conn_db" 68} 69 70case "$cmd" in 71 list) list_cmd ;; 72 upsert) shift; upsert_cmd "${1:-}" "${2:-}" "${3:-}" "${4:-}" "${5:-}" ;; 73 del) shift; del_cmd "${1:-}" ;; 74 *) 75 exit 0 76 ;; 77esac