@jswork/ushell-module-base 1.0.71 → 1.0.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/modules/_mkp.sh +59 -0
- package/package.json +4 -1
package/CHANGELOG.md
ADDED
package/modules/_mkp.sh
CHANGED
|
@@ -3,3 +3,62 @@
|
|
|
3
3
|
function mkp() {
|
|
4
4
|
mkdir -p "$1" && cd "$1"
|
|
5
5
|
}
|
|
6
|
+
|
|
7
|
+
mkfile() {
|
|
8
|
+
local force=0
|
|
9
|
+
|
|
10
|
+
# 解析选项
|
|
11
|
+
while [[ $# -gt 0 && "$1" == -* ]]; do
|
|
12
|
+
case "$1" in
|
|
13
|
+
-f|--force) force=1; shift ;;
|
|
14
|
+
-h|--help)
|
|
15
|
+
echo "Usage: mkfile [-f] <file-path> [content...]"
|
|
16
|
+
echo " -f, --force Overwrite if file exists"
|
|
17
|
+
echo " If content is provided, it will be written to the file."
|
|
18
|
+
echo " If not, an empty file is created (or stdin if piped)."
|
|
19
|
+
return 0
|
|
20
|
+
;;
|
|
21
|
+
*)
|
|
22
|
+
echo "❌ Unknown option: $1" >&2
|
|
23
|
+
return 1
|
|
24
|
+
;;
|
|
25
|
+
esac
|
|
26
|
+
done
|
|
27
|
+
|
|
28
|
+
if [[ $# -eq 0 ]]; then
|
|
29
|
+
echo "Usage: mkfile [-f] <file-path> [content...]" >&2
|
|
30
|
+
echo " Use -h for more help" >&2
|
|
31
|
+
return 1
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
local filepath="$1"
|
|
35
|
+
shift
|
|
36
|
+
|
|
37
|
+
# 创建父目录
|
|
38
|
+
local dirpath
|
|
39
|
+
dirpath="$(dirname "$filepath")"
|
|
40
|
+
if [[ -n "$dirpath" && "$dirpath" != "." ]]; then
|
|
41
|
+
mkdir -p "$dirpath" || return 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
# 检查文件是否已存在
|
|
45
|
+
if [[ -e "$filepath" ]]; then
|
|
46
|
+
if [[ $force -eq 1 ]]; then
|
|
47
|
+
echo "⚠️ Overwriting: $filepath"
|
|
48
|
+
else
|
|
49
|
+
echo "❌ File already exists: $filepath (use -f to overwrite)" >&2
|
|
50
|
+
return 1
|
|
51
|
+
fi
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# 写入内容
|
|
55
|
+
if [[ $# -gt 0 ]]; then
|
|
56
|
+
printf '%s\n' "$*" > "$filepath"
|
|
57
|
+
elif [[ ! -t 0 ]]; then
|
|
58
|
+
cat > "$filepath"
|
|
59
|
+
else
|
|
60
|
+
touch "$filepath"
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
echo "✅ Created: $filepath"
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jswork/ushell-module-base",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.72",
|
|
4
4
|
"description": "Unix like shell base module.",
|
|
5
5
|
"main": "index.sh",
|
|
6
6
|
"repository": {
|
|
@@ -27,5 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"release": "release-it"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@release-it/conventional-changelog": "^10.0.4"
|
|
30
33
|
}
|
|
31
34
|
}
|