Prompt sigil shuffle code cleaned up and improved.
A more portable third method is provided. And some comments make it understandable.
This commit is contained in:
+29
-5
@@ -65,14 +65,25 @@ _debug "Dynamic color loading processed..."
|
||||
if( ${#reference_colors} == 0 ) then
|
||||
_debug colorshuffle
|
||||
#echo
|
||||
|
||||
# Shuffle, if supported
|
||||
if( $?cshenv_detected_shuf ) then
|
||||
_debug "PRIMARY COLOR!"
|
||||
set reference_colors=`shuf -e $reference_colors_original`
|
||||
else
|
||||
set reference_colors=`shuf -e ${reference_colors_original}`
|
||||
|
||||
# Then use `sort -R` if possible
|
||||
else if ( $?cshenv_sort_can_shuffle ) then
|
||||
_debug "FALLBACK COLOR!"
|
||||
set reference_colors=`echo $reference_colors_original | tr " " "\n" | sort -R | xargs`
|
||||
set reference_colors=( `echo ${reference_colors_original} | tr " " "\n" | sort -R` )
|
||||
|
||||
# If not, `awk` with prepended random numbers can be used to trick
|
||||
# `sort` into a shuffle
|
||||
else
|
||||
_debug "POSIX FALLBACK COLOR!"
|
||||
set _seed=`date +%s%N`
|
||||
set reference_colors=( `echo ${reference_colors_original} | tr " " "\n" | awk -v seed="${_seed}" 'BEGIN{srand(seed)} {print rand(), $0}' | sort -n | awk '{print $2}'` )
|
||||
endif
|
||||
|
||||
if( $?last_color ) then
|
||||
set first_color = ${reference_colors[1]}
|
||||
if( ${first_color} == ${last_color} ) then
|
||||
@@ -89,17 +100,30 @@ endif
|
||||
if( ${#referencechars} == 0 ) then
|
||||
_debug symbolshuffle
|
||||
#echo
|
||||
|
||||
# Then use `sort -R` if possible
|
||||
if( $?cshenv_detected_shuf ) then
|
||||
_debug "PRIMARY CHAR!"
|
||||
set referencechars=`shuf -e $referencechars_original`
|
||||
else
|
||||
set referencechars=`shuf -e ${referencechars_original}`
|
||||
|
||||
# Then use `sort -R` if possible
|
||||
else if ( $?cshenv_sort_can_shuffle ) then
|
||||
_debug "FALLBACK CHAR!"
|
||||
set referencechars=(`echo $referencechars_original | tr " " "\n" | sort -R | xargs`)
|
||||
|
||||
# If not, `awk` with prepended random numbers can be used to trick
|
||||
# `sort` into a shuffle
|
||||
else
|
||||
_debug "POSIX FALLBACK CHAR!"
|
||||
set _seed=`date +%s%N`
|
||||
set referencechars=( `echo ${referencechars_original} | tr " " "\n" | awk -v seed="${_seed}" 'BEGIN{srand(seed)} {print rand(), $0}' | sort -n | awk '{print $2}'` )
|
||||
endif
|
||||
|
||||
if( $?last_sym ) then
|
||||
set first_sym = ${referencechars[1]}
|
||||
if( ${first_sym} == ${last_sym} ) then
|
||||
_debug "COLLISION CHAR!"
|
||||
# Instead of a reshuffle, we put the collision at the end.
|
||||
set tmp_char="${referencechars[1]}"
|
||||
shift referencechars
|
||||
set referencechars=( ${referencechars} ${tmp_char} )
|
||||
|
||||
Reference in New Issue
Block a user