]> git.madduck.net Git - etc/tridactyl.git/blob - .config/tridactyl/edit-and-backup

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

initial checkin
[etc/tridactyl.git] / .config / tridactyl / edit-and-backup
1 #!/bin/sh
2 #
3 # edit-and-backup
4 #
5 # Wrapper for Tridactyl's $editorcmd, which saves a backup before returning
6 # to Tridactyl.
7 #
8 # © 2021–5 martin f. krafft <madduck@madduck.net>
9 # Released under the Apache Licence 2.0.
10 #
11 set -eu
12
13 BACKUPDIR=${TMPDIR:-/tmp}/tridactyl-backups
14 mkdir --parent $BACKUPDIR
15
16 FILENAME="$1"
17 EDITOR="${2:-editor}"
18
19 URL="${FILENAME#*_}"
20 URL="${URL%%_*}"
21
22 if [ -t 0 ]; then
23   echo -n "\033]0;Tridactyl: editing input field on $URL using ${EDITOR%% *}\007"
24 fi
25
26 set -x
27 eval "$EDITOR" "$FILENAME"
28
29 notify() {
30   local summary
31   summary="$1"
32   shift
33   if command -v notify-send >/dev/null; then
34     notify-send "$summary" "$@"
35   else
36     echo >&2 "$summary" "$@"
37   fi
38 }
39
40 if [ -s "$FILENAME" ]; then
41
42   BACKUPFILE="$(mktemp --tmpdir="$BACKUPDIR" $URL-$(date +%F-%H%M.%N)-XXXXXXXX.txt)"
43   cat "$FILENAME" >"$BACKUPFILE"
44
45   notify "Tridactyl backup saved" "Saved a backup of your edits to $BACKUPFILE"
46
47 else
48
49   notify "Nothing to be saved"
50
51 fi
52
53 exit 0