Advertisement
JoseDaSilvaSauro

Untitled

Nov 19th, 2023
30
0
187 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.41 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # This i3status wrapper allows to add custom information in any position of the statusline
  4. # It was developed for i3bar (JSON format)
  5.  
  6. # The idea is to define "holder" modules in i3status config and then replace them
  7.  
  8. # In order to make this example work you need to add
  9. # order += "tztime holder__hey_man"
  10. # and
  11. # tztime holder__hey_man {
  12. #        format = "holder__hey_man"
  13. # }
  14. # in i3staus config
  15.  
  16. # Don't forget that i3status config should contain:
  17. # general {
  18. #   output_format = i3bar
  19. # }
  20. #
  21. # and i3 config should contain:
  22. # bar {
  23. #   status_command exec /path/to/this/script.sh
  24. # }
  25.  
  26. # Make sure jq is installed
  27. # That's it
  28.  
  29. # You can easily add multiple custom modules using additional "holders"
  30.  
  31. function update_holder {
  32.  
  33.   local instance="$1"
  34.   local replacement="$2"
  35.   echo "$json_array" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j"
  36. }
  37.  
  38. function remove_holder {
  39.  
  40.   local instance="$1"
  41.   echo "$json_array" | jq "del(.[] | (select(.instance==\"$instance\")))"
  42. }
  43.  
  44. function cmus {
  45.  
  46. artist=$(printf $(cmus-remote -C status | grep "tag artist" | cut -c 12-))
  47.  
  48.   if [[ $artist = *[!\ ]* ]]; then
  49.           song=$(printf $(cmus-remote -C status | grep title | cut -c 11-))
  50.           printf "$artist ﱘ  $song"
  51.   else
  52.       json_array=$(remove_holder holder__i3_layout)
  53.   fi
  54. }
  55.  
  56. function split {
  57.  
  58.   local layout=$(i3-msg -t get_tree | jq --raw-output 'recurse(.nodes[]; .nodes !=null) | select(.nodes[].focused).layout')
  59.   if [ "$layout" == splith ] ; then
  60.     local json='{ "full_text": "[horizontal]", "color": "#92BFEB" }'
  61.     json_array=$(update_holder holder__split "$json")
  62.   elif [ "$layout" == splitv ] ; then
  63.     local json='{ "full_text": "[vertical]", "color": "#92BFEB" }'
  64.     json_array=$(update_holder holder__split "$json")
  65.   elif [ "$layout" == tabbed ] ; then
  66.     local json='{ "full_text": "[tabbed]", "color": "#92BFEB" }'
  67.     json_array=$(update_holder holder__split "$json")
  68.   elif [ "$layout" == stacked ] ; then
  69.     local json='{ "full_text": "[stacked]", "color": "#92BFEB" }'
  70.     json_array=$(update_holder holder__split "$json")
  71.   else
  72.     json_array=$(remove_holder holder__split)
  73.   fi
  74. }
  75. i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true
  76. do
  77.   read line
  78.   json_array="$(echo $line | sed -e 's/^,//')"
  79.   split
  80.   cmus
  81.   echo ",$json_array"
  82. done)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement