summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorIngo Bürk <admin@airblader.de>2020-03-30 08:37:42 +0200
committerGitHub <noreply@github.com>2020-03-30 08:37:42 +0200
commit101215bbc83b97de30b6b535bbe2e93d2e913804 (patch)
tree8fa388baf73b007f55a26ffe026b335de71ff04b /contrib
parentfb8dc7cce74ca42fb900a76224417927a1175893 (diff)
parent3a4f47295d0102429c985a5f64856498cae8b037 (diff)
Merge pull request #387 from ilya-bystrov/master
Small wrapper with the ability to add custom info in any position
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/any_position_wrapper.sh64
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/any_position_wrapper.sh b/contrib/any_position_wrapper.sh
new file mode 100755
index 0000000..8d877d4
--- /dev/null
+++ b/contrib/any_position_wrapper.sh
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+# This i3status wrapper allows to add custom information in any position of the statusline
+# It was developed for i3bar (JSON format)
+
+# The idea is to define "holder" modules in i3status config and then replace them
+
+# In order to make this example work you need to add
+# order += "tztime holder__hey_man"
+# and
+# tztime holder__hey_man {
+# format = "holder__hey_man"
+# }
+# in i3staus config
+
+# Don't forget that i3status config should contain:
+# general {
+# output_format = i3bar
+# }
+#
+# and i3 config should contain:
+# bar {
+# status_command exec /path/to/this/script.sh
+# }
+
+# Make sure jq is installed
+# That's it
+
+# You can easily add multiple custom modules using additional "holders"
+
+function update_holder {
+
+ local instance="$1"
+ local replacement="$2"
+ echo "$json_array" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j"
+}
+
+function remove_holder {
+
+ local instance="$1"
+ echo "$json_array" | jq "del(.[] | (select(.instance==\"$instance\")))"
+}
+
+function hey_man {
+
+ local rand_val=$((RANDOM % 3))
+ if [ $rand_val == 1 ] ; then
+ local json='{ "full_text": "Hey Man!", "color": "#00FF00" }'
+ json_array=$(update_holder holder__hey_man "$json")
+ elif [ $rand_val == 0 ] ; then
+ local json='{ "full_text": "Hey Man!", "color": "#FF0000" }'
+ json_array=$(update_holder holder__hey_man "$json")
+ else
+ json_array=$(remove_holder holder__hey_man)
+ fi
+}
+
+i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true
+do
+ read line
+ json_array="$(echo $line | sed -e 's/^,//')"
+ hey_man
+ echo ",$json_array"
+done)