ajout des options pour wiki
This commit is contained in:
parent
f4c7269b18
commit
9d68a96138
|
@ -11,8 +11,8 @@ EXTS=(
|
|||
conf:conf
|
||||
sql:sql
|
||||
sieve:sieve
|
||||
mdt:markdown mdwn:markdown md:markdown text:markdown
|
||||
twp:twpage
|
||||
mdt:markdown md:markdown text:markdown
|
||||
twp:tiddlywiki
|
||||
puml:puml
|
||||
iuml:iuml
|
||||
sh:shell
|
||||
|
@ -29,7 +29,8 @@ EXTS=(
|
|||
# Aliases de templates
|
||||
TEMPLATES=(
|
||||
t:text c:conf
|
||||
md:markdown twp:twpage
|
||||
md:markdown mdt:markdown mdpage:markdown
|
||||
tw:tiddlywiki twp:tiddlywiki twpage:tiddlywiki
|
||||
plantuml:puml
|
||||
sh:shell
|
||||
python:pyfile pyf:pyfile py:pyfile
|
||||
|
@ -47,7 +48,7 @@ TEMPLATES=(
|
|||
# Scripts à utiliser pour générer les templates
|
||||
TEMPLS=(
|
||||
text:text conf:text sql:text sieve:text
|
||||
markdown:wiki twpage:wiki
|
||||
markdown:wiki tiddlywiki:wiki
|
||||
puml:plantuml iuml:plantuml
|
||||
shell:shell
|
||||
pyfile:python pymodule:python
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: générer un fichier $NAME
|
||||
|
||||
USAGE
|
||||
$scriptname [options] <file>
|
||||
|
||||
OPTIONS
|
||||
-t TEMPLATE
|
||||
Indiquer le modèle de fichier à utiliser pour la génération. Les valeurs
|
||||
valides sont:
|
||||
${TEMPLATES[*]}
|
||||
-e, --edit
|
||||
-g, --no-edit
|
||||
Editer (resp. ne pas éditer) le fichier après l'avoir généré.
|
||||
Par défaut, l'éditeur est lancé après la génération.
|
||||
-f, --overwrite
|
||||
Ecraser le fichier s'il existe déjà
|
||||
-E, --encoding ENCODING
|
||||
Spécifier l'encoding à utiliser pour la génération du fichier"
|
||||
}
|
||||
|
||||
NAME=wiki
|
||||
TEMPLATES=(markdown tiddlywiki)
|
||||
NAMES=()
|
||||
EXTS=(mdt md text twp)
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
if [ "$1" == "--matches-template" ]; then
|
||||
for template in "${TEMPLATES[@]}"; do
|
||||
[ "$template" == "$2" ] && exit 0
|
||||
done
|
||||
exit 1
|
||||
elif [ "$1" == "--matches-name" ]; then
|
||||
for name in "${NAMES[@]}"; do
|
||||
[ "$name" == "$2" ] && exit 0
|
||||
done
|
||||
exit 1
|
||||
elif [ "$1" == "--matches-ext" ]; then
|
||||
for ext in "${EXTS[@]}"; do
|
||||
[ "$ext" == "$2" ] && exit 0
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#source /etc/ulib || exit 1
|
||||
source "$(dirname "$0")/../ulib/ulib" || exit 1
|
||||
urequire DEFAULTS
|
||||
|
||||
function check_overwrite() {
|
||||
if [ -e "$1" -a -z "$overwrite" ]; then
|
||||
eerror "$1: refus d'écraser un fichier déjà existant (utiliser -f)"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function generate_markdown() {
|
||||
local file="$1"
|
||||
local mode=markdown
|
||||
|
||||
check_overwrite "$1" || return
|
||||
estep "$(ppath "$file")"
|
||||
echo -n >"$file" "
|
||||
|
||||
-*- coding: $encoding ${mode:+mode: $mode }-*- vim:sw=4:sts=4:et:ai:si:sta:fenc=$encoding:noeol:binary"
|
||||
[ -n "$2" ] && array_add "$2" "$file"
|
||||
return 0
|
||||
}
|
||||
|
||||
function generate_tiddlywiki() {
|
||||
local file="$1"
|
||||
local mode=text
|
||||
|
||||
check_overwrite "$1" || return
|
||||
estep "$(ppath "$file")"
|
||||
echo -n >"$file" "
|
||||
|
||||
-*- coding: $encoding ${mode:+mode: $mode }-*- vim:sw=4:sts=4:et:ai:si:sta:fenc=$encoding:noeol:binary"
|
||||
[ -n "$2" ] && array_add "$2" "$file"
|
||||
return 0
|
||||
}
|
||||
|
||||
template=
|
||||
edit=1
|
||||
overwrite=
|
||||
encoding=
|
||||
#executable=
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with display_help' \
|
||||
-t:,--template: template= \
|
||||
-e,--edit edit=1 \
|
||||
-g,--no-edit edit= \
|
||||
-f,--overwrite overwrite=1 \
|
||||
-E:,--encoding: encoding= \
|
||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||
# à rajouter ci-dessus si les fichiers peuvent être exécutables:
|
||||
#-x,--executable executable=1 \
|
||||
#-n,--no-executable executable= \
|
||||
|
||||
[ -n "$encoding" ] || encoding=utf-8
|
||||
|
||||
files2edit=()
|
||||
r=0
|
||||
for file in "$@"; do
|
||||
t="$template"
|
||||
if [ -z "$t" ]; then
|
||||
dir="$(dirname "$file")"
|
||||
name="$(basename "$file")"
|
||||
# Si template n'est pas spécifié, le déterminer le cas échéant à partir
|
||||
# du nom de fichier. Rajouter ici le code approprié.
|
||||
fi
|
||||
|
||||
case "$t" in
|
||||
markdown|mdpage|mdt|md|text) generate_markdown "$file" files2edit || r=$?;;
|
||||
tiddlywiki|twpage|twp) generate_tiddlywiki "$file" files2edit || r=$?;;
|
||||
*) die "$NAME: template invalide: $t";;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$edit" -a "${#files2edit[*]}" -gt 0 ]; then
|
||||
"${EDITOR:-vi}" "${files2edit[@]}"
|
||||
fi
|
||||
|
||||
exit $r
|
Loading…
Reference in New Issue