Skip to content

Selection of personal plugins (with a focus on debian) for the Haskell status-bar xmobar.

License

Notifications You must be signed in to change notification settings

tsiliakis/xmobar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TL;DR

If you're just searching for the plugins I wrote, they are here :

I'm gratefull for any comments or hints !


xmobar

On this page I try to gather some information about xmobar, which is a status bar written in Haskell. Here is the “about”-part from the official website.

xmobar is a minimalistic, mostly text based, status bar. It was originally designed and implemented by 
Andrea Rossato to work with xmonad, but it's actually usable with any window-manager. xmobar was inspired 
by the Ion3 status bar, and supports similar  features, like dynamic color management, icons,
output templates, and extensibility through plugins.

Xmobar can be used with any window manager or desktop environment. You can use it with xmonad, which is a excellent minimalistic window manager also written in Haskell (screenshot), Gnome, KDE or as I do - with XFCE.

Installing xmobar should be quite painless with your distribution's package manager, but can also be done via Cabal or the source code on Github. Again the official website has excellent documentation on how each method works. I recommend on playing around with xmobar at first with your package managers version, but would switch to a more up-to-date version via cabal or source code, since then you can implement your own plugins and maybe even the plugins I wrote.

Plugins

Writing your own plugin

If you want to write your own plugin, the first stop should be the HelloWorld example (if you want the full source code, just click on HelloWorld.hs in the lower left corner of this snippet). This plugin implements the most basic functionality, that a plugin should have. As you can see, you can have your own plugin in 6 lines of code.

<script src="http://gist-it.appspot.com/github/jaor/xmobar/blob/master/samples/Plugins/HelloWorld.hs?slice=15:24&footer=minimal"></script>

I won't go into details about how to write a plugin, since the official site again does a great job at explaining it. On thing I will say to writing plugins is, that I recommend to start small. Have a rought idea of what you want to achieve and write it down in a simple .hs file. I wouldn't start immediately with the plugin, but first make sure, that your code is working and more importantly, working the way you intend to. Run it through ghci and play around with it, or even better - write tests. If you have a working .hs file , making it into a plugin is just adding a few lines at the top and the bottom.

Using your plugins

In this section I will explain how to make XMobar recognize your plugins. As an example I use two of my own plugins : ShowIP and Countdown. Wherever you find those two names, you can just replace them with the name of your own plugin.For XMobar to be able to find your plugins, you have to place them in the right folder. The most convenient place is src/Plugins. Just copy your completed plugin into that folder. Next, you have to import your plugins into xmobar. This is done in two files.

./src/Config.hs

Here you have to import your module. You can see that I just wrote my own plugins under the default plugins. Of course you can write yours at the top, but be sure to mark them in some way, so you can find them again. :)

src/Config.hs
{...}
 
import Plugins.Kbd
import Plugins.Locks
-- these are my plugins that I wrote and I add them here
import Plugins.ShowIP
import Plugins.Countdown
 
{...}

The second thing you have to do, while you're in Config.hs, is to add your plugin data type to the runnableTypes list data type. ( Notice the :*: at the end )

src/Config.hs
{...}
 
runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: BufferedPipeReader :*: CommandReader :*: StdinReader :*: 
XMonadLog :*: EWMH :*: Kbd :*: Locks :*: ShowIP :*: Countdown :*:
 
{...}
xmobar.cabal

If you used some external modules in your project, the right place to import them is the xmobar.cabal-file in the root directory. Just append the package name of your module and the appropriate version. If you're unsure what version to use, you can identify the function(s) you are using and find the oldest version where they function the way you want. If you are more in a hurry, or just want to test things, you can just put in the version you are currently using. An easy way to find out the version is the command cabal info <package-name> and the field Versions installed : .

xmobar.cabal
{...}
 
   build-depends:
      base == 4.*,
      containers,
      process,
      old-locale,
      bytestring,
      directory,
      unix,
      time,
      filepath,
      X11 >= 1.6.1,
      mtl >= 2.0 && < 2.2,
      parsec == 3.1.*,
      stm >= 2.3 && < 2.5,
-- manually added dependency for my plugins
      HTTP >= 4000.0.5
 
{...}

Building your plugins

The easiest way to build your own plugins is by using cabal. If you checked out the git repo, you just have to go into the directory with the xmobar.cabal and execute the following command :

cabal configure --enable-benchmarks --enable-tests --verbose=2 && cabal build --verbose=2 && cabal install --haddock-executables

This command creates also the Haddock documentation and the verbosity level is increased. Also dependency checking, compilation for test suites and compilation for benchmarks is activated.

My Plugins

ShowIP

A simple plugin to display the external IP or any other String from a webserver.

This plugin can be pointed to a website, retrieves its content with a Http GET and displays the string. It needs 3 parameters : a String, which is the prefix (e.g. 'IP : '), a String which is the url of the server and a int which is the rate the plugin updates in tenths of seconds.

As a simple server that returns a IP, feel free to use my server at http:srv.u0.org/ip.php , but I can't guarantee that it will be up forever. An alternative is http:wtfismyip.com/text.

Countdown

A simple plugin to display the remaining days till a specific date.

This plugin needs 5 parameters : The date's Year Month Day and a string that can be shown after the difference of days. The recommendet value for the string is ' Days'. The last parameter is the update rate of the plugin in tenth of seconds.

It can be used as a countdown till e.g. New Years or vacations. If you set the date to New Years you automatically get the day of the year.

AptUpdates

A simple plugin to display the number of packages that can be updated via aptitude.

The plugin needs 2 parameters : a string to display after the number of updatable packages and the rate the plugin should check for new packages in tenth of seconds. It's best when you have a cron-job to update the package database (aptitude update) and use this plugin to show the packages that are available to be updated. This plugin does not(!) automatically update your repository, since root rights are needed for that.

Since it uses aptitude, you have to run a system with aptitude. This plugin was tested on Debian Wheezy 3.2.0-4-amd64 and was build with aptitude 0.6.8.2 in mind.

LoadAverage

A simple plugin to display the load average of the system.

This plugin is using uptime to retrieve the load average and then parses the result to a definable form. It needs 2 paramters : a String that will be displayed before the load average (e.g. 'Load average :') and another String, which will be used as the delimiter. E.g. - , which will result in '0.93 - 0.97 - 1.01'. of course a simple space ' ' can also be used).

xmobar configuration

To get xmobar running you need a config file in your home directory. This file is usually called .xmobarrc. Here you can fine tune your xmobar, configure which plugins to run and how to show them. xmmobar's config file is quite easy to modify and is more or less self explanatory. I will once again point to the official documentation, but will attach my configuration that works with xmobar 0.18. Modification is maybe needed on the network interface (mine is eth0) and in order to run Countdown, ShowIP, AptUpdates and LoadAverage you have to compile my plugins.

Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , borderColor = "black"
       , border = TopB
       , bgColor = "black"
       , fgColor = "white"
       , position = Bottom
       , lowerOnStart = False
       , persistent = False
       , hideOnStart = False
       , allDesktops = True
       , overrideRedirect = True
       , commands = [ Run Network "eth0" ["-L","0","-H","1600","--normal","green","--high","red","-m","4","-t","<rx>/<tx>"] 10
                    , Run Memory ["-t","Mem: <used> MB"] 30
                    , Run Swap [] 1000
                    , Run Date "%A, %e.%0m %B - %_H:%M" "date" 10
                    , Run MultiCpu ["-t","CPU : <bar> <total0>% /<total1>%","-L","3","-H","50","--normal","green","--high","white","-p","3","-b"," ","-f","|"] 10
                    , Run Countdown 2013 7 11 " Days " 36000
                    , Run ShowIP "IP : " "http://srv.u0.org/ip.php" 6000
                    , Run AptUpdates " new Packages" 36000
                    , Run LoadAverage "Load : " " " 200
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%multicpu% | %memory% * %swap% | %eth0% | %ShowIP% | %Countdown% | %AptUpdates% }{ %LoadAverage% - %date%"
       }

One thing I want to point out, is a specific error, that puzzled me at first :

configuration file contains errors at:
"Config" (line 23, column 10):
unexpected "s"
expecting space or "Run"

This error is thrown by xmobar, when you change your config and the parameters for the plugins aren't right. Don't be confused by the line and column that are printed, this has to the with the fact, that the plugins aren't loaded properly and Haskell expects a parameter and finds the field sepChar. A good way to debug this, is to comment out the any line in question and start with a plain config.

About

Selection of personal plugins (with a focus on debian) for the Haskell status-bar xmobar.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages