diff options
author | katherine <shmibs@shmibbles.me> | 2016-01-14 10:39:53 +0000 |
---|---|---|
committer | katherine <shmibs@shmibbles.me> | 2016-01-14 10:39:53 +0000 |
commit | f4cb82b99daf3e2f848a504b4acfe809a7ae5970 (patch) | |
tree | 74faa090a51ba5cbff3a51560f1d56b7fb7d2ba3 /.zprofile-dtach | |
parent | c0255be3de8e984106881ad8955bc14774e4cc21 (diff) | |
download | dotfiles-f4cb82b99daf3e2f848a504b4acfe809a7ae5970.tar.gz |
remote session with dtach
Diffstat (limited to '.zprofile-dtach')
-rw-r--r-- | .zprofile-dtach | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/.zprofile-dtach b/.zprofile-dtach new file mode 100644 index 0000000..6f57ef7 --- /dev/null +++ b/.zprofile-dtach @@ -0,0 +1,57 @@ +if [[ -z "${DTACH_SUB}" ]]; then +{ + setopt NULL_GLOB + + while true; do + set -- /tmp/dtach* + if [[ "$#" -gt 0 ]]; then + # session exists, so show the menu + { + while true; do + set -- /tmp/dtach* + if [[ "$#" -eq 0 ]]; then + # logout if all sessions terminated + clear + logout + fi + + # list sessions + set -- /tmp/dtach* + if [[ "$#" -gt 0 ]]; then + ls /tmp/dtach* | sed 's/\/tmp\/dtach-//g' + fi + + echo -n "> " + read -A args + case "${args[1]}" in + q) + break; + ;; + + *) + if [[ "${args[1]}" != "q" ]]; then + DTACH_SUB=true dtach -A "/tmp/dtach-${args[1]}" -z zsh + clear + fi + ;; + esac + + done + } + + clear + logout + else + # create the main session + DTACH_SUB=true dtach -A /tmp/dtach-1 -z zsh + clear + set -- /tmp/dtach* + if [[ "$#" -eq 0 ]]; then + # logout if all sessions terminated + clear + logout + fi + fi + done +} +fi |