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
|
if( ${#reference_colors} == 0 ) then
|
||||||
_debug colorshuffle
|
_debug colorshuffle
|
||||||
#echo
|
#echo
|
||||||
|
|
||||||
# Shuffle, if supported
|
# Shuffle, if supported
|
||||||
if( $?cshenv_detected_shuf ) then
|
if( $?cshenv_detected_shuf ) then
|
||||||
_debug "PRIMARY COLOR!"
|
_debug "PRIMARY COLOR!"
|
||||||
set reference_colors=`shuf -e $reference_colors_original`
|
set reference_colors=`shuf -e ${reference_colors_original}`
|
||||||
else
|
|
||||||
|
# Then use `sort -R` if possible
|
||||||
|
else if ( $?cshenv_sort_can_shuffle ) then
|
||||||
_debug "FALLBACK COLOR!"
|
_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
|
endif
|
||||||
|
|
||||||
if( $?last_color ) then
|
if( $?last_color ) then
|
||||||
set first_color = ${reference_colors[1]}
|
set first_color = ${reference_colors[1]}
|
||||||
if( ${first_color} == ${last_color} ) then
|
if( ${first_color} == ${last_color} ) then
|
||||||
@@ -89,17 +100,30 @@ endif
|
|||||||
if( ${#referencechars} == 0 ) then
|
if( ${#referencechars} == 0 ) then
|
||||||
_debug symbolshuffle
|
_debug symbolshuffle
|
||||||
#echo
|
#echo
|
||||||
|
|
||||||
|
# Then use `sort -R` if possible
|
||||||
if( $?cshenv_detected_shuf ) then
|
if( $?cshenv_detected_shuf ) then
|
||||||
_debug "PRIMARY CHAR!"
|
_debug "PRIMARY CHAR!"
|
||||||
set referencechars=`shuf -e $referencechars_original`
|
set referencechars=`shuf -e ${referencechars_original}`
|
||||||
else
|
|
||||||
|
# Then use `sort -R` if possible
|
||||||
|
else if ( $?cshenv_sort_can_shuffle ) then
|
||||||
_debug "FALLBACK CHAR!"
|
_debug "FALLBACK CHAR!"
|
||||||
set referencechars=(`echo $referencechars_original | tr " " "\n" | sort -R | xargs`)
|
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
|
endif
|
||||||
|
|
||||||
if( $?last_sym ) then
|
if( $?last_sym ) then
|
||||||
set first_sym = ${referencechars[1]}
|
set first_sym = ${referencechars[1]}
|
||||||
if( ${first_sym} == ${last_sym} ) then
|
if( ${first_sym} == ${last_sym} ) then
|
||||||
_debug "COLLISION CHAR!"
|
_debug "COLLISION CHAR!"
|
||||||
|
# Instead of a reshuffle, we put the collision at the end.
|
||||||
set tmp_char="${referencechars[1]}"
|
set tmp_char="${referencechars[1]}"
|
||||||
shift referencechars
|
shift referencechars
|
||||||
set referencechars=( ${referencechars} ${tmp_char} )
|
set referencechars=( ${referencechars} ${tmp_char} )
|
||||||
|
|||||||
Reference in New Issue
Block a user