forked from ryanoasis/public-bash-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test code for generating unique combinations (for Nerd Fonts script)
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
# resouces | ||
# http://stackoverflow.com/questions/3846123/generating-permutations-using-bash | ||
# http://stackoverflow.com/questions/17762764/generate-all-possible-combinations-of-a-function-call-using-bash-script | ||
|
||
printf "# %s\n" {fontawesome,},{octicons,},{fontlinux,},{pomicons,},{powerlineextra,} | ||
|
||
|
||
printf "# - %s\n" --{fontawesome,}--{octicons,}--{fontlinux,}--{pomicons,}--{powerlineextra,} | ||
|
||
|
||
perm() { | ||
local items="$1" | ||
local out="$2" | ||
local i | ||
[[ "$items" == "" ]] && echo "$out" && return | ||
for (( i=0; i<${#items}; i++ )) ; do | ||
perm "${items:0:i}${items:i+1}" "$out${items:i:1}" | ||
done | ||
} | ||
while read line ; do perm $line ; done < File | ||
|
||
|
||
echo --{fa,}{o,} | ||
printf "--{fa,}{o,}" | ||
|
||
printf " %s\n" {fa,}{o,} | ||
|
||
printf " %s\n" --{fontawesome,}{octicons,}{fontlinux,}{pomicons,},{powerlineextra,},{fontawesomeextension,} | ||
|
||
# this seems to be working: | ||
printf " %s\n" {--fontawesome,}\ {--octicons,} | ||
|
||
# too many spaces: | ||
printf " %s\n" {--fontawesome,}\ {--octicons,}\ {--fontlinux,}\ {--pomicons,}\ {--powerlineextra,}\ {--fontawesomeextension,} | ||
|
||
# try to eliminate build up of spaces: | ||
|
||
printf " %s\n" {' --fontawesome',}{' --octicons',}{--fontlinux,}{--pomicons,}{--powerlineextra,}{--fontawesomeextension,} | ||
|
||
# lookin' good: | ||
printf " %s\n" {' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# http://stackoverflow.com/questions/26176481/generate-combinations-of-elements-with-echo | ||
|
||
POWER=$((2**$#)) | ||
#BITS=`seq -f '0' -s '' 1 $#` | ||
BITS=`eval echo {1..$#} | sed -E 's/[0-9]+[ ]*/0/g'` | ||
|
||
while [ $POWER -gt 1 ];do | ||
POWER=$(($POWER-1)) | ||
BIN=`bc <<< "obase=2; $POWER"` | ||
MASK=`echo $BITS | sed -e "s/0\{${#BIN}\}$/$BIN/" | grep -o .` | ||
POS=1; AWK=`for M in $MASK;do | ||
[ $M -eq 1 ] && echo -n "print \\$\${POS};" | ||
POS=$(($POS+1)) | ||
done;echo` | ||
awk -v ORS=" " "{$AWK}" <<< "$@" | sed 's/ $//' | ||
done |