Skip to content

Instantly share code, notes, and snippets.

@rashkopetrov
Last active July 7, 2021 14:23
Show Gist options
  • Save rashkopetrov/4a4a96b1c83f4c8cc82497065cd3d266 to your computer and use it in GitHub Desktop.
Save rashkopetrov/4a4a96b1c83f4c8cc82497065cd3d266 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ###########################################
# Title :PrinTxt
# Description :This script print given text with different style
# Author :Rashko Petrov
# Website :https://rashkopetrov.dev
# GitHub :https://gist.github.com/rashkopetrov/4a4a96b1c83f4c8cc82497065cd3d266/
# Date :2021-07-07
# Version :0.21.07.07 - 2021-07-07
# Usage :bash printxt.sh [option] [text]
# BashVersion :Tested with 4.4.12
# License :MIT License
# :Copyright (c) 2021 Rashko Petrov
# ###########################################
NC="\033[0m" # No Colo
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
printText () {
case "$1" in
nl)
printf "\n"
;;
text)
printf "$2\n"
;;
textList)
printf "${YELLOW}==>${NC} $2\n"
;;
textSep)
printf "${NC}---------------------${NC}\n"
;;
alertText)
printf "${RED}$2${NC}\n"
;;
alertSep)
printf "${RED}---------------------${NC}\n"
;;
noticeText)
printf "${YELLOW}$2${NC}\n"
;;
noticeSep)
printf "${YELLOW}---------------------${NC}\n"
;;
successText)
printf "${GREEN}$2${NC}\n"
;;
successSep)
printf "${GREEN}---------------------${NC}\n"
;;
*)
esac
}
if [ "${#}" = "0" ]; then
printText alert "./print.sh: arguments missing"
printText alert "Try './print.sh --help' for more information."
printText nl
exit 1
fi
if [[ $1 = "h" || $1 = "help" || $1 = "--help" ]]; then
printText text "Usage: ./print.sh [type] [text]"
printText nl
printText text "Types:"
printText text " nl"
printText text " Prints a new line"
printText text " text"
printf " This is text\n"
printText text " textSep"
printf " ${NC}---------------------${NC}\n"
printText text " textList"
printf " ${YELLOW}==>${NC} Text with list arrow\n"
printText text " alertText"
printf " ${RED}This is alert${NC}\n"
printText text " alertSep"
printf " ${RED}---------------------${NC}\n"
printText text " noticeText"
printf " ${YELLOW}This is alert${NC}\n"
printText text " noticeSep"
printf " ${YELLOW}---------------------${NC}\n"
printText text " successText"
printf " ${GREEN}This is alert${NC}\n"
printText text " successSep"
printf " ${GREEN}---------------------${NC}\n"
printText nl
printText text "Examples:"
printText text " ./printxt.sh --help Prints the help text"
printText text " ./printxt.sh nl Prints a new line"
printText text " ./printxt.sh text \"text to be printed\" Prints given text"
fi
printText "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment