nulib/bin/templ.yml

39 lines
1009 B
YAML
Raw Normal View History

2024-02-06 23:57:22 +04:00
#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
2024-03-18 17:32:16 +04:00
source "$(dirname -- "$0")/../load.sh" || exit 1
require: fndate
2024-02-06 23:57:22 +04:00
: ${EDITOR:=vim}
2024-03-05 20:56:51 +04:00
autoext=1
2024-02-06 23:57:22 +04:00
args=(
"créer un nouveau fichier .yaml"
"<files...>"
2024-03-05 20:56:51 +04:00
-j,--no-autoext autoext= "ne pas rajouter l'extension .yaml ni .yml"
2024-02-06 23:57:22 +04:00
)
parse_args "$@"; set -- "${args[@]}"
[ $# -gt 0 ] || die "vous devez spécifier les noms des fichiers à créer"
for file in "$@"; do
2024-03-18 17:32:16 +04:00
setx file=fndate_verifix "$file" .yml
2024-03-05 20:56:51 +04:00
setx filename=basename -- "$file"
2024-02-06 23:57:22 +04:00
if [[ "$filename" == *.* ]]; then
2024-03-05 20:56:51 +04:00
: # y'a déjà une extension, ne rien faire
elif [ -z "$autoext" ]; then
: # ne pas rajouter d'extension
2024-02-06 23:57:22 +04:00
elif [ -f "$file.yaml" ]; then
file="$file.yaml"
else
file="$file.yml"
fi
[ -e "$file" ] && die "$file: fichier existant"
estep "Création de $file"
2024-03-05 20:56:51 +04:00
2024-02-06 23:57:22 +04:00
echo >"$file" "\
# -*- coding: utf-8 mode: yaml -*- vim:sw=2:sts=2:et:ai:si:sta:fenc=utf-8
"
"$EDITOR" +3 "$file"
done