From 7a344b82dd9479b21362d311973545acfc850229 Mon Sep 17 00:00:00 2001 From: lachtan Date: Sun, 15 Mar 2026 14:25:12 +0100 Subject: [PATCH] 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. --- bashrc | 7 +++++-- functions.sh | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bashrc b/bashrc index 5eb6226..912d5a6 100644 --- a/bashrc +++ b/bashrc @@ -7,13 +7,16 @@ export LWS=$WORKSPACE LWS_DEBUG=${LWS_DEBUG:-0} LWS_FAST=${LWS_FAST:-0} -echo "Linux Workspace initialization" +source "$LWS/functions.sh" if [[ -z $LC_ALL ]]; then export LC_ALL=en_US.UTF-8 fi -source "$LWS/functions.sh" +if is_interactive_shell; then + echo "Linux Workspace initialization" +fi + source_directory_sh "$LWS/rc" source_directory_sh "$HOME/.bashrc.d" diff --git a/functions.sh b/functions.sh index a6bad05..30ac627 100644 --- a/functions.sh +++ b/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