From Wicked Cool Shell Scripts, 2nd Edition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash

function initializeANSI () {

esc="\033" # 如果无效,直接敲 ESC 键。

# 前景色:
blackf="${esc}[30m"; redf="${esc}[31m"; greenf="${esc}[32m"
yellowf="${esc}[33m" bluef="${esc}[34m"; purplef="${esc}[35m"
cyanf="${esc}[36m"; whitef="${esc}[37m"

# 背景色:
blackb="${esc}[40m"; redb="${esc}[41m"; greenb="${esc}[42m"
yellowb="${esc}[43m" blueb="${esc}[44m"; purpleb="${esc}[45m"
cyanb="${esc}[46m"; whiteb="${esc}[47m"

# 粗体、斜体、下划线以及样式切换:
boldon="${esc}[1m"; boldoff="${esc}[22m"
italicson="${esc}[3m"; italicsoff="${esc}[23m"
ulon="${esc}[4m"; uloff="${esc}[24m"
invon="${esc}[7m"; invoff="${esc}[27m"
reset="${esc}[0m"
}

initializeANSI
echo -e "
${yellowf}This is a phrase in yellow${redb} and red${reset}
${boldon}This is bold${ulon} this is italics${reset} bye-bye
${italicson}This is italics${italicsoff} and this is not
${ulon}This is ul${uloff} and this is not
${invon}This is inv${invoff} and this is not
${yellowf}${redb}Warning I ${yellowb}${redf}Warning II${reset}
"

Add snippets for shell common comment

1
2
3
4
5
6
7
8
9
10
11
{
"Print to shellNote": {
"prefix": "shell",
"body": [
" # Description: $1",
" # Author: Your Name",
" # Date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}"
],
"description": "shel script comment"
}
}