57 lines
1.4 KiB
Bash
Executable File
57 lines
1.4 KiB
Bash
Executable File
#!/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}
|
|
|
|
executable=1
|
|
autoext=1
|
|
args=(
|
|
"créer un nouveau fichier .sh"
|
|
"<files...>"
|
|
-x,--exec executable=1 "créer un script exécutable"
|
|
-n,--no-exec executable= "créer un fichier non exécutable"
|
|
-j,--no-autoext autoext= "ne pas rajouter l'extension .sh"
|
|
)
|
|
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" .sh
|
|
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.sh"
|
|
fi
|
|
[ -e "$file" ] && die "$file: fichier existant"
|
|
estep "Création de $file"
|
|
|
|
if [ -n "$executable" ]; then
|
|
cat >"$file" <<EOF
|
|
#!/bin/bash
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
source /etc/nulib.sh || exit 1
|
|
|
|
args=(
|
|
"description"
|
|
#"usage"
|
|
)
|
|
parse_args "\$@"; set -- "\${args[@]}"
|
|
|
|
EOF
|
|
chmod +x "$file"
|
|
"$EDITOR" +6 "$file"
|
|
else
|
|
cat >"$file" <<EOF
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
EOF
|
|
"$EDITOR" +2 "$file"
|
|
fi
|
|
done
|