|
|
@ -0,0 +1,59 @@ |
|
|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
# global variables |
|
|
|
|
|
|
|
# functions |
|
|
|
|
|
|
|
function bashrc_count_lines { |
|
|
|
wc -l "$HOME/.bashrc" | cut -d' ' -f1 |
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_watch_start { |
|
|
|
if [ -n "${BASHRC_LINES+set}" ]; then |
|
|
|
echo "provided so far BASHRC_LINES=$BASHRC_LINES" |
|
|
|
else |
|
|
|
echo 'count lines of .bashrc' |
|
|
|
BASHRC_LINES=$(bashrc_count_lines) |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
function bashrc_watch_end { |
|
|
|
bashrc_lines=$(bashrc_count_lines) |
|
|
|
if [[ "$BASHRC_LINES" -lt "$bashrc_lines" ]]; then |
|
|
|
echo '*****************************' |
|
|
|
echo '* BASHRC has evolved *' |
|
|
|
echo '* please execute: *' |
|
|
|
echo '* *' |
|
|
|
echo "* source \$HOME/.bashrc *" |
|
|
|
echo '* *' |
|
|
|
echo '*****************************' |
|
|
|
else |
|
|
|
echo 'everything is fine!' |
|
|
|
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" |
|
|
|
else |
|
|
|
session_line="export ${env_var}=${env_value}" |
|
|
|
append_or_replace "^${session_line}.*" "$session_line" "$HOME/.bashrc" &>/dev/null |
|
|
|
eval "$session_line" |
|
|
|
set +e |
|
|
|
eval "BASHRC_LINES=$BASHRC_LINES $0" |
|
|
|
exit $? |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
# main |
|
|
|
|
|
|
|
set -Eeu |
|
|
|
bashrc_watch_start |
|
|
|
echo 'init' |
|
|
|
bashrc_env_sync 'SESSION_RESTART' true |
|
|
|
|
|
|
|
echo 'suite' |
|
|
|
bashrc_watch_end |