You are not logged in.

#1 2017-07-24 21:24:21

damo
....moderator....
Registered: 2015-08-20
Posts: 5,280

HowTo convert Conky v1.9 to v1.10 - using convert.lua

HowTo convert Conky v1.9 to v1.10

                                                                            by damo and Sector11 (The Gruesome Twosome)
Conky Wiki.    This link is also in Menu -> Help & Support -> Conky

With the coming of Conky v1.10 in LUA format, it is possible your old conky configs will no longer work properly, or break completely. Conky v1.10 will attempt to convert on the fly, but this doesn't always work. Conky v1.10 is available in Debian Stretch (now stable), and this is what you will get if you dist-upgrade from jessie to stretch (or install BL Helium when it is released).

But what about all those conkys you have now that you have been/are using in the v1.9 and earlier format? Simple: convert them.

When conky v1.10 is installed it comes with a file called convert.lua, which you can find in:

/usr/share/doc/conky-all/convert.lua

Or you can get a copy here and save it in your $PATH (eg. '~/bin'), make it executable and you're off to the races.

The Conky Wiki says, among other things (HINT: it's a useful read wink ):

Conky Wiki wrote:

Some things have changed since the release of 1.10, there is a new way of writing the settings and variables and some settings/variables are removed. The good news is the Lua API hasn't been changed so all your Lua scripts still work!
Unfortunately the convert script is not flawless, you might still need to tweak it somewhat but it should take care of the more annoying and tedious work (syntax change).

The easiest way to convert an existing config is to use the convert.lua script: The convert.lua usage is:

$ convert.lua 
Usage: convert.lua old_conkyrc [new_conkyrc]

Tries to convert conkyrc from the old v1.x format to the new, lua-based format.

Keep in mind that there is no guarantee that the output will work correctly
with conky, or that it will be able to convert every conkyrc. However, it
should provide a good starting point.

Altough you can use this script with only 1 arg and let it overwrite the old
config, it's suggested to use 2 args so that the new config is written in a new
file (so that you have backup if something went wrong).

For more information about the new format, read the wiki page
<https://github.com/brndnmtthws/conky/wiki>

So, be clever and use 2 arguments angel  (NB: the url in convert.lua is out-of-date and will 404. The one shown here is the active one)

LUA syntax for settings

From Configuration File Syntax

  • Each setting's argument(s) must be enclosed in single or double quotation marks (unless the argument is a boolean or a number).

So these are all acceptable:

update_interval = 10,
out_to_console = true,
out_to_stderr = "no",
color0 = '000000',

Don't leave an empty value like you can with Conky v1.9 - Conky v1.10 will fail!

------------------------------------------------------------------------

Things to watch out for after the conversion
  • The most noticeable changes are the settings section: all the settings are now placed in conky.config = { settings here }; and the TEXT section is placed in conky.text = [[ text section ]].

  • The values in the config section are separated by a "," although a comma isn't needed after the last one.

  • Comments start with "--". You can have multiline comments by using: "--[[ your text ]]"

Comments

-- This is a comment

--[[   		<-- starts commented block
This is a multiline comment
with lots of lines.
Here is another one :)
]]   		<-- ends commented block

NB: The conky.text = [[ ]] section treats the text same way as in v1.9, so commented lines must start with "#" NOT "--".
In fact, you could copy and paste everything below "TEXT" in your v1.9 Conky into conky.text[[ ... ]].

conky.text = [[ 
# This a comment 
-- This is NOT a comment, and will appear in the output!
]]

A major potential gotcha is that convert.lua seems to be looking for the word "TEXT", and uses it to decide where to place the "conky.text=". If you have eg "## TEXT..." somewhere, config.text may end up in the wrong place.

Remember, Conky v1.10 treats "#" as a comment, so doesn't convert anything after the first one on a line:

## own_window_type normal

becomes

--# own_window_type normal

If you subsequently uncomment this, it needs to be changed to v1.10 syntax:

own_window_type = 'normal',

Color hexcodes

Colors do not use the "#" any more (and they weren't supposed to before anyway!), so "#DCDCDC" becomes "DCDCDC", "${color DCDCDC}" or "color0 = 'DCDCDC',". But, maybe it's a bug, but "color0 DCDCDC" converts to "color0 = '#DCDCDC',"!

However, both of these work with no complaints in v1.10:

default_color = '000000',
default_color = '#000000',
...
${color 000000}
${color #000000}

This "undocumented feature", although discouraged, is actually quite handy when copy/pasting from a colour picker wink

NB: If you use a simple sed command to scrub any leftover "#" characters from your conkys, be aware that they will be removed from any comments in 'conky.text = [[  ]]', so you will need to put them back again for commented lines!

sed -i 's/#//g' conkyfile

@johnraff has suggested this one, which will remove "#" only if it's at the front of a six-character word:

sed -ri 's/#([[:alnum:]]{6})\b/\1/g'

Warning: Although "probably safe enough", this command will remove the "#" from a real comment if:

  • There is no space after the # (usually there is).

  • The first word has exactly six letters, like #yellow

If your conky v1.9 uses hexcodes for colour commands without the "#" you are OK, but you are in trouble if you use settings like:

draw_shades yes
default_shade_color #000000
draw_outline no
default_outline_color #000000
default_color = #DCDCDC    #Gainsboro
color0 = #98FB98           #PaleGreen

Because v1.10 treats "#" in conky.config = {  } as a comment, after conversion this will become

draw_shades = true,
default_shade_color = '',--000000
draw_outline = false,
default_outline_color = '',--000000
default_color = '',--DCDCDC    #Gainsboro
color0 = '',--98FB98           #PaleGreen

   
Not what you want, and conky will fail! So clean out those #hexcodes to read just the 6 character hex values without the "#", and then it will convert to:

draw_shades = true,
default_shade_color = '#000000',
draw_outline = false,
default_outline_color = '#000000',
default_color = '#DCDCDC',    --Gainsboro
color0 = '#98FB98',           --PaleGreen

Which does do the job, even though the documentation says the hexcodes shouldn't have a "#" wink
   
Some variables are changed or no longer available

Conky Wiki wrote:

Some variables have had subtle changes, for example the rss variable updates now in seconds instead of minutes. If you experience any weird behavior with your new config, I advise you to check out the manual for a possible change in variable syntax. Some variables are also not available anymore in conky 1.10 eg. ${pre_exec ...}. When you still can not find the correct solution you might want to try the -D or -DD flag when you start conky in your terminal eg. conky -DD -c /PATH/TO/CONFIG . This will run conky in debug mode giving you an insight into what conky is doing at the moment.

------------------------------------------------------------------------

Conversion Example

BunsenLabs Hydrogen default conkyrc, "BL-Default.conkyrc", for Conky v1.9

###  Begin Window Settings  #####################
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,skip_taskbar,skip_pager,sticky
own_window_colour 000000
own_window_class Conky
own_window_title Bunsen Labs Default Conky

### ARGB can be used for real transparency
### NOTE that a composite manager is required for real transparency.
### This option will not work as desired (in most cases) in conjunction with
### own_window_type normal
# own_window_argb_visual yes # Options: yes or no

### When ARGB visuals are enabled, this use this to modify the alpha value
### Use: own_window_type normal
### Use: own_window_transparent no
### Valid range is 0-255, where 0 is 0% opacity, and 255 is 100% opacity.
# own_window_argb_value 50

minimum_size 200 0  ### width | height
maximum_width 200

gap_x 20    ### left | right
gap_y 45    ### up | down

alignment tr
#######################  End Window Settings  ###
###  Font Settings  #############################
# Use Xft (anti-aliased font and stuff)
use_xft yes
xftfont Monospace:bold:size=9
#xftfont Liberation Sans:size=9

# Alpha of Xft font. Must be a value at or between 1 and 0 ###
xftalpha 1
# Force UTF8? requires XFT ###
override_utf8_locale yes

uppercase no
#########################  End Font Settings  ###
###  Colour Settings  ###########################
draw_shades no #yes
default_shade_color 000000

draw_outline no # amplifies text if yes
default_outline_color 000000

#default_color 656667 # Waldorf original colour
#default_color 7a7a7a # Flame  & Bunsen Grey
#default_color 929292 # Labs Grey
default_color C0C0C0 # Silver
color0 B0E0E6 # PowderBlue
color1 778899 # LightSlateGray
color2 D8BFD8 # Thistle
color3 9ACD32 # YellowGreen
color4 FFA07A # LightSalmon
color5 FFDEAD # NavajoWhite
color6 00BFFF # DeepSkyBlue
color7 5F9EA0 # CadetBlue
color8 BDB76B # DarkKhaki
color9 CD5C5C # IndianRed
#######################  End Colour Settings  ###
###  Borders Section  ###########################
draw_borders no
# Stippled borders?
stippled_borders 5
# border margins
border_inner_margin 5
border_outer_margin 0
# border width
border_width 2
# graph borders
draw_graph_borders yes #no
#default_graph_size 15 40
#######################  End Borders Section  ###
###  Miscellaneous Section  #####################
# Boolean value, if true, Conky will be forked to background when started.
background yes

# Adds spaces around certain objects to stop them from moving other things
# around, this only helps if you are using a mono font
# Options: right, left or none
use_spacer none

# Default and Minimum size is 256 - needs more for single commands that
# "call" a lot of text IE: bash scripts
text_buffer_size 6144

# Subtract (file system) buffers from used memory?
no_buffers yes

# change GiB to G and MiB to M
short_units yes

# Like it says, ot pads the decimals on % values
# doesn't seem to work since v1.7.1
pad_percents 2

# Imlib2 image cache size, in bytes. Default 4MiB Increase this value if you use
# $image lots. Set to 0 to disable the image cache.
imlib_cache_size 0

# Use the Xdbe extension? (eliminates flicker)
# It is highly recommended to use own window with this one
# so double buffer won't be so big.
double_buffer yes

#   Maximum size of user text buffer, i.e. layout below TEXT line in config file
#  (default is 16384 bytes)
# max_user_text 16384

# Desired output unit of all objects displaying a temperature. Parameters are
# either "fahrenheit" or "celsius". The default unit is degree Celsius.
# temperature_unit Fahrenheit

#################  End Miscellaneous Section  ###
#### ${font Monospace:bold:size=10}${alignc}${execpi 600 $HOME/.config/conky/scripts/bunsenweather.sh}
update_interval 1

TEXT
${color}${alignc}S Y S T E M    I N F O
${hr}
Host:${alignr}${nodename}
Uptime:${alignr}${uptime}
UTC:${alignr}${utime %H:%M}

${goto 60}Used${alignr}Size
Root${goto 60}${fs_used /}${alignr}${fs_size /}
Home${goto 60}${fs_used /home}${alignr}${fs_size /home}

${goto 60}MEM${alignr}MAX
RAM${goto 60}${mem}${alignr}${memmax}
Swap${goto 60}${swap}${alignr}${swapmax}

CPU:${goto 60}Used${alignr}GHz
Avg${goto 60}${if_match ${cpu cpu0}<10}  ${cpu cpu0}\
${else}${if_match ${cpu cpu0}<100} ${cpu cpu0}\
${else}${cpu cpu0}${endif}${endif}%${alignr}${freq_g}

${alignc}S H O R T C U T    K E Y S
${hr}
[Alt] + F2${alignr}Run Dialog
[Alt] + F3${alignr}Alt Menu
[S] + Space${alignr}Main Menu
[S] + Tab${alignr}Client Menu
[S] + t${alignr}Terminal
[S] + f${alignr}File Manager
[S] + e${alignr}Editor
[S] + m${alignr}Media Player
[S] + w${alignr}Web Browser
[S] + h${alignr}Task Manager
[S] + l${alignr}Lock Screen
[S] + v${alignr}Volume Control
[S] + x${alignr}Logout
[PrtSc]${alignr}Screenshot

Then do:

convert.lua BL-Default.conkyrc BL-Default-v10.conkyrc

The result, for BunsenLabs Helium default conkyrc, "BL-Default.conkyrc", for Conky v1.10:

conky.config = {
--##  Begin Window Settings  #####################
	own_window = true,
	own_window_type = 'normal',
	own_window_transparent = true,
	own_window_hints = 'undecorated,below,skip_taskbar,skip_pager,sticky',
	own_window_colour = '#000000',
	own_window_class = 'Conky',
	own_window_title = 'Bunsen Labs Default Conky',

--## ARGB can be used for real transparency
--## NOTE that a composite manager is required for real transparency.
--## This option will not work as desired (in most cases) in conjunction with
--## own_window_type normal
-- own_window_argb_visual yes # Options: yes or no

--## When ARGB visuals are enabled, this use this to modify the alpha value
--## Use: own_window_type normal
--## Use: own_window_transparent no
--## Valid range is 0-255, where 0 is 0% opacity, and 255 is 100% opacity.
-- own_window_argb_value 50

	minimum_width = 200, minimum_height = 0,--## width | height
	maximum_width = 200,

	gap_x = 20,--## left | right
	gap_y = 45,--## up | down

	alignment = 'top_right',
--######################  End Window Settings  ###
--##  Font Settings  #############################
-- Use Xft (anti-aliased font and stuff)
	use_xft = true,
	font = 'Monospace:bold:size=9',
--xftfont Liberation Sans:size=9

-- Alpha of Xft font. Must be a value at or between 1 and 0 ###
	xftalpha = 1,
-- Force UTF8? requires XFT ###
	override_utf8_locale = true,

	uppercase = false,
--########################  End Font Settings  ###
--##  Colour Settings  ###########################
	draw_shades = false,--yes
	default_shade_color = '#000000',

	draw_outline = false,-- amplifies text if yes
	default_outline_color = '#000000',

--default_color 656667 # Waldorf original colour
--default_color 7a7a7a # Flame  & Bunsen Grey
--default_color 929292 # Labs Grey
	default_color = '#C0C0C0',-- Silver
	color0 = '#B0E0E6',-- PowderBlue
	color1 = '#778899',-- LightSlateGray
	color2 = '#D8BFD8',-- Thistle
	color3 = '#9ACD32',-- YellowGreen
	color4 = '#FFA07A',-- LightSalmon
	color5 = '#FFDEAD',-- NavajoWhite
	color6 = '#00BFFF',-- DeepSkyBlue
	color7 = '#5F9EA0',-- CadetBlue
	color8 = '#BDB76B',-- DarkKhaki
	color9 = '#CD5C5C',-- IndianRed
--######################  End Colour Settings  ###
--##  Borders Section  ###########################
	draw_borders = false,
-- Stippled borders?
	stippled_borders = 5,
-- border margins
	border_inner_margin = 5,
	border_outer_margin = 0,
-- border width
	border_width = 2,
-- graph borders
	draw_graph_borders = true,--no
--default_graph_size 15 40
--######################  End Borders Section  ###
--##  Miscellaneous Section  #####################
-- Boolean value, if true, Conky will be forked to background when started.
	background = true,

-- Adds spaces around certain objects to stop them from moving other things
-- around, this only helps if you are using a mono font
-- Options: right, left or none
	use_spacer = 'none',

-- Default and Minimum size is 256 - needs more for single commands that
-- "call" a lot of text IE: bash scripts
	text_buffer_size = 6144,

-- Subtract (file system) buffers from used memory?
	no_buffers = true,

-- change GiB to G and MiB to M
	short_units = true,

-- Like it says, ot pads the decimals on % values
-- doesn't seem to work since v1.7.1
	pad_percents = 2,

-- Imlib2 image cache size, in bytes. Default 4MiB Increase this value if you use
-- $image lots. Set to 0 to disable the image cache.
	imlib_cache_size = 0,

-- Use the Xdbe extension? (eliminates flicker)
-- It is highly recommended to use own window with this one
-- so double buffer won't be so big.
	double_buffer = true,

--   Maximum size of user text buffer, i.e. layout below TEXT line in config file
--  (default is 16384 bytes)
-- max_user_text 16384

-- Desired output unit of all objects displaying a temperature. Parameters are
-- either "fahrenheit" or "celsius". The default unit is degree Celsius.
-- temperature_unit Fahrenheit

--################  End Miscellaneous Section  ###
--### ${font Monospace:bold:size=10}${alignc}${execpi 600 $HOME/.config/conky/scripts/bunsenweather.sh}
	update_interval = 1,

};

conky.text = [[
${color}${alignc}S Y S T E M    I N F O
${hr}
Host:${alignr}${nodename}
Uptime:${alignr}${uptime}
UTC:${alignr}${utime %H:%M}

${goto 60}Used${alignr}Size
Root${goto 60}${fs_used /}${alignr}${fs_size /}
Home${goto 60}${fs_used /home}${alignr}${fs_size /home}

${goto 60}MEM${alignr}MAX
RAM${goto 60}${mem}${alignr}${memmax}
Swap${goto 60}${swap}${alignr}${swapmax}

CPU:${goto 60}Used${alignr}GHz
Avg${goto 60}${if_match ${cpu cpu0}<10}  ${cpu cpu0}\
${else}${if_match ${cpu cpu0}<100} ${cpu cpu0}\
${else}${cpu cpu0}${endif}${endif}%${alignr}${freq_g}

${alignc}S H O R T C U T    K E Y S
${hr}
[Alt] + F2${alignr}Run Dialog
[Alt] + F3${alignr}Alt Menu
[S] + Space${alignr}Main Menu
[S] + Tab${alignr}Client Menu
[S] + t${alignr}Terminal
[S] + f${alignr}File Manager
[S] + e${alignr}Editor
[S] + m${alignr}Media Player
[S] + w${alignr}Web Browser
[S] + h${alignr}Task Manager
[S] + l${alignr}Lock Screen
[S] + v${alignr}Volume Control
[S] + x${alignr}Logout
[PrtSc]${alignr}Screenshot
]];

Note the conversions of some commented lines. For example:

# max_user_text 16384
# temperature_unit Fahrenheit

becomes

-- max_user_text 16384
-- temperature_unit Fahrenheit

If you subsequently uncomment the line without correcting the syntax, you will get an error. Make sure you edit lines like this to

-- max_user_text = 16384
-- temperature_unit = 'Fahrenheit'

Better still, use the default! wink :

-- temperature_unit = 'Celsius'

------------------------------------------------------------------------

We suspect that the official documentation hasn't been updated completely, and man conky has sections which seem to be the same in both versions, although they refer to settings or variables which have been changed.
So if there are NEW subtle changes, Be Advised: they may not be, probably are not, documented.  If you find some "undocumented feature" please share it, right here in this thread.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#2 2017-07-25 05:13:55

malm
jgmenu developer
Registered: 2016-10-13
Posts: 531
Website

Re: HowTo convert Conky v1.9 to v1.10 - using convert.lua

Great work. Very helpful.

Offline

Board footer

Powered by FluxBB