Skip to content

Commit 08a62ee

Browse files
committed
2 parents 48f4710 + c9c393f commit 08a62ee

5 files changed

Lines changed: 298 additions & 3 deletions

File tree

gohot.ps1

Lines changed: 0 additions & 2 deletions
This file was deleted.

linux/ubuntu/apply_config.sh

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#!/bin/bash
2+
3+
# 配置应用脚本 - 通过软链接快速应用shell配置文件
4+
# 作者: mudssky
5+
# 用途: 快速应用config目录下的配置文件到用户主目录
6+
7+
# 获取脚本所在目录
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
CONFIG_DIR="$SCRIPT_DIR/config"
10+
11+
# 颜色定义
12+
RED='\033[0;31m'
13+
GREEN='\033[0;32m'
14+
YELLOW='\033[1;33m'
15+
BLUE='\033[0;34m'
16+
NC='\033[0m' # No Color
17+
18+
# 日志函数
19+
log_info() {
20+
echo -e "${BLUE}[INFO]${NC} $1"
21+
}
22+
23+
log_success() {
24+
echo -e "${GREEN}[SUCCESS]${NC} $1"
25+
}
26+
27+
log_warning() {
28+
echo -e "${YELLOW}[WARNING]${NC} $1"
29+
}
30+
31+
log_error() {
32+
echo -e "${RED}[ERROR]${NC} $1"
33+
}
34+
35+
# 检查配置目录是否存在
36+
check_config_dir() {
37+
if [ ! -d "$CONFIG_DIR" ]; then
38+
log_error "配置目录不存在: $CONFIG_DIR"
39+
exit 1
40+
fi
41+
}
42+
43+
# 备份现有配置文件
44+
backup_existing_config() {
45+
local config_file="$1"
46+
local home_path="$HOME/$config_file"
47+
48+
if [ -e "$home_path" ] && [ ! -L "$home_path" ]; then
49+
local backup_path="${home_path}.backup.$(date +%Y%m%d_%H%M%S)"
50+
log_warning "备份现有配置文件: $home_path -> $backup_path"
51+
mv "$home_path" "$backup_path"
52+
elif [ -L "$home_path" ]; then
53+
log_info "移除现有软链接: $home_path"
54+
rm "$home_path"
55+
fi
56+
}
57+
58+
# 创建软链接
59+
create_symlink() {
60+
local config_file="$1"
61+
local source_path="$CONFIG_DIR/$config_file"
62+
local target_path="$HOME/$config_file"
63+
64+
if [ ! -f "$source_path" ]; then
65+
log_error "配置文件不存在: $source_path"
66+
return 1
67+
fi
68+
69+
# 备份现有配置
70+
backup_existing_config "$config_file"
71+
72+
# 创建软链接
73+
ln -s "$source_path" "$target_path"
74+
75+
if [ $? -eq 0 ]; then
76+
log_success "成功创建软链接: $target_path -> $source_path"
77+
return 0
78+
else
79+
log_error "创建软链接失败: $target_path"
80+
return 1
81+
fi
82+
}
83+
84+
# 应用zsh配置
85+
apply_zsh_config() {
86+
log_info "应用 Zsh 配置..."
87+
88+
if create_symlink ".zshrc"; then
89+
if [ -f "$CONFIG_DIR/.p10k.zsh" ]; then
90+
create_symlink ".p10k.zsh"
91+
fi
92+
log_success "Zsh 配置应用完成"
93+
else
94+
log_error "Zsh 配置应用失败"
95+
return 1
96+
fi
97+
}
98+
99+
# 应用bash配置
100+
apply_bash_config() {
101+
log_info "应用 Bash 配置..."
102+
103+
if create_symlink ".bashrc"; then
104+
log_success "Bash 配置应用完成"
105+
else
106+
log_error "Bash 配置应用失败"
107+
return 1
108+
fi
109+
}
110+
111+
# 应用所有可用配置
112+
apply_all_configs() {
113+
log_info "应用所有可用配置..."
114+
115+
local applied_count=0
116+
117+
# 检查并应用zsh配置
118+
if [ -f "$CONFIG_DIR/.zshrc" ]; then
119+
apply_zsh_config && ((applied_count++))
120+
fi
121+
122+
# 检查并应用bash配置
123+
if [ -f "$CONFIG_DIR/.bashrc" ]; then
124+
apply_bash_config && ((applied_count++))
125+
fi
126+
127+
# 应用其他配置文件
128+
for config_file in "$CONFIG_DIR"/.*; do
129+
if [ -f "$config_file" ]; then
130+
local filename=$(basename "$config_file")
131+
case "$filename" in
132+
".zshrc"|"p10k.zsh"|"bashrc")
133+
# 已经处理过的文件,跳过
134+
;;
135+
"."|"..")
136+
# 跳过当前目录和父目录
137+
;;
138+
*)
139+
if create_symlink "$filename"; then
140+
((applied_count++))
141+
fi
142+
;;
143+
esac
144+
fi
145+
done
146+
147+
log_success "总共应用了 $applied_count 个配置文件"
148+
}
149+
150+
# 列出可用配置
151+
list_configs() {
152+
log_info "可用的配置文件:"
153+
154+
if [ -d "$CONFIG_DIR" ]; then
155+
for config_file in "$CONFIG_DIR"/.*; do
156+
if [ -f "$config_file" ]; then
157+
local filename=$(basename "$config_file")
158+
case "$filename" in
159+
"."|"..")
160+
# 跳过当前目录和父目录
161+
;;
162+
*)
163+
local target_path="$HOME/$filename"
164+
if [ -L "$target_path" ] && [ "$(readlink "$target_path")" = "$config_file" ]; then
165+
echo -e " ${GREEN}${NC} $filename (已链接)"
166+
else
167+
echo -e " ${YELLOW}${NC} $filename (未链接)"
168+
fi
169+
;;
170+
esac
171+
fi
172+
done
173+
else
174+
log_error "配置目录不存在: $CONFIG_DIR"
175+
fi
176+
}
177+
178+
# 显示帮助信息
179+
show_help() {
180+
echo "配置应用脚本 - 通过软链接快速应用shell配置文件"
181+
echo ""
182+
echo "用法: $0 [选项]"
183+
echo ""
184+
echo "选项:"
185+
echo " zsh, z 应用 Zsh 配置 (.zshrc, .p10k.zsh)"
186+
echo " bash, b 应用 Bash 配置 (.bashrc)"
187+
echo " all, a 应用所有可用配置"
188+
echo " list, l 列出所有可用配置"
189+
echo " help, h 显示此帮助信息"
190+
echo ""
191+
echo "示例:"
192+
echo " $0 zsh # 应用 Zsh 配置"
193+
echo " $0 bash # 应用 Bash 配置"
194+
echo " $0 all # 应用所有配置"
195+
echo " $0 list # 列出可用配置"
196+
echo ""
197+
echo "配置文件位置: $CONFIG_DIR"
198+
}
199+
200+
# 主函数
201+
main() {
202+
# 检查配置目录
203+
check_config_dir
204+
205+
# 解析命令行参数
206+
case "${1:-help}" in
207+
"zsh"|"z")
208+
apply_zsh_config
209+
;;
210+
"bash"|"b")
211+
apply_bash_config
212+
;;
213+
"all"|"a")
214+
apply_all_configs
215+
;;
216+
"list"|"l")
217+
list_configs
218+
;;
219+
"help"|"h"|"")
220+
show_help
221+
;;
222+
*)
223+
log_error "未知选项: $1"
224+
echo ""
225+
show_help
226+
exit 1
227+
;;
228+
esac
229+
}
230+
231+
# 执行主函数
232+
main "$@"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
4+
###################################
5+
# Prerequisites
6+
7+
# Update the list of packages
8+
sudo apt-get update
9+
10+
# Install pre-requisite packages.
11+
sudo apt-get install -y wget curl
12+
13+
# Get the latest PowerShell version from GitHub API
14+
echo "Getting latest PowerShell version..."
15+
LATEST_VERSION=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
16+
echo "Latest version: $LATEST_VERSION"
17+
18+
# Download the PowerShell package file
19+
PACKAGE_NAME="powershell_${LATEST_VERSION#v}-1.deb_amd64.deb"
20+
DOWNLOAD_URL="https://github.com/PowerShell/PowerShell/releases/download/$LATEST_VERSION/$PACKAGE_NAME"
21+
echo "Downloading $PACKAGE_NAME..."
22+
wget "$DOWNLOAD_URL"
23+
24+
###################################
25+
# Install the PowerShell package
26+
sudo dpkg -i "$PACKAGE_NAME"
27+
28+
# Resolve missing dependencies and finish the install (if necessary)
29+
sudo apt-get install -f
30+
31+
# Delete the downloaded package file
32+
rm "$PACKAGE_NAME"
33+
34+
# Start PowerShell Preview
35+
pwsh
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
4+
###################################
5+
# Prerequisites
6+
7+
# Update the list of packages
8+
sudo apt-get update
9+
10+
# Install pre-requisite packages.
11+
sudo apt-get install -y wget
12+
13+
# Download the PowerShell package file
14+
wget https://github.com/PowerShell/PowerShell/releases/download/v7.5.1/powershell_7.5.1-1.deb_amd64.deb
15+
16+
###################################
17+
# Install the PowerShell package
18+
sudo dpkg -i powershell_7.5.1-1.deb_amd64.deb
19+
20+
# Resolve missing dependencies and finish the install (if necessary)
21+
sudo apt-get install -f
22+
23+
# Delete the downloaded package file
24+
rm powershell_7.5.1-1.deb_amd64.deb
25+
26+
# Start PowerShell Preview
27+
pwsh

templates/golang.scripts.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"test": "go test",
44
"goproxy": "go env -w GOPROXY=https://goproxy.cn,direct",
55
"mod:on": "go env -w GO111MODULE=on",
6-
"mod:clean": "go mod tidy"
6+
"mod:clean": "go mod tidy",
7+
"watch": "watchexec.exe --restart --clear --exts go --no-project-ignore go run ./main.go",
8+
"watch:test": "watchexec.exe --restart --clear --exts go --no-project-ignore go test -v ./...",
9+
"watch:doc": "watchexec.exe --restart --clear --exts go --no-project-ignore go doc -all"
710
}
811
}

0 commit comments

Comments
 (0)