ted: support no file argument

This commit is contained in:
PowerUser64 2025-04-09 01:48:50 -07:00
parent e32deeca76
commit 7898226366

View file

@ -5,6 +5,7 @@
# shellcheck disable=SC2016
set -eu
shopt -s nullglob # prevent ./foo.* from erroring if there are no results
pname="${0##*/}"
@ -20,6 +21,7 @@ backup_git() {
# Add new files and commit them
git add "$1"
git commit -m "ted-backup: add $dirname"
git push
fi
}
@ -61,17 +63,22 @@ case "${1:-}" in
-h|--help) usage; exit;;
esac
filename="$1"; shift
dirname="${filename%%.*}"
tests_dir="${XDG_DOCUMENTS_DIR:-"$HOME"/Documents}/code-tests"
date="$(date +%F)"
tempdir_arr=("$tests_dir/"*"$dirname")
tempdir="${tempdir_arr[0]:-"$tests_dir/$date-$dirname"}"
tempdir="$tests_dir"
mkdir -p "$tempdir"
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"}"
# build an argument list for the editor
ed_args=("$filename")
fi
# build an argument list for the editor
ed_args=("$filename")
cmds=("$SHELL")
for a;do
shift
@ -85,8 +92,10 @@ done
cd "$tempdir"
# launch editor
ed "${ed_args[@]}"
if [ "${#ed_args[@]}" != 0 ]; then
# launch editor
ed "${ed_args[@]}"
fi
# launch the command
if [ "${#cmds}" != 0 ]; then