Skip to content

Commit

Permalink
Test code for generating unique combinations (for Nerd Fonts script)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanoasis committed Oct 24, 2016
1 parent 75c9125 commit d1f011d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
42 changes: 42 additions & 0 deletions combinations.sh
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',}
17 changes: 17 additions & 0 deletions unique-combinations.sh
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

0 comments on commit d1f011d

Please sign in to comment.