Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Support sensible-editor
Browse files Browse the repository at this point in the history
Many versions of Linux (most Debian-based versions) support a mechanimsm
based on a link called "sensible-editor", which is configured to invoke
the user's preferred editing tool.

To get colorization help, the temp file is now named with a ".json"
extension.  Most editors can colorize appropriately based on that.
  • Loading branch information
penrods committed Sep 9, 2019
1 parent a6f9cdc commit 909a4dc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions bin/mycroft-config
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function help() {

VIEWER="nano --syntax=json --view"
if [ -z "$EDITOR" ] ; then
EDITOR="nano --syntax=json --tempfile"
if [ $( which sensible-editor ) ] ; then
EDITOR="sensible-editor"
else
EDITOR="nano --syntax=json --tempfile"
fi
fi

if [ -z "$TEMP" ] ; then
Expand Down Expand Up @@ -118,33 +122,33 @@ function edit_config() {
fi

if [ -f "${_conf_file}" ] ; then
cp "${_conf_file}" "${TEMP}/mycroft.conf"
cp "${_conf_file}" "${TEMP}/mycroft.json"
else
echo "{" > "${TEMP}/mycroft.conf"
echo "}" >> "${TEMP}/mycroft.conf"
echo "{" > "${TEMP}/mycroft.json"
echo "}" >> "${TEMP}/mycroft.json"
fi

while [ 1 ] ; do
case $1 in
system | user)
# Allow user to edit
$EDITOR $TEMP/mycroft.conf
$EDITOR $TEMP/mycroft.json
;;
default | remote)
# View-only
$VIEWER $TEMP/mycroft.conf
$VIEWER $TEMP/mycroft.json
;;
esac

cmp --quiet "${_conf_file}" "${TEMP}/mycroft.conf"
cmp --quiet "${_conf_file}" "${TEMP}/mycroft.json"
rc=$?
if [ $rc -eq 0 ] ; then
echo "Configuration unchanged."
break
fi

# file was changed, validate changes
validate_config_file $TEMP/mycroft.conf
validate_config_file $TEMP/mycroft.json
if [ $? -ne 0 ] ; then
echo "${YELLOW}WARNING: ${RESET}Configuration file does not pass validation, see errors above."
echo "Press X to abandon changes, S to force save, any other key to edit again."
Expand All @@ -156,7 +160,7 @@ function edit_config() {
case $key in
[Ss])
echo "Saving..."
mv $TEMP/mycroft.conf $_conf_file
mv $TEMP/mycroft.json $_conf_file
signal_reload_config
break
;;
Expand Down

0 comments on commit 909a4dc

Please sign in to comment.