From: tfheen Date: Thu, 10 May 2012 07:55:56 +0000 (+0000) Subject: Add vnc function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62fb6a78becefd9be44c401aaaa03981b63e4949;p=dotfiles Add vnc function git-svn-id: file:///svn/tfheen/trunk/dotfiles@1516 8da78d58-1cd3-0310-bee5-d77bd1b3e8bf --- diff --git a/zshfunc/_vnc b/zshfunc/_vnc new file mode 100644 index 0000000..ddc8f5a --- /dev/null +++ b/zshfunc/_vnc @@ -0,0 +1,30 @@ +#compdef vnc + +_vnc () { + local curcontext="$curcontext" state line ret=1 expl + typeset -A opt_args + + _arguments -C -s \ + '*:hosts:->hosts' && ret=0 + + if [[ -n "$state" ]]; then + if compset -P '*@'; then + _wanted hosts expl host _vnc_all_hosts && ret=0 + else + _alternative \ + 'hosts:: _vnc_all_hosts' \ + 'users:: _vnc_users -qS@' && ret=0 + fi + fi + return ret +} + +_vnc_users () { + _tags users && _combination -s '@' my-accounts users-hosts users "$@" +} + +_vnc_all_hosts () { + _tags hosts && _combination -s '@' my-accounts users-hosts hosts "$@" +} + +_vnc "$@" diff --git a/zshfunc/vnc b/zshfunc/vnc new file mode 100755 index 0000000..a0985cd --- /dev/null +++ b/zshfunc/vnc @@ -0,0 +1,17 @@ +# -*- sh -*- +## vim:ft=zsh:foldmethod=marker + +local HOST VM + +if [ $# -lt 2 ]; then + echo "Usage: $0 HOST VM" + return +fi +HOST=$1 +VM=$2 + +LPORT=$(( $RANDOM % 10000 + 5900)) +VNCDISPLAY=$(ssh $HOST "gnt-instance list --no-headers -o name,network_port | awk '/^$VM/ { print \$2 - 5900 } END { exit 1; }' || virsh -c qemu:///system vncdisplay $VM | sed s/://") + +ssh -N -f -L ${LPORT}:localhost:$(( $VNCDISPLAY + 5900 )) $HOST +gvncviewer localhost:$(( $LPORT - 5900 ))