Difference between revisions of "Lemonbar"

From ArchWiki
Jump to: navigation, search
m (Examples: fixed example)
m (Newline removed, style fixes)
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
 
== 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.
 
  
== Configuration ==  
+
{{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.
 +
 
 +
== Configuration ==
 +
 
 
Configuration of bar is done at compile time in the file config.h. A default config.h looks like this:
 
Configuration of bar is done at compile time in the file config.h. A default config.h looks like this:
  
Line 49: Line 51:
 
}}
 
}}
  
==== Change location of the bar ====  
+
==== 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.
 
{{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.
Line 59: Line 61:
  
 
==== Change the font ====
 
==== 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}}.
 
{{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}}.
  
Line 67: Line 70:
  
 
==== Colors ====
 
==== 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).
 
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).
  
Line 85: Line 89:
  
 
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|bar}} to update through a script, you need to add the -p option.
 
  
 
==== Colors ====
 
==== Colors ====
 +
 
{{ic|bar}} uses the following commands to color the text, background or the under/overline.
 
{{ic|bar}} uses the following commands to color the text, background or the under/overline.
  
Line 94: Line 98:
 
! Command !! Description
 
! Command !! Description
 
|-
 
|-
| \f# || uses the # color as the font's color.  
+
| \f# || uses the # color as the font's color.
 
|-
 
|-
 
| \b# || Uses the # color as the background
 
| \b# || Uses the # color as the background
Line 121: Line 125:
  
 
{{hc|example.sh|
 
{{hc|example.sh|
#!/usr/bin/bash
+
#!/bin/bash
  
 
# Define the clock
 
# Define the clock
 
Clock() {
 
Clock() {
    DATE=$(date "+%a %b %d, %T")
+
        DATE=$(date "+%a %b %d, %T")
   
+
 
    echo -n "$DATE"
+
        echo -n "$DATE"
 
}
 
}
  
Line 133: Line 137:
  
 
while true; do
 
while true; do
    echo "\c\f1\b0\u6 $(Clock)\ur"
+
        echo "\c\f1\b0\u6 $(Clock)\ur"
    sleep 1;
+
        sleep 1;
 
done
 
done
 
}}
 
}}
Line 141: Line 145:
  
 
{{hc|example.sh|
 
{{hc|example.sh|
#!/usr/bin/bash
+
#!/bin/bash
  
 
#Define the battery
 
#Define the battery
 
Battery() {
 
Battery() {
    BATPERC=$(acpi --battery | awk -F, '{print $2}')
+
        BATPERC=$(acpi --battery | awk -F, '{print $2}')
    echo "$DATE"
+
        echo "$BATPERC"
 
}
 
}
  
 
# Print the percentage
 
# Print the percentage
 
while true; do
 
while true; do
    echo "\r$(Battery)"
+
        echo "\r$(Battery)"
    sleep 1;
+
        sleep 1;
 
done
 
done
 
}}
 
}}

Revision as of 12:09, 2 July 2013

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.

Installation

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

Configuration

Configuration of bar is done at compile time in the file config.h. A default config.h looks like this:

config.h
/* 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 make in the directory to make a config.h automatically from the config.def.h text file. After you're done configuring recompile.

Use an overline instead of an underline

bar by default supports underlining text with a certain color, but it also supports overlining text instead. To make bar overline the text replace the 1 with a 0 in the following line

config.h
/* Choose between an underline or an overline */
#define BAR_UNDERLINE 0

Change location of the bar

bar can be placed at the top or the bottom of the screen. It defaults to be on the top. To get bar on the bottom, edit the following lines in config.h or use the option -b at runtime.

config.h
/* Default bar position, overwritten by '-b' switch */
#define BAR_BOTTOM 1

Change the font

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 stlarch_fontAUR. To use such a font, install the font and edit config.h accordingly. The below example shows how to change the bar font to use stlarch.

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 bar supports the use of up to ten colors. These are defined at the bottom 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(COLOR6 to black(000000).

config.h
#define COLOR6 0x000000

Usage

Bar prints no information on its own. To get any text into bar 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 bar to update through a script, you need to add the -p option.

Colors

bar uses the following commands to color the text, background or the under/overline.

Colors
Command Description
\f# uses the # color as the font's color.
\b# Uses the # color as the background
\u# Uses the # color for under/overlining the text.

Text alignment

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

Tabular data
Distro Color
\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 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 /path/to/script/example.sh | bar -p

example.sh
#!/bin/bash

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

        echo -n "$DATE"
}

# Print the clock

while true; do
        echo "\c\f1\b0\u6 $(Clock)\ur"
        sleep 1;
done

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

example.sh
#!/bin/bash

#Define the battery
Battery() {
        BATPERC=$(acpi --battery | awk -F, '{print $2}')
        echo "$BATPERC"
}

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