Advertisement
svenhoefer

Untitled

Nov 17th, 2018
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.55 KB | None | 0 0
  1. # $(1) = title; $(2) = color; $(3) = left, center, right
  2. define draw_line
  3.     @ \
  4.     printf '%.0s-' {1..$(shell tput cols)}; \
  5.     if test "$(1)"; then \
  6.         cols=$(shell tput cols); \
  7.         length=$(shell echo $(1) | awk '{print length}'); \
  8.         case "$(3)" in \
  9.             *right)  let indent="length + 1" ;; \
  10.             *center) let indent="cols - (cols - length) / 2" ;; \
  11.             *left|*) let indent="cols" ;; \
  12.         esac; \
  13.         tput cub $$indent; \
  14.         test "$(2)" && printf $$(tput setaf $(2)); \
  15.         printf '$(1)'; \
  16.         test "$(2)" && printf $$(tput sgr0); \
  17.     fi; \
  18.     echo
  19. endef
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement