-
Notifications
You must be signed in to change notification settings - Fork 0
/print
107 lines (96 loc) · 4.26 KB
/print
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
# Colors a string ($1) with a number ($2)
__c() { printf "%s" "$(tput $3 ${2:-7})${1}$(tput sgr0)"; }
prompt_fg_black() { echo "\[$(tput setaf 0)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_red() { echo "\[$(tput setaf 1)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_green() { echo "\[$(tput setaf 2)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_yellow() { echo "\[$(tput setaf 3)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_blue() { echo "\[$(tput setaf 4)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_magenta() { echo "\[$(tput setaf 5)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_cyan() { echo "\[$(tput setaf 6)\]${1}\[$(tput sgr0)\]"; }
prompt_fg_gray() { echo "\[$(tput setaf 7)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_black() { echo "\[$(tput setaf 0)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_red() { echo "\[$(tput setab 1)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_green() { echo "\[$(tput setab 2)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_yellow() { echo "\[$(tput setab 3)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_blue() { echo "\[$(tput setab 4)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_magenta() { echo "\[$(tput setab 5)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_cyan() { echo "\[$(tput setab 6)\]${1}\[$(tput sgr0)\]"; }
prompt_bg_white() { echo "\[$(tput setab 7)\]${1}\[$(tput sgr0)\]"; }
color_black() { printf "`__c "$1" 0 setaf`"; }
color_red() { printf "`__c "$1" 1 setaf`"; }
color_green() { printf "`__c "$1" 2 setaf`"; }
color_yellow() { printf "`__c "$1" 3 setaf`"; }
color_blue() { printf "`__c "$1" 4 setaf`"; }
color_magenta() { printf "`__c "$1" 5 setaf`"; }
color_cyan() { printf "`__c "$1" 6 setaf`"; }
color_gray() { printf "`__c "$1" 7 setaf`"; }
bg_black() { printf "`__c "$1" 0 setab`"; }
bg_red() { printf "`__c "$1" 1 setab`"; }
bg_green() { printf "`__c "$1" 2 setab`"; }
bg_yellow() { printf "`__c "$1" 3 setab`"; }
bg_blue() { printf "`__c "$1" 4 setab`"; }
bg_magenta() { printf "`__c "$1" 5 setab`"; }
bg_cyan() { printf "`__c "$1" 6 setab`"; }
bg_white() { printf "`__c "$1" 7 setab`"; }
underline() { echo "$1"; }
print_error() { printf "`color_red "▒"` $@\n"; }
print_info() { printf "`color_blue "▒"` $@\n"; }
print_ok() { printf "`color_green "▒"` $@\n"; }
print_warning() { printf "`color_yellow "▒"` $@\n"; }
print_cmd() {
# awk $1=$1 removes extra spaces
printf "\033[1;30m▒ $ %s\n" "`echo "$@" | awk '$1=$1'`$(tput sgr0)";
}
[ ${ZSH_VERSION} ] && {
color_black() { echo "%F{black}${1}%f"; }
color_red() { echo "%F{red}${1}%f"; }
color_green() { echo "%F{green}${1}%f"; }
color_yellow() { echo "%F{yellow}${1}%f"; }
color_blue() { echo "%F{blue}${1}%f"; }
color_magenta() { echo "%F{magenta}${1}%f"; }
color_cyan() { echo "%F{cyan}${1}%f"; }
color_gray() { echo "%F{8}${1}%f"; }
bg_black() { echo "%K{black}${1}%k"; }
bg_red() { echo "%K{red}${1}%k"; }
bg_green() { echo "%K{green}${1}%k"; }
bg_yellow() { echo "%K{yellow}${1}%k"; }
bg_blue() { echo "%K{blue}${1}%k"; }
bg_magenta() { echo "%K{magenta}${1}%k"; }
bg_cyan() { echo "%K{cyan}${1}%k"; }
bg_white() { echo "%K{white}${1}%k"; }
underline() { echo "%U${1}%u"; }
prompt_fg_black() { color_black $@; }
prompt_fg_red() { color_red $@; }
prompt_fg_green() { color_green $@; }
prompt_fg_yellow() { color_yellow $@; }
prompt_fg_blue() { color_blue $@; }
prompt_fg_magenta() { color_magenta $@; }
prompt_fg_cyan() { color_cyan $@; }
prompt_fg_gray() { color_gray $@; }
prompt_bg_black() { bg_black $@; }
prompt_bg_red() { bg_red $@; }
prompt_bg_green() { bg_green $@; }
prompt_bg_yellow() { bg_yellow $@; }
prompt_bg_blue() { bg_blue $@; }
prompt_bg_magenta() { bg_magenta $@; }
prompt_bg_cyan() { bg_cyan $@; }
prompt_bg_white() { bg_white $@; }
print_error() { print -P "`color_red "▒"` $@"; }
print_info() { print -P "`color_blue "▒"` $@"; }
print_ok() { print -P "`color_green "▒"` $@"; }
print_warning() { print -P "`color_yellow "▒"` $@"; }
print_cmd() { print -P `color_gray " $ $(echo "$@" | awk '$1=$1')"`; }
}
question() {
local question_string="`color_magenta ▒` $1 [y/`color_cyan N`] ";
if [[ -n $ZSH_VERSION ]]; then
# https://askubuntu.com/a/1246583/652908
read "response?`print -P "$question_string"`";
else
# https://stackoverflow.com/a/3232082/1054579
read -r -p "$question_string" response;
fi
[[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] && return 0;
return 1;
}