Advertisement
kbmonkey

Command Line Status Printer

Jun 1st, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.52 KB | None | 0 0
  1. #!/bin/bash
  2. # a dynamic Command Line Status printer
  3.  
  4. #Copyright 2012 Wesley (kbmonkey) Werner
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. # For when just piping to your WM bar isn't enough ;)
  20.  
  21. # USAGE
  22.  
  23. # - place this file in your PATH, like ~/bin/clis
  24. # - make executable: chmod +x ~/bin/clis
  25. # - configure keyboard shortcuts to: echo "mode?" > /tmp/clis-mode
  26. #   where ? is 1 to 4
  27.  
  28. # ~/.xbindkeysrc example using Super-F1 to F4:
  29. # use 'xbindkeys --key' to find the key codes.
  30. #
  31. #   "echo 'mode1' > /tmp/clis-mode"
  32. #       Mod2 + Mod4 + F1
  33. #
  34. #   "echo 'mode2' > /tmp/clis-mode"
  35. #       Mod2 + Mod4 + F2
  36. #
  37. #   "echo 'mode3' > /tmp/clis-mode"
  38. #       Mod2 + Mod4 + F3
  39. #
  40. #   "echo 'mode4' > /tmp/clis-mode"
  41. #       Mod2 + Mod4 + F4
  42. #
  43. # NOTIFICATIONS
  44. #
  45. # Write notification strings to /tmp/clis-notify
  46. # to show a quick message.
  47. #
  48. # launch clis at login autostart: clis &
  49. # enjoy toggling your bar infos back and forth :)
  50. #
  51. # kbmonkey!
  52. #
  53. # CHANGES
  54. #
  55. # 2013-02-13
  56. # + add DEFAULT_UPDATE_SPEED
  57. # + detect /tmp/clis-notify and show it's contents for DEFAULT_UPDATE_SPEED * 4
  58. # + check if any of the files exist before reading them
  59. # + append notifications to /tmp/clis-history
  60. #
  61. ################################################################################
  62. #
  63. # seconds between updates
  64. DEFAULT_UPDATE_SPEED=2
  65.  
  66. # help text lists the modes available
  67. HELPLINE=" &6S-F2 &5Now Playing &6S-F3 &5Conky &6S-F4 &5Todo"
  68.  
  69. # append to help text the WM shortcuts
  70. HELPLINE="&8S-A-# &7send to follow &8W-S-# &7send to no follow &8W-A &7rotate mode &8W-Tab &7last space &8S-A-j/k/o/p &7move"$HELPLINE
  71. #
  72. # for debugging: diplay snapwm colors
  73. #HELPLINE="&1 color1 &2 color2 &3 color3 &4 color4 &5 color5 &6 color6 &7 color7 &8 color8 &9 color9"
  74.  
  75. # MAIN LOOP
  76. #
  77. ################################################################################
  78. #
  79. while true
  80. do
  81.     # reset update speed
  82.     UPDATE_SPEED=$DEFAULT_UPDATE_SPEED
  83.  
  84.     # get the mode and notification text
  85.     if [ -e "/tmp/clis-mode" ]; then
  86.         ACTION=`cat /tmp/clis-mode`
  87.         else ACTION=""
  88.         fi
  89.     if [ -e "/tmp/clis-notify" ]; then
  90.         NOTIFY=`cat /tmp/clis-notify`
  91.         else NOTIFY=""
  92.         fi
  93.  
  94.     # there are notifications
  95.     if [[ "$NOTIFY" != "" ]]; then
  96.         # override the action to bypass the default help text
  97.         ACTION="notify"
  98.         # set the notification text
  99.         INFOLINE="&9$NOTIFY"
  100.         # show it for longer than the default
  101.         UPDATE_SPEED=$[DEFAULT_UPDATE_SPEED * 4]
  102.         # remove the notification file
  103.         rm /tmp/clis-notify
  104.         # write to notification history
  105.         echo `date +"%D %T"` "-" $NOTIFY >> /tmp/clis-history
  106.         # foo
  107.         fi
  108.    
  109.     # set the text to display based on what mode is set
  110.     case "$ACTION" in
  111.     mode2)
  112.         # now playing
  113.         INFOLINE="`ncmpcpp --now-playing '&5{{%t, &6by %a, from %b}}|{{%f}}'`"
  114.         ;;
  115.     mode3)
  116.         # conky: configured with out_to_console (yes) and out_to_x (no)
  117.         # ensure you symlink your conky config to ~/.conkyrc
  118.         INFOLINE=`conky -i 1 -c ~/.conkyrc`
  119.         # conky top cpu is faulty in out_to_console mode.
  120.         # (my guess it uses internal cpu averaging and not system values)
  121.         # add top 2 (head) processes
  122.         INFOLINE="$INFOLINE &8`ps -eo '%C%% %c' | sort -k1 -n -r | head -2 | tr '\n' ' '`"
  123.         ;;
  124.     mode4)
  125.         # next calcurse appointment & top todo item
  126.         INFOLINE=`calcurse -n | tr -s '\n' ' '`
  127.         INFOLINE="&5$INFOLINE  &8`cat ~/.calcurse/todo | head -n 1`"
  128.         ;;
  129.     notify)
  130.         # notification text
  131.         # this is here simply to bypass the *) test from setting the $HELPLINE
  132.         ;; 
  133.     *)
  134.         # hotkey help
  135.         INFOLINE=$HELPLINE
  136.         ;;
  137.     esac
  138.  
  139.     # append the time
  140.     INFOLINE="$INFOLINE &4#! `date +%T`"
  141.    
  142.     # set the root window title, which is how snapwm gets it's bar text.
  143.     # if you use another WM that has text piped to it's bar
  144.     # you can just echo "$INFOLINE".
  145.     xsetroot -name "$INFOLINE"
  146.     echo "$INFOLINE"
  147.    
  148.     # sleep until next time
  149.     sleep $UPDATE_SPEED
  150.    
  151. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement