diff options
| author | Přemysl Eric Janouch <p@janouch.name> | 2026-01-27 15:35:03 +0100 |
|---|---|---|
| committer | Přemysl Eric Janouch <p@janouch.name> | 2026-01-27 15:35:55 +0100 |
| commit | 1dc39f900c1307407894f1ca207a1a2a869c43dc (patch) | |
| tree | 1672a7f5d60efb5d11619a960f06c79478e3bcfa /sdn-edit | |
| parent | dbea5cb193f9c2caa8fba9893ab32efbb415ebd6 (diff) | |
| download | sdn-1dc39f900c1307407894f1ca207a1a2a869c43dc.tar.gz sdn-1dc39f900c1307407894f1ca207a1a2a869c43dc.tar.xz sdn-1dc39f900c1307407894f1ca207a1a2a869c43dc.zip | |
Add and integrate sdn-edit
Diffstat (limited to 'sdn-edit')
| -rwxr-xr-x | sdn-edit | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/sdn-edit b/sdn-edit new file mode 100755 index 0000000..2245ba3 --- /dev/null +++ b/sdn-edit @@ -0,0 +1,48 @@ +#!/bin/sh -e +# sdn-edit: an editor for sdn that makes use of Midnight Commander configuration +# to make more kinds of files directly editable + +if [ "$#" -ne 1 ] +then + echo "Usage: $0 FILE" >&2 + exit 2 +fi + +# This handles both MC_DATADIR and odd installation locations. +datadir= +if command -v mc >/dev/null +then datadir=$(mc --datadir | sed 's/ (.*)$//') +fi + +config= +for dir in "$HOME"/.config/mc "$datadir" /etc/mc +do + if [ -n "$dir" -a -f "$dir/mc.ext.ini" ] + then + config=$dir/mc.ext.ini + break + fi +done + +# This is often used in %env{} expansion, so let's be on the same page. +export PAGER=${PAGER:-less} + +export MC_EXT_FILENAME=$(realpath "$1") +export MC_EXT_BASENAME=$(basename "$1") +export MC_EXT_CURRENTDIR=$(dirname "$MC_EXT_FILENAME") +output=$(sdn-mc-ext <"$config" "$(file -Lbz "$1")" \ + "$MC_EXT_FILENAME" "$MC_EXT_BASENAME" "$MC_EXT_CURRENTDIR" Edit || :) +kind=$(echo "$output" | sed -n 1p) +command=$(echo "$output" | sed -n 2p) + +case "$kind" in +'') + if [ -n "$command" ] + then eval "$command" + else "${VISUAL:-${EDITOR:-vi}}" -- "$MC_EXT_FILENAME" + fi + ;; +*) + echo "Unsupported: $kind" >&2 + exit 1 +esac |
