Added screen_attach function to start/reattach screen sessions on console/xterm.

This commit is contained in:
Darren 'Tadgy' Austin 2020-12-02 20:06:29 +00:00
commit 60f84452cf
3 changed files with 33 additions and 3 deletions

View file

@ -7,7 +7,6 @@ export LANG="en_GB.UTF-8"
export LC_COLLATE="POSIX" # 'C' causes issues with some applications
# export LC_CTYPE="POSIX" # Not sure why I set this in the first place...
export LESS="-RMi -PM?f%F:stdin. -- Page %dt of %D -- %lt/%L (%Pt\%)$"
export MANPAGER="less -Mis -PM'Page %dt$'"
export PAGER="less"
export PATH="/usr/local/sbin:/usr/sbin:/opt/sbin:/sbin:$PATH"
export VISUAL="$EDITOR"
@ -19,10 +18,12 @@ if [[ "$_PLATFORM" = "Linux" ]]; then
export I_WANT_A_BROKEN_PS=1
export LYNX_CFG="$HOME/.lynx.cfg"
export LYNX_LSS="$HOME/.lynx.lss"
export MANPAGER="most"
export MANPATH="$HOME/.local/share/man:$MANPATH"
hash dircolors >/dev/null 2>&1 && eval "$(dircolors -b ~/.dir_colors)"
elif [[ "$_PLATFORM" = "Darwin" ]]; then
export LSCOLORS="ExGxdxdxCxDxDxbcacbeae"
export MANPAGER="less -Mis -PM'Page %dt$'"
export MANPATH="/opt/local/share/man:$MANPATH"
export PATH="/opt/local/sbin:/opt/local/bin:$PATH"
else
@ -116,6 +117,10 @@ unset _OUTPUT _PLATFORM
# Screen.
hash screen >/dev/null 2>&1 && {
# Reattach existing screens.
screen_attach
# Output some screen info.
export SCREENDIR="$HOME/.screen-$(hostname --short)"
if [[ ! -e ~/.hushlogin ]]; then
if [[ ! -z "$STY" ]]; then

27
.bashrc
View file

@ -153,6 +153,30 @@ _unlock_agents_file() {
fi
}
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
@ -205,7 +229,8 @@ unset _COLOUR
# Set the debugger prompt.
# PS4="+(\\\$? = \$?) \${BASH_SOURCE##*/}\${FUNCNAME:+(\$FUNCNAME)}:\$LINENO: "
PS4="+(\[\e[33m\]\\\$? = \$?\[$(tput sgr0)\]) \[$(tput bold)$(tput setaf 4)\]\${BASH_SOURCE##*/}\[$(tput sgr0)\]\${FUNCNAME:+(\[$(tput bold)$(tput setaf 2)\]\$FUNCNAME\[$(tput sgr0)\])}:\[$(tput bold)$(tput setaf 1)\]\$LINENO\[$(tput sgr0)\]: "
# PS4="+(\[\e[33m\]\\\$? = \$?\[$(tput sgr0)\]) \[$(tput bold)$(tput setaf 4)\]\${BASH_SOURCE##*/}\[$(tput sgr0)\]\${FUNCNAME:+(\[$(tput bold)$(tput setaf 2)\]\$FUNCNAME\[$(tput sgr0)\])}:\[$(tput bold)$(tput setaf 1)\]\$LINENO\[$(tput sgr0)\]: "
export PS4="+(\[\e[33m\]\$?\[$(tput sgr0)\]) \[$(tput bold)$(tput setaf 4)\]\${BASH_SOURCE##*/}\[$(tput sgr0)\]\${FUNCNAME:+(\[$(tput bold)$(tput setaf 2)\]\$FUNCNAME\[$(tput sgr0)\])}:\[$(tput bold)$(tput setaf 1)\]\$LINENO\[$(tput sgr0)\]: "
# The commands to execute before the prompt is displayed.
PROMPT_COMMAND="_agent_prompt_command"

2
.dmrc
View file

@ -1,2 +1,2 @@
[Desktop]
Session=LXDE
Session=lightdm-xsession