ted: better git commits & variable names

This commit is contained in:
PowerUser64 2025-05-30 15:04:16 -07:00
parent a6bc524f54
commit f4d79aaec7

View file

@ -14,13 +14,13 @@ ed() {
}
backup_git() {
cd "${1:-}"
cd "$1"
if command -v git > /dev/null; then
# Commit all existing files
git commit -am "ted-backup: update $dirname"
git commit -am "ted-backup($dirname): update files" || true
# Add new files and commit them
git add "$1"
git commit -m "ted-backup: add $dirname"
git commit -m "ted-backup($dirname): add files" || true
git push
fi
}
@ -64,20 +64,20 @@ case "${1:-}" in
esac
tests_dir="${XDG_DOCUMENTS_DIR:-"$HOME"/Documents}/code-tests"
tempdir="$tests_dir"
mkdir -p "$tempdir"
code_dir="$tests_dir"
ed_args=()
if [ "$1" != -- ]; then
filename="$1"; shift
dirname="${filename%%.*}"
date="$(date +%F)"
tempdir_arr=("$tests_dir/"*"$dirname")
tempdir="${tempdir_arr[0]:-"$tests_dir/$date-$dirname"}"
code_dir_arr=("$tests_dir/"*"$dirname")
code_dir="${code_dir_arr[0]:-"$tests_dir/$date-$dirname"}"
# build an argument list for the editor
ed_args=("$filename")
fi
mkdir -p "$code_dir"
cmds=("$SHELL")
for a;do
@ -90,7 +90,7 @@ for a;do
ed_args+=("$a")
done
cd "$tempdir"
cd "$code_dir"
if [ "${#ed_args[@]}" != 0 ]; then
# launch editor
@ -110,7 +110,7 @@ fi
# check if directory is empty. If it is, remove it.
filecount="$(find . -maxdepth 1 -print | wc -l)"
if [ "$filecount" = 0 ]; then
rmdir "$tempdir"
rmdir "$code_dir"
else
backup_git .
fi