-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·72 lines (60 loc) · 1.42 KB
/
install.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
#!/bin/bash
GIT_CONFIG="$HOME/.gitconfig"
GIT_TRANSLATION_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
GIT_TRANSLATION_CONFIG_FILE="$GIT_TRANSLATION_DIR/aliases"
function get_config_string () {
language=$1
cat <<EOF
# the following include was inserted by git-translation project
[include]
path = $GIT_TRANSLATION_CONFIG_FILE/$language
EOF
}
function install() {
language=${1:-"hu"}
config=$(get_config_string $language)
if grep -Fq "$config" "$GIT_CONFIG"
then
echo "Some translation is already installed, exiting..."
exit;
fi
echo Installing aliases
echo "$config" >> $GIT_CONFIG
}
remove() {
language=${1:-"hu"}
file=$GIT_CONFIG
from=$(grep -n '# the following' "$file" | cut -d ':' -f 1)
to=$(( from + 2 ))
THE_DIFF=$(cat << EOF
${from},${to}d1
< # the following include was inserted by git-translation project
< [include]
< path = $GIT_TRANSLATION_CONFIG_FILE/$language
EOF
)
echo "$THE_DIFF" | patch -p0 "$file"
}
function help() {
cat <<EOF
The follwing commands are available:
intall - install the alias config in your gitconfig
remove - opposite of install
For both commands you can provide a language option but at the moment it will
only work with "hu" for hungarian language.
EOF
}
function main() {
case "$1" in
"install")
install $2
;;
"remove")
remove $2
;;
"help" | "" | *)
help
;;
esac
}
main $@