File: bgedit-screen-tmux.sh

package info (click to toggle)
mutt 2.0.5-4.1%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 26,212 kB
  • sloc: ansic: 97,386; sh: 4,703; perl: 2,018; makefile: 726; python: 547; yacc: 318
file content (66 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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"