-
Notifications
You must be signed in to change notification settings - Fork 0
/
myhelp.sh
executable file
·91 lines (81 loc) · 2.36 KB
/
myhelp.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
#!/bin/bash
# echo "\n\n\n\n\n\n"
version="1.0"
cfg_path=$HOME"/myhelp_cfg.txt"
if [ -f "$cfg_path" ];then
. ${cfg_path} # source 包含
else
cat <<End-of-message
首次使用, 请编辑配置文件: ${cfg_path}
End-of-message
cat > ${cfg_path} <<End-of-message
zsh_path=$HOME/.zshrc
bash_path=$HOME/.bashrc
note_path=$HOME/myhelp_note.txt
local_path=$HOME/myhelp_local.txt
sync_url="" # 远端同步URL, 类似 http://xxx.com/myhelp.txt
End-of-message
exit;
fi
cat <<End-of-message
-------------------------------------------------------------------------
服务器命令行管理助手 ${version}
https://github.com/cary929/myhelp
-------------------------------------------------------------------------
命令: #myhelp [参数]
参数:
cmd 显示个人添加的自定义命令
note 显示笔记, 可从远端获取
local 显示本地笔记, 只在本机使用, 不同步
sync 获取远端帮助文件内容, 并覆盖本地的文件
-------------------------------------------------------------------------
End-of-message
for var in $*
do
case "$var" in
"note")
if [ -f "${note_path}" ];then
cat $note_path
else
cat > ${note_path} <<End-of-message
#=====myhelp=====
End-of-message
cat <<End-of-message
已创建帮助文件模板, 您可以编辑使用 , 也可以使用下面命令来获取远端的帮助文件:
#myhelp sync
End-of-message
fi
exit;;
"local")
if [ -f "${local_path}" ];then
cat $local_path
else
cat > ${local_path} <<End-of-message
#=====mylocal=====
End-of-message
cat <<End-of-message
已经为您添加本地帮助文件: ${local_path}
End-of-message
fi
exit;;
"cmd")
if [ -f "$zsh_path" ];then
grep -A 200 =====myhelp_cmd===== ${zsh_path}
else
grep -A 50 =====myhelp_cmd===== ${bash_path}
fi
exit;;
"sync" )
if [ -z "$sync_url" ];then
echo '同步URL未配置.'
else
wget -P ~ -O "${note_path}" -q ${sync_url}
echo '同步成功'
fi
exit;;
"version" ) echo "Version: ${version}"
exit ;;
"exit" ) exit;;
* ) echo "不支持的命令"
esac
done