tivasyk

simple console ruler

Jul 17th, 2019
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.70 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # tivasyk <[email protected]>
  3. # Draw a simple screen-wide ruler
  4. TICK_0='┼'
  5. TICK_5='┴'
  6. TICK_1='─'
  7. SCREEN_WIDTH=$(tput cols)
  8. # Prepare the ruler
  9. for (( i=1; i<=SCREEN_WIDTH; i++)); do
  10.     if [[ $(( i % 10 )) == 0 ]]; then
  11.         RULER_STRING+=$TICK_0
  12.         if [[ ${#i} > 1 ]]; then
  13.             RULER_LABELS=${RULER_LABELS::(-$(( ${#i} -1 )) ) }
  14.         fi
  15.         RULER_LABELS+="${i}"
  16.     elif [[ $(( i % 5 )) == 0 ]]; then
  17.         RULER_STRING+=$TICK_5
  18.         RULER_LABELS+=' '
  19.     else
  20.         RULER_STRING+=$TICK_1
  21.         RULER_LABELS+=' '
  22.     fi
  23. done
  24. # Print the ruler in invented colors
  25. tput rev
  26. printf "%s\n%s\n" "${RULER_LABELS}" "${RULER_STRING}"
  27. tput sgr0
Advertisement
Add Comment
Please, Sign In to add comment