-
Notifications
You must be signed in to change notification settings - Fork 12
/
_sh
executable file
·344 lines (287 loc) · 12.7 KB
/
_sh
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/zsh
alias hl='hl'
function hl() {
if [ $# -eq 0 ]; then
echo "Usage: $0"
return 1
fi
}
# https://docs.npmjs.com/cli/v10/commands/npm
# https://pnpm.io/cli/add
# https://pnpm.io/workspaces
# pnpm v7 文档 https://github.com/pnpm/pnpm.io/blob/v7/docs/workspaces.md
function nodePro() {
# --loglevel silly --yes --no-commit-hooks
# --include-merged-tags --no-push --no-git-tag-version
npx lerna changed
npx lerna version patch --exact
npx lerna version patch --exact --message '🎨 chore(release): Publish' --conventional-commits
npx lerna version prerelease --preid beta
npx lerna publish prerelease --preid rc --dist-tag rc
npx lerna publish from-git --preid rc --dist-tag rc
npx lerna publish from-package
# pnpm 处理 workspaces ( pnpm>9.0 link-workspace-packages 默认为 false )
pnpm run script-name --filter workspace-name
pnpm add package-name --filter workspace-name --link-workspace-packages=true
pnpm update package-name --filter workspace-name
pnpm outdated package-name --filter workspace-name --json
pnpm outdated -r
pnpm ls -r --json # 等效 npx lerna ls --graph
pnpm ls -r --depth -1 --json # 等效 npx lerna ls --long
pnpm up -r @afe/[email protected] # 更新不存在的版本号会报错
# 更新 包的版本号为 "@afe/pro-form": "workspace:0.1.3"
pnpm up -r "@afe/pro-*" # 加 --workspace 作用一样
# 升级到 npm latest 指定的版本
# 如果 workspace 内部包 版本号大于npm最新版 则使用内部包版本号
pnpm up -r "@afe/pro-*" --latest
pnpm up -r "@afe/pro-*@beta" # 升级到 beta rc
npm version patch --no-git-tag-version --workspaces
npm version prerelease --preid rc --no-git-tag-version --workspaces
pnpm install --ignore-engines --ignore-platform
pnpm view @afe/pro-card --json --registry http://comm-npm.tem.team
npm update package1 package2 --save
# 搜索组织下的包 https://www.npmjs.com/org/ant-design
npm --searchlimit=100 search @ant-design
npm ls pkg_name
npm ls --all --json --loglevel silent
npm ls --all -g
npm ls -g
npm root -g
which npm/node # 查看本地安装的模块
# npx 用法
npx ls # 等同于 ls
npx mocha --version
npx http-server
# 忽略本地的同名模块 --no-install 强制使用本地模块
npx --ignore-existing http-server
# https://code.visualstudio.com/api/get-started/your-first-extension
npx --package yo --package generator-code -- yo code
npm config ls
npm config set registry https://registry.npmmirror.com -g
npm i --registry https://registry.npmmirror.com
npm i --registry https://registry.npmjs.org
}
function gitPro() {
code ~/.zsh_history
code ~/.gitconfig
code ~/.gitconfig-github
open https://github.com/paulirish/git-open
open https://gitlab.com/warmhug/test
# 对比 feat 分支和 master 的差异
git cherry -v master feat-xx
git log master..feat-xx --oneline
git diff master..feat-xx
current_branch=$(git rev-parse --abbrev-ref HEAD)
git log -n 10
git log --graph
git log --oneline --decorate
git log --oneline --first-parent --reverse | tail -1
git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all
git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"
git diff --name-only version1/branch1 version2/branch2
# 比较当前分支和 master 分支的实际不同的内容
git diff --name-only master..HEAD
git diff master..HEAD -b -w --ignore-blank-lines --ignore-space-change --ignore-all-space -p --stat [file/dir]
git diff master..HEAD -b -w --ignore-blank-lines --ignore-space-change --ignore-all-space --name-only
git diff @{upstream}
git commit --amend # 修改提交信息
# 压缩 commit
git merge --squash feature-branch
# 保留压缩前的所有commit信息 其中的 hash 修改记录 也会被保留
git add .
git commit --no-verify
# git merge 会产生重复无用的 Merge pull request pull_id from xx_branch 或者 Merge branch “branch_name” 信息,不利于 review 提交记录。
# git rebase 需要经常 reapply 其他提交的改动,commit 的时间顺序也会乱掉。只对自己的分支 commit 做 rebase,公共的分支不要 rebase. 其后续的 commit hash 将全部改变
git rebase -i [commit_id] # hash 换成 master
git rebase origin/master
git push --force-with-lease # 强制提交 比 -f 安全
git reset [file | 057d] # 回退文件、或回退到某个版本
git reset HEAD^ [file] # 回退 所有内容或某个文件 到上一个版本
git revert commit_id # 回滚代码 不抹掉 提交记录 产生新纪录
# --soft 不修改本地文件 --hard 本地的文件修改都被丢弃
git reset --[soft | hard] [HEAD^ | 057d]
git reset --hard origin/master # 将本地的状态回退到和远程的一样
git reflog # 撤销 reset 时 找到撤销前的 commit_id 再 git reset 即可
# 解决冲突
# Git 合并出现冲突的原因在于 两个分支版本对一个文件的同一区域 做了修改。如果是不同区域,Git 会尝试自动合并(auto-merge,默认策略)解决冲突。 https://www.freecodecamp.org/news/resolve-merge-conflicts-in-git-a-practical-guide/
# 操作 https://stackoverflow.com/a/930495/2190503
git stash push lock.yaml # 暂存 lock 文件,使用当前 lock 文件
git checkout --ours "*lock*" # 使用 当前或目标(--theirs) 的 lock 文件
# 在 .gitattributes 文件里配置 当 pnpm-lock.yaml 出现冲突时,将以当前分支为准
pnpm-lock.yaml merge=ours
# pristine
git reset --hard && git clean --force -dfx
# wipe
git reset --hard && git clean --force -df
#
git pull --rebase # 同 git fetch + git rebase
# 打 annotated tags
git tag -v @afe/[email protected]
git tag -a 0.0.1 -m 'Release version 0.0.1'
git fetch --all --tags
git push [origin] --tags # 推送所有标签到服务器
git push origin --delete tag_name
# tag 只附在一个 commit 上、如果这个 commit 被 squash,但 tag 仍然存在。
# https://stackoverflow.com/questions/54281360/what-happens-to-tags-of-squashed-commits
# 从另一个仓库的分支 pick 先 git fetch <other-repo-url> <other-branch>
git cherry-pick commit-hash # commit-hash 可以是其他仓库的hash
git stash show --patch
git worktree list
cd "$(git rev-parse --show-toplevel || echo .)"
# push_beta="branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD) && echo ${branch}"
git remote [-v add | set-url] origin [email protected]
# GitHub stars topics/javascript
# https://github.com/search?q=stars:%3E1&s=stars&type=Repositories
# https://github.com/topics/javascript
# 搜索 issues
# https://help.github.com/articles/searching-issues/
# https://github.com/search?type=Issues&q=xx+in:body+author:warmhug
# https://github.com/search?type=Issues&q=xx+commenter:warmhug+user:ant-design
# https://github.com/search?type=Issues&q=xx+commenter:warmhug+repo:ant-design/ant-design-mobile
# GitHub commit 或合并 MR 时,可以自动修改 issue 状态、关闭关联的 issue。
# 业内成熟的 GIT 分支模型 https://cloud.githubusercontent.com/assets/36899/7315642/015f534c-eaa2-11e4-9882-b7cc7535fb72.png
# GitHub Issues blog https://gitblog.io/
}
function setAlias() {
#
alias proxy='export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890'
alias py='python3 -m http.server 3000'
alias cc='code ~/.config/clash/ss.yaml'
# 重启 webshelll
alias webshell='sudo supervisord -c /usr/local/etc/supervisord.conf'
# pnpm i 如果安装报错,比如 node pnpm 版本有切换、尝试清空重装
alias re='rm pnpm-lock.yaml && git clean -xdf && pnpm store prune && pnpm i'
# git
alias gaa='git add --all'
alias gb='git branch'
alias gba='git branch --all'
# 删除本地除 当前和master 分支外的其他分支
alias gbd='git branch | grep -v "master" | xargs git branch -D'
alias gc='git checkout'
alias gd='git diff'
alias gl='git log'
alias glp='git log -p'
alias gp='git pull -p'
alias gs='git status'
}
setAlias
function note() {
code /Users/hua/Library/CloudStorage/OneDrive-个人/_misc.txt
code /Users/hua/Library/CloudStorage/OneDrive-个人/_life.txt
code /Users/hua/Library/CloudStorage/OneDrive-个人/_work.txt
}
function hl-file() {
return 1
more filename # 一页一页的显示档案内容.
head/tail -n 20 ~/.zsh_history # 只看 头/尾 几行(默认10行)
history 10 # 列出10条
mv fname rename / cat -n fname / say hello / type -a node(pwd) / ln -s source_file dist
env / w / who / whoami / tty / last / nettop / nslookup / mtr -r
date # 显示系统的当前日期和时间 date "+%Y-%m-%d_%H:%M:%S"
curl https://www.baidu.com -o xx.html # 下载页面到 xx.html 里
mkdir -p ~/inner/aa && touch $_/file.txt # 创建目录并能生成文件
echo ttt > ./file.txt # 覆盖文件原内容并重新输入内容,若文件不存在则创建文件
echo `which node` >> ./file.txt # 向文件追加内容,原内容将保存
grep -rn 'grep' * # 以 字符串 grep 来搜索 当前目录及子目录 的所有文件内容
grep grep$ she*.md # 以 正则表达式 grep$ 来搜索 当前目录下 文件名匹配 she*.md 的内容
grep -r --include=\*.{cpp,h} pattern ./
grep -r --exclude-dir=node_modules pattern ~/
# ls 命令默认只显示文件名
ls -d $PWD/*
ls -la
find . -name '*bash*'
find . -name "*.js" -not -path "*node_modules*" -not -path "*js-css-html*"
find . -name '*.DS_Store' -type f -delete # 删除某目录及子目录下的 .DS_Store 文件
# find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件(modify time)
}
function mac() {
return 1
echo "system: $HOME $PATH $SHELL"
open -a Activity\ Monitor # 打开活动监视器 或者 "Activity Monitor"
top # 或 top -o cpu 按 q 退出. man top
ps -ax
ps -ef | grep adb # 有时候 adb devices 没反应 需要杀掉进程重启
lsof -i:8087 # 查找出占用了某个端口的程序和其对应的PID
kill 3747(进程id) # 杀掉后台进程
kill -9 $(lsof -ti:3000,3001) # 杀掉端口占用的进程
kill -9 *pid* # 强制杀掉进程
zsh_stats # 命令使用状态
# brew 国内源 https://www.jianshu.com/p/bea984d27cd2
cd/ls/tree "$(brew --repo)"
brew config
# 更换 home-bottles
export HOMEBREW_BOTTLE_DOMAIN=http://mirrors.aliyun.com/homebrew/homebrew-bottles
brew install tree
xcode-select --install # 安装 git gcc
# 阻止电脑睡眠 同时按住 shift、control、电源键,关闭显示器
# pmset noidle
# defaults read com.apple.screencapture # 查看系统截图设置
# 将系统截屏后图片保存为 jpg 格式,体积比原 png 格式显著缩小
defaults write com.apple.screencapture type jpg
# 修改截屏图片保存路径
defaults write com.apple.screencapture location ~/Downloads/
sips -z height width [file]
# 批量修改 宽或高 最大值 保持宽高比
sips -Z 640 *.jpg
# zip加解密 https://www.jianshu.com/p/bf4a6244180f
zip -e output.zip ~/xx.txt
# 查看状态
csrutil status
# 关闭 sip 关机、按住电源键(非m1按下`Cmd R`) 选择实用工具->终端
# csrutil disable
# 允许安装”任何来源“的软件,解决 Movist.app已损坏 问题
sudo spctl --master-disable
# macOS 14.4 以上版本,需要运行此命令后 再右键打开
xattr -cr /Applications/Movist.app
# 查看本机内网IP
ifconfig
# 查看本机公网IP
curl ipinfo.io/json # curl ifconfig.me
# 查看域名路由 或 `ping baidu.com`
traceroute baidu.com
}
function commit() {
# printf "\n"
echo "\033[32m git op (y/n)? \033[0m"
read git_op
[[ $git_op = "n" ]] && exit
BASEDIR=$(dirname $0)
## echo $BASEDIR
cd $BASEDIR
echo "\033[32m git status \033[0m"
git st
echo "\033[32m git add -A \033[0m"
git add -A
echo "\033[32m git ci \033[0m"
git ci -a -m 'autocommit'
echo "\033[32m git push \033[0m"
git push
read -p "Press Return to Close..."
}
# 基本语法
function base_grammar() {
: <<COMMENT
多行注释
export hl=hl
export -f hl
COMMENT
if false; then
这是多行注释的内容。
fi
# return 1
# exit 1
printenv HOME # 打印环境变量
local str="long...\
实际不换行"
local str1="第一行
第二行"
local num=1
local num="$num"2 # 或 num=${num}2
local new_msg="Merged $(($num-1)) $((${num}-1)) commits"
echo $str $str1 $num $new_msg
local blank_path="/Applications/Google\" \"Chrome.app/Contents/MacOS/Google\" \"Chrome"
local blank_path=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
local blank_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
local escaped_blank_path=${blank_path////\\/}
echo $escaped_blank_path
}