Skip to content

Instantly share code, notes, and snippets.

@alsolovyev
Created January 29, 2019 14:36
Show Gist options
  • Save alsolovyev/92375b34306ceb0746a64d4c91b7ea3a to your computer and use it in GitHub Desktop.
Save alsolovyev/92375b34306ceb0746a64d4c91b7ea3a to your computer and use it in GitHub Desktop.
Bash. Useful Tips
#!/bin/bash
DEF='\e[0m' #Default color and effects
case $TERM in *term*)
#Color picker, usage: printf ${BLD}${CUR}${RED}${BBLU}"Hello!)"${DEF}|
#----------------------------------------------------------+---------+
# Text color | Background color |
#--------------------------------------------------------------------+
# Base color|Lighter shade| Base color | Lighter shade |
BLK='\e[30m'; blk='\e[90m'; BBLK='\e[40m'; bblk='\e[100m' #| Black |
RED='\e[31m'; red='\e[91m'; BRED='\e[41m'; bred='\e[101m' #| Red |
GRN='\e[32m'; grn='\e[92m'; BGRN='\e[42m'; bgrn='\e[102m' #| Green |
YLW='\e[33m'; ylw='\e[93m'; BYLW='\e[43m'; bylw='\e[103m' #| Yellow |
BLU='\e[34m'; blu='\e[94m'; BBLU='\e[44m'; bblu='\e[104m' #| Blue |
MGN='\e[35m'; mgn='\e[95m'; BMGN='\e[45m'; bmgn='\e[105m' #| Magenta |
CYN='\e[36m'; cyn='\e[96m'; BCYN='\e[46m'; bcyn='\e[106m' #| Cyan |
WHT='\e[37m'; wht='\e[97m'; BWHT='\e[47m'; bwht='\e[107m' #| White |
#----------------------------------------------------------+---------+
# Effects |
#--------------------------------------------------------------------+
BLD='\e[1m' #Bold\brighter |
DIM='\e[2m' #Dim\darker |
CUR='\e[3m' #Italic font |
UND='\e[4m' #Underline |
INV='\e[7m' #Inverted |
COF='\e[?25l' #Cursor Off |
CON='\e[?25h' #Cursor On |
#--------------------------------------------------------------------+
# Text positioning, usage: XY 10 10 "Hello World!" |
XY () { printf "\e[${2};${1}H${3}"; } # |
#--------------------------------------------------------------------+
# Print line, usage: line - 10 | line -= 20 | line "Hello World!" 20 |
line () { printf %.s"${1}" $(seq ${2}); } # |
#--------------------------------------------------------------------+
;; esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment