ted: support no file argument
This commit is contained in:
parent
e32deeca76
commit
7898226366
1 changed files with 19 additions and 10 deletions
|
@ -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
|
||||||
|
|
||||||
filename="$1"; shift
|
|
||||||
dirname="${filename%%.*}"
|
|
||||||
tests_dir="${XDG_DOCUMENTS_DIR:-"$HOME"/Documents}/code-tests"
|
tests_dir="${XDG_DOCUMENTS_DIR:-"$HOME"/Documents}/code-tests"
|
||||||
date="$(date +%F)"
|
tempdir="$tests_dir"
|
||||||
|
|
||||||
tempdir_arr=("$tests_dir/"*"$dirname")
|
|
||||||
tempdir="${tempdir_arr[0]:-"$tests_dir/$date-$dirname"}"
|
|
||||||
mkdir -p "$tempdir"
|
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")
|
cmds=("$SHELL")
|
||||||
for a;do
|
for a;do
|
||||||
shift
|
shift
|
||||||
|
@ -85,8 +92,10 @@ done
|
||||||
|
|
||||||
cd "$tempdir"
|
cd "$tempdir"
|
||||||
|
|
||||||
# launch editor
|
if [ "${#ed_args[@]}" != 0 ]; then
|
||||||
ed "${ed_args[@]}"
|
# launch editor
|
||||||
|
ed "${ed_args[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
# launch the command
|
# launch the command
|
||||||
if [ "${#cmds}" != 0 ]; then
|
if [ "${#cmds}" != 0 ]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue