From c35664f7759e8a74019b6a1a9146c4b0e7f23430 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Mon, 25 Mar 2024 15:37:56 +0100 Subject: [PATCH] =?UTF-8?q?qemush=20:=20r=C3=A9=C3=A9criture=20de=20la=20f?= =?UTF-8?q?onction=20`attach`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/qemush | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/qemush b/bin/qemush index efc96ad..704377c 100755 --- a/bin/qemush +++ b/bin/qemush @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# version=0.9.0 +# version=0.10.0 # Re-exec the script as qemu via sudo (only if needed) [ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@" @@ -68,9 +68,19 @@ public_start() { # Attach to a running virtual machine output, the latest opened if no # argument is provided public_attach() { - export QEMUSH_NAME="$1" + export QEMUSH_NAME - exec socat -,rawer,escape=15 "UNIX-CONNECT:$(pathof socket)" + if [ -n "$1" ]; then + QEMUSH_NAME=$1 + socket_path=$(pathof socket) + else + socket_path=$(find ~/sockets/monitors -type s -printf '%T@ %p\n' | sort -r -n | head -1 | cut -d \ -f 2-) + QEMUSH_NAME=$(basename "$socket_path") + fi + + printf 'Attaching to \033[1m%s\033[0m, escape with C-d (EOF)\n' "$QEMUSH_NAME" + socat -,rawer,escape=4 "UNIX-CONNECT:${socket_path}" + echo } # List running virtual machines