-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamiya.sh
68 lines (57 loc) · 1.71 KB
/
amiya.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
function amiya() {
if [ $# = 0 ]; then
echo "please let me know what you want: "
echo "* <create_experiments>"
echo "* <add_experiment>"
elif [ $1 = "create_experiments" ]; then
if [ $# = 1 ]; then
echo 'expected 2 para, but just 1 found'
else
echo "create an experiments $green<$2>$none_c for $yellow$NOW$none_c? [Y/n] "
read -r input
if [ $input = "Y" ]; then
echo "CONFIRMED, creating now"
mkdir ~/Experiments/$2
touch ~/Experiments/$2/index
echo "$NOW: <$2>" >> ~/Experiments/$2/index
echo "$now='$2'" >> ~/Documents/projects/peanuts/amiya/experiments_list.sh
echo "\n"$(date "+%B(%Y)") "[$2]" >> ~/Experiments/README
echo "$green ---> FINISHED"
elif [ $input = "n" ]; then
echo 'CANCELED'
else
echo 'Invalid input'
fi
fi
elif [ $1 = "add_experiment" ]; then
if [ $# = 1 ]; then
echo "expected 2 para, but just 1 found"
else
echo "add an experiment $green<$2>$none_c to $yellow${(P)now}($now)$none_c? [Y/n] "
read -r input
if [ $input = "Y" ]; then
echo 'CONFIRMED, creating now'
mkdir ~/Experiments/${(P)now}/$2
echo "\n<$2>" $(date "+%Y-%m-%d %H:%M:%S") >> ~/Experiments/${(P)now}/index
touch ~/Experiments/${(P)now}/$2/log
elif [ $input = "n" ]; then
echo 'CANCELED'
else
echo 'Invalid input'
fi
fi
else
echo "no command found !!!"
fi
}
. ~/Documents/projects/peanuts/amiya/knowledge.sh
_amiya(){
local cur cword words # 定义变量,cur表示当前光标下的单词
read -cn cword # 所有指令集
read -Ac words # 当前指令的索引值
cur="$words[$cword-1]" # 当前指令值
if [ $cur = "amiya" ];then
reply=(create_experiments add_experiment)
fi
}
compctl -K _amiya amiya # -K 表示使用函数