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