summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2020-04-27 18:18:34 -0700
committerKevin McCarthy <kevin@8t8.us>2020-04-27 18:18:34 -0700
commit43204e7bec742ecf242b9f4d52ed790a60af98fa (patch)
tree3d5f58707ea90e3e189beb35e8a717c526bbbc46 /contrib
parentd5d8b62a390fb18e84c5e51a1c2151f905ea0ec3 (diff)
Add contrib/bgedit-screen-tmux.sh.
This script wraps running the editor inside a new GNU Screen or tmux session. The script is derived from Aaron Schrab's script posted to mutt-dev, but rewritten to run in a posix shell, automatically adjust between tmux and screen, and with a bit more error checking.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/Makefile.am2
-rw-r--r--contrib/bgedit-screen-tmux.sh66
2 files changed, 67 insertions, 1 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 3cda1544..4922b8ae 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -7,7 +7,7 @@ SAMPLES = Mush.rc Pine.rc gpg.rc pgp2.rc pgp5.rc pgp6.rc Tin.rc \
sample.muttrc-compress sample.muttrc-starter \
sample.vimrc-sidebar colors.default colors.linux smime.rc \
ca-bundle.crt smime_keys_test.pl mutt_xtitle markdown2html \
- bgedit-detectgui.sh
+ bgedit-detectgui.sh bgedit-screen-tmux.sh
EXTRA_DIST = language.txt language50.txt \
patch.slang-1.2.2.keypad.1 \
diff --git a/contrib/bgedit-screen-tmux.sh b/contrib/bgedit-screen-tmux.sh
new file mode 100644
index 00000000..5124d957
--- /dev/null
+++ b/contrib/bgedit-screen-tmux.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+#
+# Copyright (C) 2020 Kevin J. McCarthy <kevin@8t8.us>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Invoke a background edit session in a new GNU Screen or tmux window.
+#
+# This script is derived from Aaron Schrab's tmuxwait script, posted to
+# mutt-dev at
+# <http://lists.mutt.org/pipermail/mutt-dev/Week-of-Mon-20200406/000591.html>.
+#
+# If you run mutt inside screen or tmux, add to your muttrc:
+# set background_edit
+# set editor = '/path/to/bgedit-screen-tmux.sh [youreditor]'
+#
+# It may also be useful to modify something like contrib/bgedit-detectgui.sh
+# to look for the $STY or $TMUX environment variables and set those
+# configuration variables appropriately.
+#
+
+set -e
+
+if [ "$#" -lt 2 ]; then
+ echo "Usage: $0 editor tempfile" >&2
+ exit 1
+fi
+
+editor=$1
+shift
+
+tmpdir=$(mktemp -d)
+trap 'rm -rf "$tmpdir"' EXIT INT QUIT
+mkfifo "$tmpdir/status"
+
+cat >"$tmpdir/run" <<END_SCRIPT
+exitval=1
+trap 'echo \$exitval > "$tmpdir/status"' EXIT INT QUIT
+$editor "\$@"
+exitval=\$?
+END_SCRIPT
+
+if test x$STY != x; then
+ screen -X screen /bin/sh "$tmpdir/run" "$@"
+elif test x$TMUX != x; then
+ tmux neww /bin/sh "$tmpdir/run" "$@"
+else
+ echo "Not running inside a terminal emulator" >&2
+ exit 1
+fi
+
+read exitval <"$tmpdir/status"
+exit "$exitval"
+