How do I change the color scheme from the command line

Success!

Turns out sed didn’t work properly either, it picked up the first change, then it stopped working. Apparently sed also does some weird stuff with creating a new file and copying it over the original file, breaking the inode watch. Relatively simple to work around though, I just needed to work on a copy of the config, then writing it over the original file. I now have a working darkman light/dark mode script for Inkdrop! :tada:

#!/bin/bash

[[ $0 == *dark-mode.d* ]] && MODE="dark" || MODE="light"

DARK_UI="vibrant-dark-ui"
DARK_SYNTAX="energy-syntax"
LIGHT_UI="default-light-ui"
LIGHT_SYNTAX="twilight-light-syntax"

CONFIG_PATH="$HOME/.config/inkdrop/config.cson"

if [[ ! -f "$CONFIG_PATH" ]]; then
    echo "Inkdrop config file not found, skipping ($CONFIG_PATH)"
    exit 0
fi

# Any config changes are made in a temporary copy of the config file, since
# modifying it inline (sed -i) would break the inode watch Inkdrop has on the
# file.

BUF="$(mktemp)"
trap "rm $BUF" EXIT

cat "$CONFIG_PATH" > "$BUF"

if [[ "$MODE" = "light" ]]; then
    CHOSEN_UI=$LIGHT_UI
    CHOSEN_SYNTAX=$LIGHT_SYNTAX
else
    CHOSEN_UI=$DARK_UI
    CHOSEN_SYNTAX=$DARK_SYNTAX
fi

sed -i -r "s/\"[^\"]+-ui\"/\"$CHOSEN_UI\"/" "$BUF"
sed -i -r "s/\"[^\"]+-syntax\"/\"$CHOSEN_SYNTAX\"/" "$BUF"

cat "$BUF" > "$CONFIG_PATH"

Video demo: Demo of Inkdrop dark/light mode toggle with Darkman

1 Like