Note: You are viewing an old version of this page. View the current version.

v1

#!/bin/sh

firstchar() {
  eval $(echo -en "${data}" | sed -e 's/^\(.\)\(.*\)$/char="\1" data="\2"/g')
}

hexdec() {
  if [ -z "${1}" ]
  then
    echo "0"
    return
  fi
  echo $(( 0x${1} + 0 ))
}

flag(){
  if [ -z "${1}" ]
  then
    echo "Usage: flag 'hexcode' [symbol]"
    echo "Generates an ANSI color flag using the specified hex codes"
    echo "Uses the optional symbol (or .) to draw the flag"
    return
  fi
  data="${1}"
  sym="${2}"
  [ -z "${sym}" ] && sym=" "
  while [ -n "${data}" ]
  do
    firstchar
    ord=$(hexdec "${char}")
    bright="0"
    [ "$(( ${ord} & 8 ))" -gt 0 ] && bright="1"
    fore="3$(( ${ord} & 7 ))"
    back="4$(( ${ord} & 7 ))"
    printf "\[\033[%s;%s;%s;7m\]%s" "${bright}" "${fore}" "${back}" "${sym}"
  done
  printf "\[\033[0m\]"
}

[ -f "/etc/flag" ] && flag "$(cat /etc/flag)"

v2.incomplete

#!/bin/sh

firstchar() {
  eval $(echo -en "${data}" | sed -e 's/^\(.\)\(.*\)$/char="\1" data="\2"/g')
}

hexdec() {
  if [ -z "${1}" ]
  then
    echo "0"
    return
  fi
  echo $(( 0x${1} + 0 ))
}

flag(){
  if [ -z "${1}" ]
  then
    echo "Usage: flag 'hexcode' [symbol]"
    echo "Generates an ANSI color flag using the specified hex codes"
    echo "Uses the optional symbol (or .) to draw the flag"
    return
  fi
  data="${1}"
  sym="${2}"
  [ -z "${sym}" ] && sym=" "
  while [ -n "${data}" ]
  do
    firstchar
    ord=$(hexdec "${char}")
    bright="0"
    [ "$(( ${ord} & 8 ))" -gt 0 ] && bright="1"
    fore="3$(( ${ord} & 7 ))"
    back="4$(( ${ord} & 7 ))"
    printf "\[\033[%s;%s;%s;7m\]%s" "${bright}" "${fore}" "${back}" "${sym}"
  done
  printf "\[\033[0m\]"
}

[ -f "/etc/flag" ] && flag "$(cat /etc/flag)"