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