forked from LCTT/lctt-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_start_translating.sh
executable file
·43 lines (40 loc) · 1.32 KB
/
2_start_translating.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
#!/bin/bash
set -e
source $(dirname "${BASH_SOURCE[0]}")/base.sh
# 搜索可以翻译的文件
declare -a files
sources_dir="$(get-lctt-path)"/sources
if [[ $# -eq 0 ]];then
i=0
while read -r file;do
if ! file-translating-p "${file}" ;then
printf " %3d. %s\n" $i "${file}"
files[$i]="${file}"
i=$((i+1))
elif file-translating-by-me-p "${file}";then
printf "*%3d. %s\n" $i "${file}"
files[$i]="${file}"
i=$((i+1))
fi
done< <(find "${sources_dir}" -name "2*.md"|sort)
read -r -p "input the article number you want to translate: " num
file="${source_dir}"/"${files[$num]}" # 使用绝对路径,否则后面无法cd进入文件所在目录
else
file="$*"
fi
cd "$(dirname "${file}")"
filename=$(basename "${file}")
# new_branch="translate-$(title-to-branch "${filename}")"
new_branch="$(filename-to-branch translate "${filename}")"
git branch "${new_branch}" master
git checkout "${new_branch}"
# 如果没有翻译,则加上翻译标志
if ! file-translating-p "${filename}";then
mark-file-as-tranlating "${filename}"
git add "${filename}"
git_user=$(get-github-user)
git commit -m "translating by ${git_user}"
git push -u origin "${new_branch}"
fi
# 打开要翻译的文章
eval "$(get-editor) '${filename}'"