Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # a dynamic Command Line Status printer
- #Copyright 2012 Wesley (kbmonkey) Werner
- #This program is free software: you can redistribute it and/or modify
- #it under the terms of the GNU General Public License as published by
- #the Free Software Foundation, either version 3 of the License, or
- #(at your option) any later version.
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #You should have received a copy of the GNU General Public License
- #along with this program. If not, see <http://www.gnu.org/licenses/>.
- # For when just piping to your WM bar isn't enough ;)
- # USAGE
- # - place this file in your PATH, like ~/bin/clis
- # - make executable: chmod +x ~/bin/clis
- # - configure keyboard shortcuts to: echo "mode?" > /tmp/clis-mode
- # where ? is 1 to 4
- # ~/.xbindkeysrc example using Super-F1 to F4:
- # use 'xbindkeys --key' to find the key codes.
- #
- # "echo 'mode1' > /tmp/clis-mode"
- # Mod2 + Mod4 + F1
- #
- # "echo 'mode2' > /tmp/clis-mode"
- # Mod2 + Mod4 + F2
- #
- # "echo 'mode3' > /tmp/clis-mode"
- # Mod2 + Mod4 + F3
- #
- # "echo 'mode4' > /tmp/clis-mode"
- # Mod2 + Mod4 + F4
- #
- # NOTIFICATIONS
- #
- # Write notification strings to /tmp/clis-notify
- # to show a quick message.
- #
- # launch clis at login autostart: clis &
- # enjoy toggling your bar infos back and forth :)
- #
- # kbmonkey!
- #
- # CHANGES
- #
- # 2013-02-13
- # + add DEFAULT_UPDATE_SPEED
- # + detect /tmp/clis-notify and show it's contents for DEFAULT_UPDATE_SPEED * 4
- # + check if any of the files exist before reading them
- # + append notifications to /tmp/clis-history
- #
- ################################################################################
- #
- # seconds between updates
- DEFAULT_UPDATE_SPEED=2
- # help text lists the modes available
- HELPLINE=" &6S-F2 &5Now Playing &6S-F3 &5Conky &6S-F4 &5Todo"
- # append to help text the WM shortcuts
- 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
- #
- # for debugging: diplay snapwm colors
- #HELPLINE="&1 color1 &2 color2 &3 color3 &4 color4 &5 color5 &6 color6 &7 color7 &8 color8 &9 color9"
- # MAIN LOOP
- #
- ################################################################################
- #
- while true
- do
- # reset update speed
- UPDATE_SPEED=$DEFAULT_UPDATE_SPEED
- # get the mode and notification text
- if [ -e "/tmp/clis-mode" ]; then
- ACTION=`cat /tmp/clis-mode`
- else ACTION=""
- fi
- if [ -e "/tmp/clis-notify" ]; then
- NOTIFY=`cat /tmp/clis-notify`
- else NOTIFY=""
- fi
- # there are notifications
- if [[ "$NOTIFY" != "" ]]; then
- # override the action to bypass the default help text
- ACTION="notify"
- # set the notification text
- INFOLINE="&9$NOTIFY"
- # show it for longer than the default
- UPDATE_SPEED=$[DEFAULT_UPDATE_SPEED * 4]
- # remove the notification file
- rm /tmp/clis-notify
- # write to notification history
- echo `date +"%D %T"` "-" $NOTIFY >> /tmp/clis-history
- # foo
- fi
- # set the text to display based on what mode is set
- case "$ACTION" in
- mode2)
- # now playing
- INFOLINE="`ncmpcpp --now-playing '&5{{%t, &6by %a, from %b}}|{{%f}}'`"
- ;;
- mode3)
- # conky: configured with out_to_console (yes) and out_to_x (no)
- # ensure you symlink your conky config to ~/.conkyrc
- INFOLINE=`conky -i 1 -c ~/.conkyrc`
- # conky top cpu is faulty in out_to_console mode.
- # (my guess it uses internal cpu averaging and not system values)
- # add top 2 (head) processes
- INFOLINE="$INFOLINE &8`ps -eo '%C%% %c' | sort -k1 -n -r | head -2 | tr '\n' ' '`"
- ;;
- mode4)
- # next calcurse appointment & top todo item
- INFOLINE=`calcurse -n | tr -s '\n' ' '`
- INFOLINE="&5$INFOLINE &8`cat ~/.calcurse/todo | head -n 1`"
- ;;
- notify)
- # notification text
- # this is here simply to bypass the *) test from setting the $HELPLINE
- ;;
- *)
- # hotkey help
- INFOLINE=$HELPLINE
- ;;
- esac
- # append the time
- INFOLINE="$INFOLINE &4#! `date +%T`"
- # set the root window title, which is how snapwm gets it's bar text.
- # if you use another WM that has text piped to it's bar
- # you can just echo "$INFOLINE".
- xsetroot -name "$INFOLINE"
- echo "$INFOLINE"
- # sleep until next time
- sleep $UPDATE_SPEED
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement