diff options
| author | Alex Leferry 2 <alexherbo2@gmail.com> | 2020-02-20 01:08:22 +0100 |
|---|---|---|
| committer | Alex Leferry 2 <alexherbo2@gmail.com> | 2020-06-18 14:33:34 +0200 |
| commit | 0b6cdfee874877d05958f28ee30744c9bfc75c5d (patch) | |
| tree | 44d59a4c747319e818d0f40558f94ac0b18aef75 | |
| parent | 3ccce2f23ff0001b8528fce41a7ab18ab8347bdf (diff) | |
Add a -wait switch to the edit shell command
Fixes #8
| -rw-r--r-- | rc/env/git.env | 2 | ||||
| -rwxr-xr-x | rc/paths/commands/edit | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/rc/env/git.env b/rc/env/git.env index cb937da..83ff9c0 100644 --- a/rc/env/git.env +++ b/rc/env/git.env @@ -1 +1 @@ -export GIT_EDITOR=edit +export GIT_EDITOR='edit -wait' diff --git a/rc/paths/commands/edit b/rc/paths/commands/edit index 9ac29a0..ceb648d 100755 --- a/rc/paths/commands/edit +++ b/rc/paths/commands/edit @@ -1,6 +1,14 @@ #!/bin/sh +# Option parser +# For the simplicity of parsing, we only parse the first argument. +wait=false +case "$1" in + -wait) wait=true; shift ;; +esac + commands='' +regex='' while test $# -gt 0; do file=$(realpath "$1") # Optional coordinates @@ -21,6 +29,27 @@ while test $# -gt 0; do commands="edit %{$file}; $commands" ;; esac + regex="${regex}|\\Q${file}\\E" done +regex=${regex#|} send "$commands" + +if test "$wait" = true; then + state=$(mktemp -d) + trap 'rm -Rf "$state"' EXIT + mkfifo "$state/status" + send " + hook -group connect-detach global BufWritePost $regex %{ + remove-hooks global connect-detach + delete-buffer %val{hook_param} + echo -to-file $state/status 0 + } + hook -group connect-detach global BufClose $regex %{ + remove-hooks global connect-detach + echo -to-file $state/status 1 + } + " + read status < "$state/status" + exit "$status" +fi |
