summaryrefslogtreecommitdiffstats
path: root/bin/weechat-config
diff options
context:
space:
mode:
Diffstat (limited to 'bin/weechat-config')
-rwxr-xr-xbin/weechat-config29
1 files changed, 29 insertions, 0 deletions
diff --git a/bin/weechat-config b/bin/weechat-config
new file mode 100755
index 0000000..b040207
--- /dev/null
+++ b/bin/weechat-config
@@ -0,0 +1,29 @@
+#!/bin/sh
+set -eu
+set -o pipefail
+
+weechat_fifo="${HOME}/.weechat/weechat_fifo"
+weechat_saved_config="${HOME}/.config/weechat/saved"
+weechat_extra_config="${HOME}/.config/weechat/extra"
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+weechat() {
+ [ -p "$weechat_fifo" ] || die "$weechat_fifo is not a fifo"
+ echo "*${1}" >> "$weechat_fifo"
+}
+
+case "$1" in
+save)
+ # shellcheck disable=SC2016
+ weechat '/fset c:${value_changed} && "${file}.${section}" != "irc.server"'
+ weechat "/eval /fset -export ${weechat_saved_config}"
+ weechat '/buffer close fset'
+ ;;
+restore)
+ weechat "/exec -oc grep -h '^/' ${weechat_saved_config} ${weechat_extra_config}"
+ ;;
+esac