available() {
  command -v "$1" >/dev/null 2>&1
}

split() {
  awk -F "$1" "{ print \$$2 }" -
}

between() {
  split "$1" 2 | split "$2" 1
}

bold() {
  # shellcheck disable=SC2312
  sed -r -e "s|<b>|$(tput bold)|g" \
         -e "s|</b>|$(tput sgr0)|g"
}

urldecode() {
  awk -niord '{ printf RT?$0chr("0x"substr(RT, 2)):$0 }' RS=%..
}

urlencode() {
  #TODO: actually do more shit here
  sed -e 's/ /\+/g'
}

htmlstrip() {
  sed -r -e "s|</?[a-zA-Z]+>||g"
}

htmldecode() {
  sed -e "s/&quot;/'/g" -e "s/&#x27;/'/g" -e 's/&amp;/\&/g' # | \
  #  awk -niord '{ printf RT?$0chr("0x"substr(RT, 4)):$0 }' RS='&#x..;'
  #BUG: awk gives up the ghost, sometimes, first seen with `-p 4 bah`
}
