#!/usr/bin/env bash
#
# draw-ruler - draw a ruler across the screen
#
# default:
#   - it displays the column number of the 1st, 11th, 21st, … column,
#     and a marker on every 5 in between.
#   - you can also specify a custom string to draw as the first parameter.
#   - every "x" in the string will be replaced by the column number.

# the string to repeat for the entire line.
# the letter "x" marks the start of the column number.
# other characters are printed as they are.

str="${1:-x...·.....}"

num_columns="$(tput cols)"
curr_column=1
while [ "${curr_column}" -le "${num_columns}" ]; do
  char="${str:$(((curr_column - 1) % ${#str})):1}"
  if [ "${char}" = "x" ]; then
    printf '%s' "${curr_column}"
    # let curr_column+=${#curr_column}
    curr_column=$((curr_column + ${#curr_column}))
  else
    printf '%s' "${char}"
    # let curr_column++
    curr_column=$((curr_column + 1))
  fi
done
echo
