From b36f358d7dd72d4c73e27c2f46e0beb0d477f757 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 25 Nov 2013 13:34:33 -0800 Subject: [PATCH] attach to screens automatically --- zsh/zshrc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zsh/zshrc b/zsh/zshrc index 569a872..a073093 100755 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -347,3 +347,22 @@ compinit if command_exists rbenv; then eval "$(rbenv init -)" fi + + +# 12. Attach to screen +# ==================== +# +# Automatically attach to a screen session. + +function not_in_screen() { + [[ "$STY" = "" ]] && [[ "$SHLVL" = "1" ]] +} + +function is_screen_running() { + NSCREENS="$(screen -ls | egrep 'Attached|Detached' | wc -l)" + [[ "${NSCREENS// /}" != "0" ]] +} + +if is_interactive && command_exists screen && not_in_screen && is_screen_running; then + screen -rx +fi