Difference between revisions of "Lemonbar"

From ArchWiki
Jump to: navigation, search
m (Newline removed, style fixes)
(Clarify the "-" color; minor cleanup)
 
(12 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:Desktop environments]]
+
[[Category:Eye candy]]
[https://github.com/LemonBoy/bar b(ar) a(in't) r(ecursive)] is a lightweight bar based on XCB. It provides foreground/background color switching along with text alignment and colored under/overlining of text, full utf8 support and reduced memory footprint. Nothing less and nothing more.
+
[https://github.com/LemonBoy/bar lemonbar] is a lightweight bar based on XCB. It provides foreground/background color switching along with text alignment and colored under/overlining of text, full utf8 support and reduced memory footprint. Nothing less and nothing more.
  
 
== Installation ==
 
== Installation ==
  
{{AUR|bar-aint-recursive}} is available in the AUR and can be installed manually or through the use of a AUR helper of your choice.
+
{{AUR|lemonbar-git}} is available in the AUR and can be installed manually or through the use of a AUR helper of your choice.
  
 
== Configuration ==
 
== Configuration ==
  
Configuration of bar is done at compile time in the file config.h. A default config.h looks like this:
+
Configuration of lemonbar is now completely done via {{ic|screenrc}}-like format strings and command line options as opposed to older versions, where configuration took place at compile-time.
  
{{hc|config.h|
+
See the man page for a short overview of those configuration options.
/* The height of the bar (in pixels) */
+
#define BAR_HEIGHT 18
+
/* The width of the bar. Set to -1 to fit screen */
+
#define BAR_WIDTH -1
+
/* Offset from the left. Set to 0 to have no effect */
+
#define BAR_OFFSET 0
+
/* Choose between an underline or an overline */
+
#define BAR_UNDERLINE 1
+
/* The thickness of the underline (in pixels). Set to 0 to disable. */
+
#define BAR_UNDERLINE_HEIGHT 2
+
/* Default bar position, overwritten by '-b' switch */
+
#define BAR_BOTTOM 0
+
/* The fonts used for the bar, comma separated. Only the first 2 will be used. */
+
#define BAR_FONT "-*-terminus-medium-r-normal-*-12-*-*-*-c-*-*-1","fixed"
+
/* Some fonts don't set the right width for some chars, pheex it */
+
#define BAR_FONT_FALLBACK_WIDTH 6
+
/* Color palette */
+
#define COLOR0 0x1A1A1A /* background */
+
#define COLOR1 0xA9A9A9 /* foreground */
+
#define COLOR2 0x303030
+
#define COLOR3 0xF92672
+
#define COLOR4 0xA6E22E
+
#define COLOR5 0xFD971F
+
#define COLOR6 0x66D9EF
+
#define COLOR7 0x9E6FFE
+
#define COLOR8 0xAF875F
+
#define COLOR9 0xCCCCC6
+
}}
+
 
+
To change the config file, clone the git repository and write the config.h. You can run {{ic|make}} in the directory to make a config.h automatically from the {{ic|config.def.h}} text file. After you're done configuring recompile.
+
 
+
==== Use an overline instead of an underline ====
+
 
+
{{ic|bar}} by default supports underlining text with a certain color, but it also supports overlining text instead. To make {{ic|bar}} overline the text replace the 1 with a 0 in the following line
+
 
+
{{hc|config.h|
+
/* Choose between an underline or an overline */
+
#define BAR_UNDERLINE 0
+
}}
+
 
+
==== Change location of the bar ====
+
 
+
{{ic|bar}} can be placed at the top or the bottom of the screen. It defaults to be on the top. To get {{ic|bar}} on the bottom, edit the following lines in {{ic|config.h}} or use the option -b at runtime.
+
 
+
{{hc|config.h|
+
/* Default bar position, overwritten by '-b' switch */
+
#define BAR_BOTTOM 1
+
}}
+
 
+
==== Change the font ====
+
 
+
{{ic|bar}} does not support image files per se, but it does support bitmap fonts that allows you to use a font with icons such as {{AUR|stlarch_font}}. To use such a font, install the font and edit {{ic|config.h}} accordingly. The below example shows how to change the bar font to use {{ic|stlarch}}.
+
 
+
{{hc|config.h|
+
/* The fonts used for the bar, comma separated. Only the first 2 will be used. */
+
#define BAR_FONT "-misc-stlarch-medium-*-normal-*-10-*-*-*-c-*-*-1","fixed"
+
}}
+
 
+
==== Colors ====
+
 
+
Lastly {{ic|bar}} supports the use of up to ten colors. These are defined at the bottom {{ic|config.h}}. The colors are defined in a hexadecimal format. The last six characters in each of the color lines define the color. For example would the following code change the 6th color({{ic|COLOR6}} to black(000000).
+
 
+
{{hc|config.h|
+
#define COLOR6 0x000000
+
}}
+
  
 
== Usage ==
 
== Usage ==
  
Bar prints no information on its own. To get any text into {{ic|bar}} you need to pipe text into it. The following example would write the text "Hello World" into your bar.
+
{{ic|lemonbar}} prints no information on its own. To get any text into {{ic|lemonbar}} you need to pipe text into it. The following example would write the text "Hello World" into your bar.
  
 
{{bc|
 
{{bc|
Line 88: Line 23:
 
}}
 
}}
  
If you want the text in {{ic|bar}} to update through a script, you need to add the -p option.
+
If you want the text in {{ic|lemonbar}} to update through a script, you need to add the {{ic|-p}} option. This prevents {{ic|lemonbar}} from exiting after stdin is closed.
  
 
==== Colors ====
 
==== Colors ====
  
{{ic|bar}} uses the following commands to color the text, background or the under/overline.
+
{{ic|lemonbar}} uses the following commands to color the text, background or the under/overline. Colors can be specified via the formats {{ic|#RRGGBB}}, {{ic|#AARRGGBB}} (with an alpha channel; this requires a compositor to be running), or even {{ic|#RGB}}.
 +
 
 +
The special color {{ic|-}} indicates the default color (which is set by command-line flags, or is otherwise the default white text on a black background).
  
 
{| border="1"
 
{| border="1"
|+ Colors
+
! Command !! Meaning
! Command !! Description
+
 
|-
 
|-
| \f# || uses the # color as the font's color.
+
| {{ic|%{F''color''} }} || Use ''color'' as the foreground/font color
 
|-
 
|-
| \b# || Uses the # color as the background
+
| {{ic|%{B''color''} }} || Use ''color'' as the background
 
|-
 
|-
| \u# || Uses the # color for under/overlining the text.
+
| {{ic|%{U''color''} }} || Use ''color'' for under/overlining the text
 
|}
 
|}
  
 
==== Text alignment ====
 
==== Text alignment ====
  
{{ic|bar}} also supports alignment of text. It uses the following commands to align the text
+
{{ic|lemonbar}} also supports alignment of text. It uses the following commands to align the text
  
 
{| border="1"
 
{| border="1"
|+ Tabular data
+
! Command !! Meaning
! Distro !! Color
+
 
|-
 
|-
| \l || Aligns the text to the left
+
| {{ic|%{l} }} || Aligns the text to the left
 
|-
 
|-
| \c || Aligns the text to the center
+
| {{ic|%{c} }} || Aligns the text to the center
 
|-
 
|-
| \r || Aligns the text to the right
+
| {{ic|%{r} }} || Aligns the text to the right
 
|}
 
|}
  
 
==== Examples ====
 
==== Examples ====
  
The following example prints the date and time in the middle of the bar underlined by COLOR6, the font's color being COLOR1 and the background COLOR0 and changes the underline back to the backgrounds color afterwards. Run it with {{ic|/path/to/script/example.sh | bar -p}}
+
The following example prints the date and time in the middle of the bar, the font's color being {{ic|yellow}} and the background {{ic|blue}} and changes the font/background color back to the default color afterwards. Run it with {{ic|/path/to/script/example.sh | lemonbar -p}}
  
 
{{hc|example.sh|
 
{{hc|example.sh|
#!/bin/bash
+
#!/usr/bin/bash
  
 
# Define the clock
 
# Define the clock
 
Clock() {
 
Clock() {
         DATE=$(date "+%a %b %d, %T")
+
         DATETIME=$(date "+%a %b %d, %T")
  
         echo -n "$DATE"
+
         echo -n "$DATETIME"
 
}
 
}
  
Line 137: Line 72:
  
 
while true; do
 
while true; do
         echo "\c\f1\b0\u6 $(Clock)\ur"
+
         echo "%{c}%{F#FFFF00}%{B#0000FF} $(Clock) %{F-}%{B-}"
         sleep 1;
+
         sleep 1
 
done
 
done
 
}}
 
}}
Line 145: Line 80:
  
 
{{hc|example.sh|
 
{{hc|example.sh|
#!/bin/bash
+
#!/usr/bin/bash
  
 
#Define the battery
 
#Define the battery
 
Battery() {
 
Battery() {
         BATPERC=$(acpi --battery | awk -F, '{print $2}')
+
         BATPERC=$(acpi --battery | cut -d, -f2)
 
         echo "$BATPERC"
 
         echo "$BATPERC"
 
}
 
}
Line 155: Line 90:
 
# Print the percentage
 
# Print the percentage
 
while true; do
 
while true; do
         echo "\r$(Battery)"
+
         echo "%{r}$(Battery)"
 
         sleep 1;
 
         sleep 1;
 
done
 
done
 
}}
 
}}

Latest revision as of 00:05, 15 January 2016

lemonbar is a lightweight bar based on XCB. It provides foreground/background color switching along with text alignment and colored under/overlining of text, full utf8 support and reduced memory footprint. Nothing less and nothing more.

Installation

lemonbar-gitAUR is available in the AUR and can be installed manually or through the use of a AUR helper of your choice.

Configuration

Configuration of lemonbar is now completely done via screenrc-like format strings and command line options as opposed to older versions, where configuration took place at compile-time.

See the man page for a short overview of those configuration options.

Usage

lemonbar prints no information on its own. To get any text into lemonbar you need to pipe text into it. The following example would write the text "Hello World" into your bar.

#!/bin/bash

# Echo the text
echo "Hello World"

If you want the text in lemonbar to update through a script, you need to add the -p option. This prevents lemonbar from exiting after stdin is closed.

Colors

lemonbar uses the following commands to color the text, background or the under/overline. Colors can be specified via the formats #RRGGBB, #AARRGGBB (with an alpha channel; this requires a compositor to be running), or even #RGB.

The special color - indicates the default color (which is set by command-line flags, or is otherwise the default white text on a black background).

Command Meaning
%{Fcolor} Use color as the foreground/font color
%{Bcolor} Use color as the background
%{Ucolor} Use color for under/overlining the text

Text alignment

lemonbar also supports alignment of text. It uses the following commands to align the text

Command Meaning
%{l} Aligns the text to the left
%{c} Aligns the text to the center
%{r} Aligns the text to the right

Examples

The following example prints the date and time in the middle of the bar, the font's color being yellow and the background blue and changes the font/background color back to the default color afterwards. Run it with /path/to/script/example.sh | lemonbar -p

example.sh
#!/usr/bin/bash

# Define the clock
Clock() {
        DATETIME=$(date "+%a %b %d, %T")

        echo -n "$DATETIME"
}

# Print the clock

while true; do
        echo "%{c}%{F#FFFF00}%{B#0000FF} $(Clock) %{F-}%{B-}"
        sleep 1
done

Another example showing the battery percentage. To use this script you need to install acpi.

example.sh
#!/usr/bin/bash

#Define the battery
Battery() {
        BATPERC=$(acpi --battery | cut -d, -f2)
        echo "$BATPERC"
}

# Print the percentage
while true; do
        echo "%{r}$(Battery)"
        sleep 1;
done