lackadaisical/editx

27 lines
526 B
Text
Executable file

# !/bin/bash
# This utility pre-allocs a file and adds execution permissions. It also
# removes the resulting file if it is empty after the editor closes.
if [[ -z $1 ]];
then
echo "No filename specified."
exit 2
fi
if [[ -z "${EDITOR}" ]];
then
ched "EDITOR env variable not set! You will have to set it yourself in the next screen."
fi
exists=$(file "$1" >/dev/null && echo $?)
touch "$1"
chmod +x "$1"
$EDITOR "$1"
wait $!
SIZE=$(du "$1" | cut -f 1)
if [[ $SIZE -eq 0 && $exists -ne 0 ]];
then
rm -rf "$1"
fi