Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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 cmus {
- artist=$(printf $(cmus-remote -C status | grep "tag artist" | cut -c 12-))
- if [[ $artist = *[!\ ]* ]]; then
- song=$(printf $(cmus-remote -C status | grep title | cut -c 11-))
- printf "$artist ﱘ $song"
- else
- json_array=$(remove_holder holder__i3_layout)
- fi
- }
- function split {
- local layout=$(i3-msg -t get_tree | jq --raw-output 'recurse(.nodes[]; .nodes !=null) | select(.nodes[].focused).layout')
- if [ "$layout" == splith ] ; then
- local json='{ "full_text": "[horizontal]", "color": "#92BFEB" }'
- json_array=$(update_holder holder__split "$json")
- elif [ "$layout" == splitv ] ; then
- local json='{ "full_text": "[vertical]", "color": "#92BFEB" }'
- json_array=$(update_holder holder__split "$json")
- elif [ "$layout" == tabbed ] ; then
- local json='{ "full_text": "[tabbed]", "color": "#92BFEB" }'
- json_array=$(update_holder holder__split "$json")
- elif [ "$layout" == stacked ] ; then
- local json='{ "full_text": "[stacked]", "color": "#92BFEB" }'
- json_array=$(update_holder holder__split "$json")
- else
- json_array=$(remove_holder holder__split)
- 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/^,//')"
- split
- cmus
- echo ",$json_array"
- done)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement