Append to a dconf list and avoiding duplicates with existing entries

I need to do this for a script i'm writing to add custom keyboard shortcuts. I get the existing list with

gsettings get custom-keybindings
['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/']

and now i need to add new entries to it and avoid duplicates with any previous custom$ shortcuts.

gsettings set custom-keybindings "[<altered_list>]"

Adding values to an existing array

arr=( "${arr[@]}" "new_element1" "new_element2" "..." "new_elementN")
arr+=( "new_element1" "new_element2" "..." "new_elementN" )

using command substituion

CUSTOM_SHORTCUTS_LIST=$(gsettings get custom-keybindings)
# ['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/']

NEW_SHORTCUTS_LIST="${CUSTOM_SHORTCUTS_LIST%]*}, 'blah']" # substituion

# ['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/', 'blah']

Here are some way people have done this when creating Gnome Terminal themes

# One Dark
dlist_append() {
    local key="$1"; shift
    local val="$1"; shift

    local entries="$(
            "$DCONF" read "$key" | tr -d '[]' | tr , "\n" | fgrep -v "$val"
            echo "'$val'"
        } | head -c-1 | tr "\n" ,

    "$DCONF" write "$key" "[$entries]"
# Nord
append_profile_uuid_to_list() {
  local uuid list
  list=$(gsettings get "$GSETTINGS_PROFILELIST_PATH" list)
  gsettings set "$GSETTINGS_PROFILELIST_PATH" list "${list%]*}, '$uuid']"


Please note that this site and the posts on it are, and will always be, a work in progress. If i waited for perfection, i’d never get anything done.