#!/usr/bin/fish
{{ ansible_managed | comment }}

{% if workspaces[workspace].type == "tmux" %}

exec urxvt -title tmux-workspace -e fish -c 'ssh -t {{workspaces[workspace].host}} tmux attach -d -t {{workspaces[workspace].session}}'

{% elif "vncviewer" in workspaces[workspace].type %}

{% if workspaces[workspace].fetch_vnc_passsword_file | default(false) %}
if not test -d ~/.vnc/passwd.{{workspaces[workspace].host}}
  rsync {{workspaces[workspace].host}}:~/.vnc/passwd ~/.vnc/passwd.{{workspaces[workspace].host}}
end
{% endif %}

{% if workspaces[workspace].type == "vncviewer-ssh-socket" %}

socat "UNIX-LISTEN:.vnc/socket.{{workspaces[workspace].host}},reuseaddr" EXEC:'ssh {{workspaces[workspace].host}} socat STDIO UNIX-CONNECT\:.vnc/socket' &
exec xtigervncviewer .vnc/socket.{{workspaces[workspace].host}}

{% elif workspaces[workspace].type == "vncviewer-ssh-tcp" %}

exec xtigervncviewer localhost:{{workspaces[workspace].display|default(home_vncserver_display_number)}} -via {{workspaces[workspace].host}} -PasswordFile ~/.vnc/passwd.{{workspaces[workspace].host}}

{% endif %}
{% endif %}
