Inhaltsverzeichnis
file plugin
This plugin allows reading of a line or of a configuration value from a file, and checking whether a file exists.
Functions
| file::readline('/path/to/file', line_number) | returns line line_number (starting with 1) of the file |
| file::readconf('/path/to/file', key, fallback) | returns the value of key from a file with lines like key=value |
| file::exist('/path/to/file') | returns 1 if the file exists, 0 if not |
file::readline
Returns up to 255 characters of a line from a file. Characters after that in the line are simply ignored. If the file cannot be opened or has less lines than requested, an empty string is returned.
file::readconf
Searches the file for key and returns everything that follows the key in that line. The key is searched as plain text, so it has to contain the delimiter (e.g. 'brightness='), otherwise the delimiter would be part of the result. If the key is found in more than one line, the last one is used. If the key is not found or the file cannot be opened, fallback is returned.
Choose the key so that it is not part of another key: 'brightness=' would also match a line lcd_brightness=5.
file::exist
Returns 1 if the file (or directory) exists, otherwise 0. This is handy for visible entries of icons and images, or to react to flag files.
Example
Widget dmesgline99 {
class 'Text'
expression file::readline('/var/log/dmesg', 99)
width 20
align 'M'
update 10000
}
A file /etc/myapp.conf with this content
volume=40 brightness=7
can be read like this:
Widget Brightness {
class 'Text'
expression file::readconf('/etc/myapp.conf', 'brightness=', '10')
prefix 'Brightness '
width 14
update 5000
}
Widget RecordIcon {
class 'Image'
file '/share/icons/record.png'
visible file::exist('/tmp/.recording')
update 1000
}
