Added screen_attach function to start/reattach screen sessions on console/xterm.
This commit is contained in:
parent
f159818c88
commit
60f84452cf
3 changed files with 33 additions and 3 deletions
27
.bashrc
27
.bashrc
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue