-
Notifications
You must be signed in to change notification settings - Fork 292
/
lint.sh
executable file
·50 lines (34 loc) · 894 Bytes
/
lint.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
#!/bin/zsh
###
# @Author: shgopher [email protected]
# @Date: 2023-11-16 14:31:20
# @LastEditors: shgopher [email protected]
# @LastEditTime: 2023-11-22 14:09:17
# @FilePath: /GOFamily/lint.sh
# @Description:
#
# Copyright (c) 2023 by shgopher, All Rights Reserved.
###
find_md(){
local printed_files=()
# 检查 zhlint 命令是否存在
if ! [ -x "$(command -v zhlint)" ]; then
# 安装 zhlint
npm install -g zhlint > /dev/null
fi
for item in $(ls -R "$1"); do
if [[ "$item" == *.md ]]; then
path="$1/$item"
if [[ ! " ${printed_files[@]} " =~ " $path " ]]; then
echo "$path"
# 调用zhlint格式化
zhlint "$path" --fix > /dev/null
printed_files+=("$path")
fi
elif [[ -d "$1/$item" ]]; then
find_md "$1/$item"
fi
done
}
# 调用
find_md "$(pwd)"