-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_shell.py
executable file
·83 lines (71 loc) · 2.96 KB
/
install_shell.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import sys
from install_lib import *
def install_shell():
environ = get_environ()
# ####################################################################################################
# install shrc_var
# ####################################################################################################
SHRC_VAR_FILE_NAME = os.path.join(environ["HOME"], ".shrc_var")
SHRC_VAR_FILE_CONTENT = """#!/bin/bash
source "${HOME}/init_bin/konix_init_lib.sh"
# importing custom environnement variables
import_env
"""
replace_file_content(SHRC_VAR_FILE_NAME, SHRC_VAR_FILE_CONTENT)
# ####################################################################################################
# Install KONIX_SH_CUSTOM_FILE
# ####################################################################################################
if not os.path.exists(environ["KONIX_SH_CUSTOM_FILE"]):
replace_file_content(environ["KONIX_SH_CUSTOM_FILE"], """#!/bin/bash
# custom sh commands
""")
# ####################################################################################################
# Install bashrc
# ####################################################################################################
replace_file_content(
os.path.join(environ["HOME"], ".bashrc"), """#!/bin/bash
[ -n "${IN_NIX_SHELL}" ] && return
[ -z "$PS1" ] && return
test "${TERM}" = "dumb" && return
konix_load_init () {
# mist be done asap to increase chances the started shell is still in the active window
if test -n "${TMUX_PANE}"
then
export KONIX_TMUX_WINDOW="$(tmux display-message -p '#{window_index}')"
fi
source "${HOME}/.shrc_var"
source "${KONIX_CONFIG_DIR}/bashrc"
source "${KONIX_SH_CUSTOM_FILE}"
}
# if the computer is in bad shape, do not load the whole configuration
[ "$(cut -d. -f1 /proc/loadavg)" -gt "$(expr 2 \* $(nproc))" ] && return
konix_load_init
""")
# ####################################################################################################
# SHRC
# ####################################################################################################
replace_file_content(
os.path.join(environ["HOME"], ".shrc"), """#!/bin/bash
[ -n "${IN_NIX_SHELL}" ] && return
[ -z "$PS1" ] && return
test "${TERM}" = "dumb" && return
konix_load_init () {
# mist be done asap to increase chances the started shell is still in the active window
if test -n "${TMUX_PANE}"
then
export KONIX_TMUX_WINDOW="$(tmux display-message -p '#{window_index}')"
fi
source "${HOME}/.shrc_var"
source "${KONIX_CONFIG_DIR}/bashrc"
source "${KONIX_SH_CUSTOM_FILE}"
}
# if the computer is in bad shape, do not load the whole configuration
[ "$(cut -d. -f1 /proc/loadavg)" -gt "$(expr 2 \* $(nproc))" ] && return
konix_load_init
""")
print("Successful installed shell config")
if __name__ == '__main__':
install_shell()