blob: ff22fe71250b0add5494cf831229aa7602582acf (
plain)
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
|
#我经过shorin本人同意后,把本aur包需要的源代码上传至gitee,并且修改了源代码获取的地址,其他无改动,我的邮箱:3824280949@qq.com
# Maintainer: Shorin <2433516202@qq.com>
pkgname=shorin-contrib-gitee-git
_pkgname=shorin-contrib
pkgver=r61.fe88d7d
pkgrel=1
pkgdesc="Shorin's personal Arch Linux toolbox and system utilities (Subcommand version)"
arch=('any')
url="https://gitee.com/jxc20120414/shorin-contrib"
license=('GPL3')
depends=('bash' 'fzf')
makedepends=('git')
install='shorin-contrib.install'
# 可选依赖:让用你包的人知道特定子命令需要什么环境
optdepends=(
'snapper: for quicksave/quickload btrfs snapshot support'
'btrfs-assistant: for advanced btrfs restoration backend'
'fuzzel: for GUI menus in Wayland'
'libnotify: for desktop notifications'
'ffmpeg: for video2gif utility'
'timg: for lsi image preview'
)
provides=("${_pkgname}")
conflicts=("${_pkgname}")
source=("git+https://gitee.com/jxc20120414/shorin-contrib.git")
sha256sums=('SKIP')
# 自动获取最新的 Git commit 数量作为版本号
pkgver() {
cd "${_pkgname}"
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
package() {
cd "${_pkgname}"
# 1. 创建私有库目录
install -dm755 "${pkgdir}/usr/lib/${_pkgname}"
# 2. 拍平复制所有脚本
find . -mindepth 2 -type f -not -path "*/\.git/*" -exec install -Dm755 {} "${pkgdir}/usr/lib/${_pkgname}/" \;
# 3. 配置全局命令
install -dm755 "${pkgdir}/usr/bin"
# 系统级(需 root 或全局可用)的命令,直接在打包阶段链接到 /usr/bin
ln -sf "/usr/lib/${_pkgname}/quicksave" "${pkgdir}/usr/bin/quicksave"
ln -sf "/usr/lib/${_pkgname}/quickload" "${pkgdir}/usr/bin/quickload"
ln -sf "/usr/lib/${_pkgname}/change-grub-theme" "${pkgdir}/usr/bin/change-grub-theme"
# 写入增强版 shorin 主调度器
cat << 'EOF' > "${pkgdir}/usr/bin/shorin"
#!/bin/bash
set -euo pipefail
# =============================================================================
# 功能描述: Shorin Contrib 的主调度器。
# 支持动态解析子命令描述,并根据 LANG 环境变量显示中文/英文。
# =============================================================================
LIB_DIR="/usr/lib/shorin-contrib"
# --------------------- 语言检测 ---------------------
if [[ "${LANG:-}" == zh_CN* ]]; then
IS_CN=true
else
IS_CN=false
fi
# --------------------- 双语字符串定义 ---------------------
if $IS_CN; then
USAGE_STR="用法:"
AVAIL_STR="可用子命令:"
ENV_STR="环境管理:"
LINK_DESC="生成本地用户的快捷软链接 (全程免密)"
UNLINK_DESC="移除本地软链接"
LINK_START="开始生成本地快捷命令..."
LINK_DONE="链接部署完成!"
LINK_ITEM="[User] 已链接:"
UNLINK_START="开始清理快捷命令..."
UNLINK_DONE="链接清理完成!"
UNLINK_ITEM="[User] 已移除:"
UNKNOWN_CMD="未知子命令"
SUB_PLACEHOLDER="<子命令>"
OPT_PLACEHOLDER="[选项]"
else
USAGE_STR="Usage:"
AVAIL_STR="Available subcommands:"
ENV_STR="Environment management:"
LINK_DESC="Create no-password local symlinks for user"
UNLINK_DESC="Remove local symlinks"
LINK_START="Creating local symlinks..."
LINK_DONE="Symlink deployment complete!"
LINK_ITEM="[User] Linked:"
UNLINK_START="Cleaning up symlinks..."
UNLINK_DONE="Symlink cleanup complete!"
UNLINK_ITEM="[User] Removed:"
UNKNOWN_CMD="unknown subcommand"
SUB_PLACEHOLDER="<subcommand>"
OPT_PLACEHOLDER="[options]"
fi
# 颜色定义
BLUE='\033[0;34m'
NC='\033[0m'
# ===================== 无参数时显示帮助 =====================
if [ $# -eq 0 ]; then
echo -e "${USAGE_STR} ${BLUE}shorin${NC} ${SUB_PLACEHOLDER} ${OPT_PLACEHOLDER}"
echo -e "\n${AVAIL_STR}"
# 遍历库目录,提取对应语言的描述
for script in "$LIB_DIR"/*; do
if [ -x "$script" ]; then
name=$(basename "$script")
if $IS_CN; then
# 中文:提取第二行,去掉 "# 描述:" 前缀
desc=$(sed -n '2p' "$script" | sed -E 's/^#[[:space:]]*描述:[[:space:]]*//')
else
# 英文:提取第三行,去掉 "# Description:" 前缀
desc=$(sed -n '3p' "$script" | sed -E 's/^#[[:space:]]*Description:[[:space:]]*//')
fi
# 若描述为空,显示占位符
[ -z "$desc" ] && desc="-"
printf " ${BLUE}%-15s${NC} %s\n" "$name" "$desc"
fi
done | sort
echo -e "\n${ENV_STR}"
printf " ${BLUE}%-15s${NC} %s\n" "link" "$LINK_DESC"
printf " ${BLUE}%-15s${NC} %s\n" "unlink" "$UNLINK_DESC"
exit 1
fi
COMMAND="$1"
shift
# ===================== 软链接管理 =====================
if [ "$COMMAND" = "link" ]; then
mkdir -p "$HOME/.local/bin"
echo "$LINK_START"
for script in "$LIB_DIR"/*; do
if [ -f "$script" ]; then
base_name=$(basename "$script")
if [[ "$base_name" != "quicksave" && "$base_name" != "quickload" && "$base_name" != "change-grub-theme" ]]; then
ln -sf "$script" "$HOME/.local/bin/$base_name"
echo " ${LINK_ITEM} ~/.local/bin/$base_name"
fi
fi
done
echo -e "\n${LINK_DONE}"
exit 0
elif [ "$COMMAND" = "unlink" ]; then
echo "$UNLINK_START"
for script in "$LIB_DIR"/*; do
if [ -f "$script" ]; then
base_name=$(basename "$script")
if [[ "$base_name" != "quicksave" && "$base_name" != "quickload" && "$base_name" != "change-grub-theme" ]]; then
rm -f "$HOME/.local/bin/$base_name"
echo " ${UNLINK_ITEM} ~/.local/bin/$base_name"
fi
fi
done
echo -e "\n${UNLINK_DONE}"
exit 0
fi
# ===================== 执行子命令 =====================
TARGET_SCRIPT="$LIB_DIR/$COMMAND"
if [ -x "$TARGET_SCRIPT" ]; then
exec "$TARGET_SCRIPT" "$@"
else
echo "shorin: ${UNKNOWN_CMD} '$COMMAND'" >&2
exit 1
fi
EOF
chmod +x "${pkgdir}/usr/bin/shorin"
# 4. Fish 补全 (保持不变)
install -dm755 "${pkgdir}/usr/share/fish/vendor_completions.d"
cat << 'EOF' > "${pkgdir}/usr/share/fish/vendor_completions.d/shorin.fish"
complete -c shorin -f
complete -c shorin -a "(ls /usr/lib/shorin-contrib/ 2>/dev/null)"
EOF
}
|