aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatherine <shmibs@shmibbles.me>2016-01-14 10:39:53 +0000
committerkatherine <shmibs@shmibbles.me>2016-01-14 10:39:53 +0000
commitf4cb82b99daf3e2f848a504b4acfe809a7ae5970 (patch)
tree74faa090a51ba5cbff3a51560f1d56b7fb7d2ba3
parentc0255be3de8e984106881ad8955bc14774e4cc21 (diff)
downloaddotfiles-f4cb82b99daf3e2f848a504b4acfe809a7ae5970.tar.gz
remote session with dtach
-rw-r--r--.zprofile5
-rw-r--r--.zprofile-dtach57
-rw-r--r--.zshrc5
-rw-r--r--.zshrc-remote59
4 files changed, 62 insertions, 64 deletions
diff --git a/.zprofile b/.zprofile
index 1fdd034..b1f3b26 100644
--- a/.zprofile
+++ b/.zprofile
@@ -1,3 +1,8 @@
emulate sh -c 'source /etc/profile'
export QT_STYLE_OVERRIDE=gtk
+
+############# CONNECTING OVER SSH #############
+if [[ -a ~/.zprofile-dtach ]]; then
+ source ~/.zprofile-dtach
+fi
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
diff --git a/.zshrc b/.zshrc
index cb7c0a6..35f8cda 100644
--- a/.zshrc
+++ b/.zshrc
@@ -112,8 +112,3 @@ case $(uname) in
*)
echo -e '[-- OS UNRECOGNISED --]'
esac
-
-############# CONNECTING OVER SSH #############
-if [[ -a ~/.zshrc-remote ]]; then
- source ~/.zshrc-remote
-fi
diff --git a/.zshrc-remote b/.zshrc-remote
deleted file mode 100644
index 98ac9d6..0000000
--- a/.zshrc-remote
+++ /dev/null
@@ -1,59 +0,0 @@
-if [[ $TERM != "screen" ]]; then
- tmux has-session 2>/dev/null
- if [[ "$?" != "0" ]]; then
- tmux
- fi
-
- tmux has-session 2>/dev/null
- if [[ "$?" != "0" ]]; then
- logout
- fi
-
- {
- while true; do
- tmux has-session 2>/dev/null
- if [[ "$?" != "0" ]]; then
- logout
- fi
-
- echo ""
- tmux list-sessions
-
- echo -n "> "
- read -A args
- case "${args[1]}" in
- a)
- if [[ "${args[2]}" != "" ]]; then
- tmux has-session -t "${args[2]}"
- if [[ "$?" == "0" ]]; then
- tmux attach-session -t "${args[2]}"
- fi
- fi
- ;;
-
- k)
- if [[ "${args[2]}" != "" ]]; then
- tmux has-session -t "${args[2]}"
- if [[ "$?" == "0" ]]; then
- tmux kill-session -t "${args[2]}"
- fi
- fi
- ;;
-
- n)
- tmux new-session
- ;;
-
- q)
- break;
- ;;
-
- *)
- ;;
- esac
-
- done
- }
-
- logout
-fi