|
|
@ -9,51 +9,73 @@ function bashrc_count_lines { |
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_watch_start { |
|
|
|
if [ -n "${BASHRC_LINES+set}" ]; then |
|
|
|
echo "provided so far BASHRC_LINES=$BASHRC_LINES" |
|
|
|
else |
|
|
|
echo 'count lines of .bashrc' |
|
|
|
if [[ -z "${BASHRC_LINES+set}" ]]; then |
|
|
|
BASHRC_LINES=$(bashrc_count_lines) |
|
|
|
else |
|
|
|
BASHRC_EVOLVED=true |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_watch_end { |
|
|
|
bashrc_lines=$(bashrc_count_lines) |
|
|
|
if [[ "$BASHRC_LINES" -lt "$bashrc_lines" ]]; then |
|
|
|
if [[ "$BASHRC_LINES" -lt "$bashrc_lines" || -n "${BASHRC_EVOLVED+set}" ]]; then |
|
|
|
echo |
|
|
|
echo '*****************************' |
|
|
|
echo '* BASHRC has evolved *' |
|
|
|
echo '* please execute: *' |
|
|
|
echo '* BASHRC has evolved! *' |
|
|
|
echo '* please synchronize: *' |
|
|
|
echo '* *' |
|
|
|
echo "* source \$HOME/.bashrc *" |
|
|
|
echo "* source ~/.bashrc *" |
|
|
|
echo '* *' |
|
|
|
echo '*****************************' |
|
|
|
else |
|
|
|
echo 'everything is fine!' |
|
|
|
echo |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_env_sync { |
|
|
|
env_var="$1" |
|
|
|
env_value="$2" |
|
|
|
if printenv | grep -q "$env_var"; then |
|
|
|
real_value=$(eval "echo \$$env_var") |
|
|
|
echo "success for $env_var = $real_value" |
|
|
|
function _bashrc_env_with_prefix { |
|
|
|
arg1="$1" |
|
|
|
arg2="$2" |
|
|
|
prefix="$3" |
|
|
|
if printenv | grep -q "$arg1"; then |
|
|
|
real_value=$(eval "echo \$$arg1") |
|
|
|
echo "success for $arg1 = $real_value" |
|
|
|
else |
|
|
|
session_line="export ${env_var}=${env_value}" |
|
|
|
append_or_replace "^${session_line}.*" "$session_line" "$HOME/.bashrc" &>/dev/null |
|
|
|
case "$prefix" in |
|
|
|
export) |
|
|
|
session_line="export ${arg1}=${arg2}" |
|
|
|
regex="$session_line" |
|
|
|
;; |
|
|
|
eval) |
|
|
|
session_line="eval \"\$($arg2)\"" |
|
|
|
regex="eval \"\\\$\\($arg2\\)\"" |
|
|
|
;; |
|
|
|
*) echo "unknown prefix $prefix" && exit 10 ;; |
|
|
|
esac |
|
|
|
append_or_replace "$regex" "$session_line" "$HOME/.bashrc" &>/dev/null |
|
|
|
eval "$session_line" |
|
|
|
set +e |
|
|
|
eval "BASHRC_LINES=$BASHRC_LINES $0" |
|
|
|
exit $? |
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_env_export { |
|
|
|
_bashrc_env_with_prefix "$1" "$2" 'export' |
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_env_eval { |
|
|
|
_bashrc_env_with_prefix "$1" "$2" 'eval' |
|
|
|
} |
|
|
|
|
|
|
|
# main |
|
|
|
|
|
|
|
set -Eeu |
|
|
|
bashrc_watch_start |
|
|
|
|
|
|
|
echo 'init' |
|
|
|
bashrc_env_sync 'SESSION_RESTART' true |
|
|
|
bashrc_env_export 'SESSION_RESTART' true |
|
|
|
bashrc_env_export 'TOTO' fluo |
|
|
|
bashrc_env_eval 'MISE_SHELL' "$HOME/.local/bin/mise activate bash" |
|
|
|
echo 'end' |
|
|
|
|
|
|
|
echo 'suite' |
|
|
|
bashrc_watch_end |