summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2022-10-22 15:49:57 +0200
committerLevente Polyak <anthraxx@archlinux.org>2023-05-19 22:27:12 +0200
commitf63d343e40f7f07c7a900cbb7445bbefa0997259 (patch)
tree377ac21460f150406c991fa393e77bc74c37bb29 /src/lib
parentb5d5402e439f5edfd642fb4f680d596f5992e874 (diff)
downloaddevtools-f63d343e40f7f07c7a900cbb7445bbefa0997259.tar.xz
config: implemented simple config module to store token and settings
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/config.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/config.sh b/src/lib/config.sh
new file mode 100644
index 0000000..5034c6e
--- /dev/null
+++ b/src/lib/config.sh
@@ -0,0 +1,27 @@
+#!/hint/bash
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+[[ -z ${DEVTOOLS_INCLUDE_CONFIG_SH:-} ]] || return 0
+DEVTOOLS_INCLUDE_CONFIG_SH=1
+
+set -e
+
+readonly XDG_DEVTOOLS_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/devtools"
+readonly XDG_DEVTOOLS_GITLAB_CONFIG="${XDG_DEVTOOLS_DIR}/gitlab.conf"
+
+# default config variables
+export GITLAB_TOKEN=""
+
+load_devtools_config() {
+ if [[ ! -f "${XDG_DEVTOOLS_GITLAB_CONFIG}" ]]; then
+ GITLAB_TOKEN=""
+ return
+ fi
+ GITLAB_TOKEN=$(grep GITLAB_TOKEN "${XDG_DEVTOOLS_GITLAB_CONFIG}"|cut -d= -f2|cut -d\" -f2)
+}
+
+save_devtools_config() {
+ mkdir -p "${XDG_DEVTOOLS_DIR}"
+ printf 'GITLAB_TOKEN="%s"\n' "${GITLAB_TOKEN}" > "${XDG_DEVTOOLS_GITLAB_CONFIG}"
+}