Compare commits
2 commits
0c36e5d4fa
...
58b3d6122e
Author | SHA1 | Date | |
---|---|---|---|
58b3d6122e | |||
0c153b400b |
2 changed files with 94 additions and 4 deletions
88
.config/shell/bin/ted
Executable file
88
.config/shell/bin/ted
Executable file
|
@ -0,0 +1,88 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# "test edit" - makes a temporary file and edits it
|
||||||
|
# requires: bash (uses arrays)
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
pname="${0##*/}"
|
||||||
|
|
||||||
|
ed() {
|
||||||
|
${EDITOR:-nvim} "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo '"Test edit" - edit a temporary file for testing code fragments'
|
||||||
|
echo ""
|
||||||
|
echo "Usage: $pname [OPTIONS] [file] [ed-opts] [--] [cmd]..."
|
||||||
|
echo ""
|
||||||
|
echo "Arguments:"
|
||||||
|
echo " file A file to edit. Also acts as the name for the directory."
|
||||||
|
echo " ed-opts Any option to pass to the editor. (eg. another file name)"
|
||||||
|
echo " cmd... A list of commands to EVALuate after the editor exits. (example: bash)"
|
||||||
|
echo ' Exposed variables:'
|
||||||
|
echo ' $filename - the name of the file specified for `file`'
|
||||||
|
echo ' $tempdir - the directory the editor was launched in.'
|
||||||
|
echo ' $ed_args - array of arguments passed to the editor.'
|
||||||
|
echo ' $cmd_args - the array of commands specified in the `cmd...` option'
|
||||||
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo " -h, --help Print usage information and exit. This only gets read in the first argument position."
|
||||||
|
echo ""
|
||||||
|
echo "Environment:"
|
||||||
|
echo " EDITOR The editor you want to use."
|
||||||
|
echo ""
|
||||||
|
echo "Examples:"
|
||||||
|
echo " Edit hello.sh and then run bash (so you can run it)"
|
||||||
|
echo " $pname hello.sh -- bash"
|
||||||
|
echo " Edit hello.sh and then run it"
|
||||||
|
echo " $pname hello.sh -- ./hello.sh"
|
||||||
|
echo " Edit hello.sh and then run it (using a variable)"
|
||||||
|
echo " $pname hello.sh -- ./\$filename"
|
||||||
|
echo " Edit hello-world.c and hello-lib.c, then compile with gcc and run bash"
|
||||||
|
echo " $pname hello-world.c hello-lib.c -- 'gcc -o hello \"\${ed_args[@]}\"' './hello' bash"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $# = 0 ]]; then usage; exit 1; fi
|
||||||
|
|
||||||
|
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="$tests_dir/$date-$dirname"
|
||||||
|
mkdir -p "$tempdir"
|
||||||
|
|
||||||
|
# build an argument list for the editor
|
||||||
|
ed_args=("$filename")
|
||||||
|
cmds=("$SHELL")
|
||||||
|
for a;do
|
||||||
|
shift
|
||||||
|
# stop reading after --
|
||||||
|
if [ "$a" = -- ]; then
|
||||||
|
cmds=("$@")
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
ed_args+=("$a")
|
||||||
|
done
|
||||||
|
|
||||||
|
cd "$tempdir"
|
||||||
|
|
||||||
|
# launch editor
|
||||||
|
ed "${ed_args[@]}"
|
||||||
|
|
||||||
|
# launch the command
|
||||||
|
if [ "${#cmds}" != 0 ]; then
|
||||||
|
for cmd in "${cmds[@]}"; do
|
||||||
|
(eval "$cmd")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check if directory is empty. If it is, remove it.
|
||||||
|
filecount="$(find . -maxdepth 1 -print | wc -l)"
|
||||||
|
if [ "$filecount" = 0 ]; then
|
||||||
|
rmdir "$tempdir"
|
||||||
|
fi
|
10
.gitconfig
10
.gitconfig
|
@ -4,6 +4,9 @@
|
||||||
[credential]
|
[credential]
|
||||||
helper = store
|
helper = store
|
||||||
|
|
||||||
|
[core]
|
||||||
|
eol = lf
|
||||||
|
|
||||||
[pull]
|
[pull]
|
||||||
rebase = false
|
rebase = false
|
||||||
|
|
||||||
|
@ -14,6 +17,7 @@
|
||||||
[safe]
|
[safe]
|
||||||
directory = /storage/emulated/0/docs
|
directory = /storage/emulated/0/docs
|
||||||
directory = /mnt/windows/Users/blake/AppData/Local/nvim
|
directory = /mnt/windows/Users/blake/AppData/Local/nvim
|
||||||
|
directory = /mnt/windows/Users/blake/git/gam150/unknown-dust_demon
|
||||||
|
|
||||||
[color]
|
[color]
|
||||||
ui = auto
|
ui = auto
|
||||||
|
@ -35,7 +39,8 @@
|
||||||
pl = pull
|
pl = pull
|
||||||
ps = push
|
ps = push
|
||||||
psf = push -f
|
psf = push -f
|
||||||
psset = "! git push --set-upstream origin \"$(git branch --show-current)\""
|
psnew = "! git push --set-upstream origin \"$(git branch --show-current)\""
|
||||||
|
reb = rebase
|
||||||
rem = remote
|
rem = remote
|
||||||
rest = restore
|
rest = restore
|
||||||
s = status
|
s = status
|
||||||
|
@ -59,7 +64,4 @@
|
||||||
required = true
|
required = true
|
||||||
clean = git-lfs clean -- %f
|
clean = git-lfs clean -- %f
|
||||||
|
|
||||||
[core]
|
|
||||||
eol = lf
|
|
||||||
|
|
||||||
# vim:noet
|
# vim:noet
|
||||||
|
|
Loading…
Add table
Reference in a new issue