-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiamond
executable file
·90 lines (77 loc) · 2.63 KB
/
diamond
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
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_MODE=a
CMD="${1}"
NAME="${2}"
ARTICLE_DIR="${HOME}/dev/src/github.com/humboldtux-articles/${NAME}"
GLMF_REPO="${HOME}/dev/src/github.com/GLMF/outils_auteurs"
function diamond_install() {
#On install pandoc via nix-env, pourpandoc > 2.10
sudo apt install pandoc
if [[ ! -d ${GLMF_REPO} ]]; then
git clone https://github.com/GLMF/outils_auteurs.git "$GLMF_REPO"
fi
}
diamond_new() {
[[ -z ${NAME} ]] && { echo 'Donnez un nom en paramètre'; exit 1;}
git clone [email protected]:humboldtux-articles/Template.git "$ARTICLE_DIR" || exit 1
cd "$ARTICLE_DIR" || exit 1
cp -n "$GLMF_REPO"/Markdown/md-auteur/pandoc-md-auteur/modeles/modele.md "$ARTICLE_DIR/$NAME".md
git add .
git commit -m'Ajout template article'
MODELE=`find "$GLMF_REPO"/Markdown/md-auteur/pandoc-md-auteur/modeles/ -type f -name "modele*template" -execdir basename {} .template ';' | fzf`
echo "export DIAMOND_MODELE=${MODELE}" > .envrc
direnv allow
git add .envrc
git commit -m"Ajout DIAMOND_MODELE env var"
printf "\n\n\nCréez le dépôt humboldtux-articles/${NAME} sur Github"
read
git remote set-url origin [email protected]:humboldtux-articles/"$NAME".git
git push
}
diamond_pandoc() {
[[ -z ${NAME} ]] && { echo 'Donnez un nom en paramètre'; exit 1;}
MODE=${1}
cd "$ARTICLE_DIR" || exit 1
eval "$(direnv export bash)"
rm -rf build cache ; mkdir -p build cache
unzip "$GLMF_REPO/Markdown/md-auteur/pandoc-md-auteur/modeles/$DIAMOND_MODELE".odt -d "$ARTICLE_DIR/build/$DIAMOND_MODELE".odt || exit 1
cd "$ARTICLE_DIR" || exit 1
pandoc --verbose "$NAME".md -M prefix="$NAME" -M images="$MODE" -M class="$DIAMOND_MODELE" \
--template="$GLMF_REPO/Markdown/md-auteur/pandoc-md-auteur/modeles/$DIAMOND_MODELE".template \
-t "$GLMF_REPO"/Markdown/md-auteur/pandoc-md-auteur/scripts/writer-article-gnulinuxmagazine.lua \
-o build/"$DIAMOND_MODELE".odt/content.xml
cd build/"$DIAMOND_MODELE".odt || exit 1
zip -r "${NAME}.odt" *
xdg-open "$ARTICLE_DIR/build/$DIAMOND_MODELE.odt/$NAME".odt
}
diamond_verify() {
diamond_pandoc ON
cd "$ARTICLE_DIR"/build || exit 1
mv *.png "$ARTICLE_DIR/build/$DIAMOND_MODELE".odt
}
diamond_create() {
diamond_pandoc OFF
}
usage() {
echo "usage: diamond [[--install| -i] | [[--new | --verify | --create] nom_article]]"
}
case ${CMD} in
-i | --install) diamond_install
exit
;;
-n | --new ) diamond_new
exit
;;
-v | --verify ) diamond_verify
exit
;;
-c | --create ) diamond_create
exit
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
;; esac