diff --git a/.bash_profile b/.bash_profile index 2a1d936..887a3ed 100644 --- a/.bash_profile +++ b/.bash_profile @@ -38,13 +38,9 @@ unset PLATFORM # Screen. hash screen >/dev/null 2>&1 && { - # Reattach existing screens. - screen_attach - - # Output some screen info. export SCREENDIR="$HOME/.screen-${HOSTNAME%%.*}" - if [[ ! -e ~/.hushlogin ]]; then - if [[ ! -z "$STY" ]]; then + if [[ -n "$SSH_TTY" ]]; then + if [[ -n "$STY" ]]; then echo "Screen $STY, window $WINDOW." echo else @@ -58,6 +54,33 @@ hash screen >/dev/null 2>&1 && { fi unset SCREENS fi + elif [[ -n "$STY" ]]; then + echo "Screen $STY, window $WINDOW." + echo + else + TTY="$(tty | cut -d/ -f3-)" + SCREENS="$(screen -list | fgrep "${HOSTNAME%%.*}" | fgrep "${TTY//\//-}")" + case "$(echo "${SCREENS:--n}" | wc -l)" in + 0) + # No screens found - start a new instance. + screen + ;; + 1) + # Just one screen - reconnect if it's not dead. + if (( $(echo "$SCREENS" | grep "Dead" | wc -l) == 1 )); then + echo "Found dead screen for $TTY:" + echo "$SCREENS" | sed -e 's/^/ /g' + else + screen -dr "${TTY//\//-}.${HOSTNAME%%.*}" + fi + ;; + *) + # Multiple screens - output a list + echo "Multiple screens found for $TTY:" + echo "$SCREENS" | sed -e 's/^/ /g' + ;; + esac + unset SCREENS fi } diff --git a/.bashrc b/.bashrc index cfb2dc2..d5c8fd4 100644 --- a/.bashrc +++ b/.bashrc @@ -1,28 +1,3 @@ -# Functions. -screen_attach() { - local TTY SCREENS - # Only continue if it's not a remote connection, and not inside screen already. - [[ -z "$SSH_TTY" ]] && [[ -z "$STY" ]] && { - TTY="$(tty | cut -d/ -f3-)" - SCREENS="$(screen -list | fgrep -v "Dead" | fgrep "${HOSTNAME%%.*}" | fgrep "${TTY//\//-}")" - case "$(echo "${SCREENS:--n}" | wc -l)" in - 0) - # No screens found - start a new instance. - screen - ;; - 1) - # Just one screen - reconnect. - screen -dr "${TTY//\//-}.${HOSTNAME%%.*}" - ;; - *) - # Multiple screens - output a list - echo "Multiple screens found for $TTY:" - echo "$SCREENS" | sed -e 's/^/ /g' - ;; - esac - } -} - # Make bash a little more pleasent - these are valid for all versions. shopt -s cdspell checkhash checkwinsize cmdhist histappend no_empty_cmd_completion