From 458847c4af0b97802c02445d2b664a6aeebe826f Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Mon, 20 Oct 2025 19:17:11 +0200 Subject: [PATCH] add new bins --- config/shared/bin/con | 135 +++++++++++++++++++++++++++++ config/shared/bin/sync_theme | 23 +++++ config/shared/bin/vm-switch-daemon | 11 +++ config/shared/bin/vmlist-sync | 3 + config/shared/bin/work | 10 +++ 5 files changed, 182 insertions(+) create mode 100755 config/shared/bin/con create mode 100755 config/shared/bin/sync_theme create mode 100755 config/shared/bin/vm-switch-daemon create mode 100755 config/shared/bin/vmlist-sync create mode 100755 config/shared/bin/work diff --git a/config/shared/bin/con b/config/shared/bin/con new file mode 100755 index 0000000..d8657d6 --- /dev/null +++ b/config/shared/bin/con @@ -0,0 +1,135 @@ +#!/usr/bin/env bash +set -euo pipefail + +ATTACH_TMUX=1 +DRY_RUN=0 +TMUX_SESSION_DEFAULT="default" + +df_platform="" +df_namespace="" +df_user="" + +ssh_identity="" +ssh_host="" +ssh_args=() + +usage() { + local prog + prog=$(basename "$0") + echo "Usage: $prog [user@]namespace [--no-tmux|-t] [--dry-run|-n] [-- ]" >&2 + echo + echo "Examples:" + echo " $prog orb namespace" + echo " $prog utm user@namespace --no-tmux" + echo " $prog core user@namespace --dry-run -- -v -p 2222" + exit 1 +} + +parse_args() { + if [[ $# -lt 2 ]]; then + usage + fi + + df_platform="$1" + local user_namespace_arg="$2" + shift 2 + + # Extract df_user and df_namespace + if [[ "$user_namespace_arg" == *@* ]]; then + df_user="${user_namespace_arg%@*}" + df_namespace="${user_namespace_arg#*@}" + else + df_user="$USER" + df_namespace="$user_namespace_arg" + fi + + # Parse remaining flags and ssh args + while [[ $# -gt 0 ]]; do + case "$1" in + -t|--no-tmux) + ATTACH_TMUX=0 + shift + ;; + -n|--dry-run) + DRY_RUN=1 + shift + ;; + --) + shift + ssh_args+=("$@") + break + ;; + *) + echo "Unknown option: $1" >&2 + usage + ;; + esac + done +} + +resolve_host() { + case "$df_platform" in + orb) + # orb-stack handles user@namespace internally + ssh_host="${df_namespace}@orb" + ;; + utm) + ssh_host="${df_namespace}.utm.local" + ssh_identity="$HOME/.ssh/id_ed25519_internal" + ;; + core) + ssh_host="${df_namespace}.core.lan" + ssh_identity="$HOME/.ssh/id_ed25519_internal" + ;; + ec2) + ssh_host="${df_namespace}.ec2.internal" + ;; + hetzner) + ssh_host="${df_namespace}.hetzner.test" + ;; + *) + echo "Error: unknown platform '$df_platform'" >&2 + exit 1 + ;; + esac +} + +build_ssh_cmd() { + local cmd=(ssh -tt) + + if [[ -n "$ssh_identity" ]]; then + cmd+=(-i "$ssh_identity" -o IdentitiesOnly=yes) + fi + + if [[ ${#ssh_args[@]} -gt 0 ]]; then + cmd+=("${ssh_args[@]}") + fi + + cmd+=("${df_user}@${ssh_host}") + + if [[ $ATTACH_TMUX -eq 1 ]]; then + cmd+=("tmux" "new-session" "-As" "$TMUX_SESSION_DEFAULT" + "-e" "DF_NAMESPACE=$df_namespace" + "-e" "DF_PLATFORM=$df_platform") + fi + + echo "${cmd[@]}" +} + +main() { + parse_args "$@" + resolve_host + ssh_cmd=($(build_ssh_cmd)) + + if [[ $DRY_RUN -eq 1 ]]; then + echo "Dry run command:" + printf '%q ' "${ssh_cmd[@]}" + echo + exit 0 + fi + + exec "${ssh_cmd[@]}" +} + +main "$@" + diff --git a/config/shared/bin/sync_theme b/config/shared/bin/sync_theme new file mode 100755 index 0000000..4c2ab2a --- /dev/null +++ b/config/shared/bin/sync_theme @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +# URL="https://raw.githubusercontent.com/triimdev/invero.nvim/refs/heads/main/extras/ghostty/invero_day" +# THEME_DIR="$HOME/.config/ghostty/themes" +# THEME_NAME="Invero Day" + +URL="https://raw.githubusercontent.com/triimdev/invero.nvim/refs/heads/main/extras/wezterm/invero_day.toml" +THEME_DIR="$HOME/.config/wezterm/colors" +THEME_NAME="Invero Day.toml" + + +THEME_PATH="${THEME_DIR}/${THEME_NAME}" + +mkdir -p "$THEME_DIR" + +if curl -fsSL -o "$THEME_PATH" "$URL"; then + echo "Theme downloaded to $THEME_PATH" +else + echo "Failed to download theme." + exit 1 +fi + diff --git a/config/shared/bin/vm-switch-daemon b/config/shared/bin/vm-switch-daemon new file mode 100755 index 0000000..df6a6d4 --- /dev/null +++ b/config/shared/bin/vm-switch-daemon @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +file=/tmp/vm-switch.txt + +# Ensure the file exists +touch "$file" + +echo "Listening on $file ..." +tail -n0 -F "$file" | while read vm; do + [ -n "$vm" ] && echo "Switch requested: $vm" && ~/bin/work "$vm" & +done + diff --git a/config/shared/bin/vmlist-sync b/config/shared/bin/vmlist-sync new file mode 100755 index 0000000..8557cff --- /dev/null +++ b/config/shared/bin/vmlist-sync @@ -0,0 +1,3 @@ +#!/bin/sh +orbctl list > /tmp/vmlist.txt + diff --git a/config/shared/bin/work b/config/shared/bin/work new file mode 100755 index 0000000..f104f06 --- /dev/null +++ b/config/shared/bin/work @@ -0,0 +1,10 @@ +#!/bin/sh +# Usage: work +vm="$1" +if [ -z "$vm" ]; then + echo "Usage: work " + exit 1 +fi + +exec vm "${vm}-orb" +