41 lines
990 B
MySQL
41 lines
990 B
MySQL
|
#!/bin/bash
|
||
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||
|
source "$(dirname -- "$0")/../load.sh" || exit 1
|
||
|
require: fndate
|
||
|
|
||
|
: ${EDITOR:=vim}
|
||
|
|
||
|
autoext=1
|
||
|
args=(
|
||
|
"créer un nouveau fichier .sql"
|
||
|
"<files...>"
|
||
|
-j,--no-autoext autoext= "ne pas rajouter l'extension .sql"
|
||
|
)
|
||
|
parse_args "$@"; set -- "${args[@]}"
|
||
|
|
||
|
[ $# -gt 0 ] || die "vous devez spécifier les noms des fichiers à créer"
|
||
|
|
||
|
for file in "$@"; do
|
||
|
setx file=fndate_verifix "$file" .sql
|
||
|
setx filename=basename -- "$file"
|
||
|
if [[ "$filename" == *.* ]]; then
|
||
|
: # y'a déjà une extension, ne rien faire
|
||
|
elif [ -z "$autoext" ]; then
|
||
|
: # ne pas rajouter d'extension
|
||
|
else
|
||
|
file="$file.sql"
|
||
|
fi
|
||
|
[ -e "$file" ] && die "$file: fichier existant"
|
||
|
estep "Création de $file"
|
||
|
|
||
|
cat >"$file" <<EOF
|
||
|
-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=$encoding
|
||
|
-- @database xxx
|
||
|
|
||
|
start transaction;
|
||
|
|
||
|
commit;
|
||
|
EOF
|
||
|
"$EDITOR" +2 "$file"
|
||
|
done
|