-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bash_profile
174 lines (166 loc) · 4.4 KB
/
.bash_profile
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
__DIR__=$(dirname $0)
#n
export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin" # Added by n-install (see http://git.io/n-install-repo).
# export PAGER="col -b | open -a /Applications/Safari.app -f"
alias cnpm='npm --registry=http://registry.npm.taobao.org'
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
alias p=python3
function c.blue(){ # 蓝色输出
echo -e "\033[34m$*\033[0m"
}
function c.green(){ # 绿色输出
echo -e "\033[32m$*\033[0m"
}
function c.red(){ # 红色输出
echo -e "\033[31m\033[01m$*\033[0m"
}
function c.magenta(){ # 洋色输出
echo -e "\033[35m\033[01m$*\033[0m"
}
pad_left() {
r=$1
c=$(expr $2 - ${#r} + 1)
for i in {1..$c}; do
r=$r' '
done
echo $r
}
function c.help() { # 显示自定义命令列表, 同 `help`, `h`
{ setopt BASH_REMATCH } || {} # zsh
reg='^ *(function) +([a-zA-Z0-9\.]+)[^#]*#? *(.*)'
func_list=()
func_desc=()
max=0
meet=0
cat ~/.bash_profile | while read line
do
if [[ meet -eq 1 ]] && [[ $line =~ '^ *#(.*)' ]]
then
func_desc[${#func_desc[@]}]+="\n > ${BASH_REMATCH[2]}"
elif [[ $line =~ $reg ]]
then
meet=1
func_list[${#func_list[@]}+1]="${BASH_REMATCH[3]}"
if [[ ${#BASH_REMATCH[3]} -gt max ]]; then
max=${#BASH_REMATCH[3]}
fi
if [[ $BASH_REMATCH[4] ]]
then; func_desc[${#func_desc[@]}+1]="${BASH_REMATCH[4]}"
fi
else
meet=0
fi
done
i=0
for fn in ${func_list[@]}; do
i=$(expr $i + 1)
s=`pad_left $fn $(expr $max + 2)`
s=`c.red $s`
s=' '$s': '`c.magenta ${func_desc[$i]}`
if [[ $1 ]]; then
if [[ $fn =~ $1 ]]; then
echo -e '\n'$s
fi
else
echo -e '\n'$s
fi
done
}
help() {
c.help $@
}
h() {
c.help $@
}
function c.addPath() { # 临时添加系统路径
PATH=$PATH:$1
}
function c.qt() { # 打开 qt 文档
open "https://doc.qt.io/qtforpython-6/PySide6/$1/$2.html"
}
function c.reload() { # 重新加载 bash profile,同 `c.r`
source ~/.bash_profile
}
c.r() {
c.reload
}
function c.translate() { # 翻译,同 `c.t`
python3 $__DIR__/py/translate.py "$@"
}
c.t() {
c.translate $@
}
function c.resou() { # 热搜
python3 $__DIR__/py/resou.py "$@"
}
function c.mdn() { # 搜索 MDN
python3 $__DIR__/py/mdn.py "$@"
}
function c.baidu() { # 百度搜索,同 `c.b`
open "https://www.baidu.com/s?wd=$*"
}
c.b() {
c.baidu $@
}
baidu() {
c.baidu $@
}
function c.google() { # 谷歌搜索,同 `c.g`
open "https://www.google.com/search?q=$*"
}
c.g() {
c.google $@
}
s() {
c.google "$@"
}
function c.gt() { # 谷歌翻译
open "https://translate.google.cn/?sl=auto&tl=zh-CN&text=$*&op=translate"
}
function c.bing() { # bing搜索,同 `c.bi`
open "https://cn.bing.com/search?q=$*"
}
c.bi() {
c.bing $@
}
bing() {
c.bing $@
}
function c.github() { # github搜索,同 `c.git`
# 搜索的文本所在地: `in:name`, `in:description`, `in:readme`, `in:file`, `in:path`
# 仓库 : `repo:OWNER/NAME`
# 语言 : `language:LANGUAGE`
# 用户 : `user:USERNAME`
# 组织 : `org:ORGNAME`
# 主题 : `topic:TOPIC`
# 文件名 : `filename:FILENAME`
# 后缀名 : `extension:EXTENSION`
# 关注数 : `followers:n` (:n, :>n, :<n, :m..n)
# fork数 : `forks:n` (:n, :>=n, :<n, :m..n)
# star数 : `stars:n` (:n, :>n, :<n, :m..n)
# 创建时间 : `created:YYYY-MM-DD`
# 推送时间 : `pushed:YYYY-MM-DD`
# 仓库的可见性 : `is:public`, `is:private`, `is:internal`
# 是否是镜像 : `mirror:true`, `mirror:false`
# 是否已归档 : `archived:true`, `archived:false`
#
# 更多见:https://docs.github.com/en/github/searching-for-information-on-github/searching-on-github
open "https://github.com/search?q=$*"
}
c.git() {
c.github $@
}
c.hub() {
c.github $@
}
hub() {
c.github "$@"
}
alias prelude='~/Documents/GitHub/scripts/shell/prelude.sh'
function snpm() { # 搜索npm包
npm search "$@" --json | prelude -c jsonf -acf 'name,version,links.npm,links.repository' | tabulate -1
}
function rustmd() {# rust 帮助文档 markdown修复
# 1. 给代码块加上 rust 标记,以高亮,配合 `bat` 使用, e.g. `rustc --explain E0277 | rustmd | bat -l md`
while read line; do { if [[ $line = '```' ]]; then [[ $count -ne 1 ]] && { echo $line'rust'; count=1 } || { count=0; echo $line; }; else echo $line; fi }; done
}