From 51e339ce74633c409db08c4b528bf80f97e16a9e Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 15 Apr 2022 15:31:44 -0400 Subject: [PATCH] Fix prompt shuffling when `shuf` is not found. --- tcshrc.prompt.defs | 5 +++++ tcshrc.prompt.final | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tcshrc.prompt.defs b/tcshrc.prompt.defs index 2efd9d4..d95a60e 100644 --- a/tcshrc.prompt.defs +++ b/tcshrc.prompt.defs @@ -6,6 +6,11 @@ if( $?CSHENV_DEBUG ) then echo "Sourcing prompt setup and definitions..." endif +which shuf >& /dev/null +if( $? == 0 ) then + setenv CSHENV_DETECTED_SHUF +endif + if( ! $?unknown_tty ) then set unknown_tty="?" if( $?CSHENV_DEBUG ) then diff --git a/tcshrc.prompt.final b/tcshrc.prompt.final index 9db349c..9800044 100644 --- a/tcshrc.prompt.final +++ b/tcshrc.prompt.final @@ -16,7 +16,13 @@ if( ${prompt_hcolor} == 0 ) then #echo colorshuffle #endif #echo  - set reference_colors=`shuf -e $reference_colors` + # Shuffle, if supported + if( $?CSHENV_DETECTED_SHUF ) then + set reference_colors=`shuf -e $reference_colors` + else + #echo "FALLBACK COLOR!" + set reference_colors=`echo $reference_colors | sed -e 's/ /\n/' | sort -R | xargs` + endif endif @@ -25,8 +31,13 @@ if( ${prompt_hsym} == 0 ) then # && ${prompt_hcolor} == 0 ) then echo symbolshuffle endif #echo  - set referencechars=`shuf -e $referencechars` - #set reference_colors=`shuf -e $reference_colors` + if( $?CSHENV_DETECTED_SHUF ) then + set referencechars=`shuf -e $referencechars` + #set reference_colors=`shuf -e $reference_colors` + else + #echo "FALLBACK CHAR!" + set referencechars=`echo $referencechars | sed -e 's/ /\n/' | sort -R | xargs` + endif endif @ prompt_hcolor = ${prompt_hcolor} + 1