-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotbash_screen
69 lines (59 loc) · 1.8 KB
/
dotbash_screen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#
# Alex's .bashrc_screen
#
# Various screen session hacks for bringing up special screens
#
SCREEN_ATT=`screen -ls | grep -c Attached`
SCREEN_DET=`screen -ls | grep -c Detached`
SCREEN_DEAD=`screen -ls | grep -c Dead`
SCREEN_STATUS="$SCREEN_ATT att/$SCREEN_DET det/$SCREEN_DEAD dead"
#
# Environment Hackage
#
# One of the biggest problems with screen is if the environment of
# the GUI session you are running in has changed. Sure screen keeps
# everything running but suddenly you can't spawn stuff that wants
# DBUS connections and the like.
#
#
ENV_DUMP_FILE="${HOME}/current_${HOSTNAME}.env"
alias dump_env="env > ${ENV_DUMP_FILE}"
# If in a GUI dump the current environment
# This is not perfect, if you spawn an xterm out of your screen session it
# vape your carefully stored environment, so don't do that.
if [[ ${TERM} == "screen" || ${TERM} == "screen-256color" ]]; then
SCREEN_TERM="run restore_gui_env to pick up GUI vars"
elif [[ ${TERM} == "linux" ]]; then
SCREEN_TERM="in a console session"
else
SCREEN_TERM="dumping env in ${ENV_DUMP_FILE}"
dump_env
fi
echo "loading .bash_screen ($SCREEN_STATUS - $SCREEN_TERM)"
# Restore a single environment variable from ${ENV_DUMP_FILE}
function restore_env_var
{
if [[ "$1" && -f ${ENV_DUMP_FILE} ]]
then
line=`grep $1 ${ENV_DUMP_FILE}`
if [ "$line" ]; then
delim=`expr index $line =`
value=${line:$delim}
echo "export $1=$value"
export $1=$value
fi
fi
}
function restore_gui_env
{
echo "Restoring GUI environment settings"
restore_env_var DBUS_SESSION_BUS_ADDRESS
restore_env_var XDG_SESSION_COOKIE
restore_env_var XAUTHORITY
restore_env_var DISPLAY
restore_env_var SSH_AUTH_SOCK
restore_env_var GPG_AGENT_INFO
restore_env_var GPG_TTY
restore_env_var GNOME_KEYRING_SOCKET
}