-
Notifications
You must be signed in to change notification settings - Fork 2
/
bash.py
62 lines (50 loc) · 1.38 KB
/
bash.py
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
"""
Module for supporting the Bash shell.
"""
from . import register_type
from .bash_like import BashLikeShell
class BashShell(BashLikeShell):
"""
Shell implementation for the Bash shell.
"""
def __init__(self):
super().__init__()
def get_shell_hook(self):
pid = self.shell_pid
location = self.envprobe_location
# Return a Bash shell script that is loaded by the user's shell.
# This will call back to envprobe every time the user gets a prompt,
# letting us execute the environment variable configuration when
# needed.
return """
if [[ ! "$PROMPT_COMMAND" =~ "__envprobe" ]];
then
export ENVPROBE_SHELL_TYPE="{TYPE}";
export ENVPROBE_CONFIG="{CONFIG}";
envprobe()
{{
_ENVPROBE=1 "{LOCATION}/envprobe.py" "$@";
}};
envprobe-config()
{{
_ENVPROBE=1 "{LOCATION}/envprobe-config.py" "$@";
}};
__envprobe()
{{
local original_retcode="$?";
if [[ -f "{CONTROL_FILE}" ]];
then
eval `cat "{CONTROL_FILE}"`;
rm "{CONTROL_FILE}";
fi
return $original_retcode;
}};
echo "Envprobe loaded successfully. :)";
PROMPT_COMMAND="__envprobe;$PROMPT_COMMAND";
fi
""".format(PID=pid,
LOCATION=location,
CONFIG=self._configuration_folder,
CONTROL_FILE=self.control_file,
TYPE=self.shell_type)
register_type('bash', BashShell)