Suppress output in non-interactive shells
Add is_interactive_shell() helper and gate all user-visible echo/debug output behind it so that non-interactive invocations (scripts, cron, ssh commands) stay silent. Move functions.sh source earlier in bashrc so helpers are available sooner.
This commit is contained in:
10
functions.sh
10
functions.sh
@@ -5,6 +5,10 @@ if [ -z "$time_ms" ]; then
|
||||
readonly time_ms='date +%s%3N'
|
||||
fi
|
||||
|
||||
function is_interactive_shell() {
|
||||
[[ $- == *i* ]]
|
||||
}
|
||||
|
||||
function is_fast_init() {
|
||||
(( $LWS_FAST ))
|
||||
}
|
||||
@@ -14,7 +18,7 @@ function is_slow_init() {
|
||||
}
|
||||
|
||||
function xlog() {
|
||||
if true_false "$LWS_DEBUG"; then
|
||||
if is_interactive_shell && true_false "$LWS_DEBUG"; then
|
||||
echo "$@"
|
||||
fi
|
||||
}
|
||||
@@ -100,11 +104,11 @@ function source_directory() {
|
||||
xlog "LOAD DIR $mask"
|
||||
for file in $mask; do
|
||||
if [[ -e "$file" ]]; then
|
||||
if (( $LWS_DEBUG )); then
|
||||
if is_interactive_shell && (( $LWS_DEBUG )); then
|
||||
start=$($time_ms)
|
||||
source "$file"
|
||||
stop=$($time_ms)
|
||||
echo "LOAD FILE $file $((stop - start)) ms"
|
||||
xlog "LOAD FILE $file $((stop - start)) ms"
|
||||
else
|
||||
source "$file"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user