diff --git a/ChangeLog b/ChangeLog index 4b277c27..7bae0f49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-03-07 + * Added alias patch ( sf.net id #2663691 ) changed it to prevent it from + overwriting existing environment variables and updated docs, syntaxfiles, ... + 2009-03-01 * Added if_updatenr * Rewrite human_readable() to minimise amount of padding diff --git a/README b/README index 000883e5..20902bbe 100644 --- a/README +++ b/README @@ -155,6 +155,16 @@ conky(1) conky(1) You might want to copy it to $HOME/.conkyrc and then start modifying it. Other configs can be found at http://conky.sf.net/ + 1malias0m + Use this to create aliases of variables. The first argument is + the new name, the second the old name, and the other arguments + are passed on to the variable. Example: If you want to use $alpha + instead of ${beta gamma delta} then you have to write the following: + alias alpha beta gamma delta . PS: Instead of creating an alias + in the config you can also use environment variables. Example: + Start conky like this: alpha="beta gamma delta" conky + + 1malignment0m Aligned position on screen, may be top_left, top_right, top_mid‐ dle, bottom_left, bottom_right, bottom_middle, middle_left, mid‐ diff --git a/doc/config_settings.xml b/doc/config_settings.xml index 2e58c4c7..dfde685d 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -1,4 +1,11 @@ + + + + Use this to create aliases of variables. The first argument is the new name, the second the old name, and the other arguments are passed on to the variable. Example: If you want to use $alpha instead of ${beta gamma delta} then you have to write the following: alias alpha beta gamma delta . PS: Instead of creating an alias in the config you can also use environment variables. Example: Start conky like this: alpha="beta gamma delta" conky + + + diff --git a/doc/conky.1 b/doc/conky.1 index eda59a0b..839b9a9e 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -145,6 +145,10 @@ and you can find the sample config file there (/etc/conky/conky.conf). .PP You might want to copy it to $HOME/.conkyrc and then start modifying it. Other configs can be found at http://conky.sf.net/ +.TP +\fB\*(T<\fBalias\fR\*(T>\fR +Use this to create aliases of variables. The first argument is the new name, the second the old name, and the other arguments are passed on to the variable. Example: If you want to use $alpha instead of ${beta gamma delta} then you have to write the following: alias alpha beta gamma delta . PS: Instead of creating an alias in the config you can also use environment variables. Example: Start conky like this: alpha="beta gamma delta" conky + .TP \fB\*(T<\fBalignment\fR\*(T>\fR Aligned position on screen, may be top_left, top_right, top_middle, bottom_left, bottom_right, bottom_middle, middle_left, middle_right, or none (also can be abreviated as tl, tr, tm, bl, br, bm, ml, mr) diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 41834c7c..4fb9e78b 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -5,7 +5,7 @@ syntax "conky" "(\.*conkyrc.*$|conky.conf)" ## Configuration items -color green "\<(alignment|background|show_graph_range|show_graph_scale|border_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|default_color|default_shade_color|default_shadecolor|default_outline_color|default_outlinecolor|imap|pop3|mpd_host|mpd_port|mpd_password|music_player_interval|sensor_device|cpu_avg_samples|net_avg_samples|double_buffer|override_utf8_locale|draw_borders|draw_graph_borders|draw_shades|draw_outline|out_to_console|out_to_stderr|out_to_x|overwrite_file|append_file|use_spacer|use_xft|font|xftalpha|xftfont|use_xft|gap_x|gap_y|mail_spool|minimum_size|maximum_width|no_buffers|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|top_cpu_separate|short_units|pad_percents|own_window|own_window_class|own_window_title|own_window_transparent|own_window_colour|own_window_hints|own_window_type|stippled_borders|temp1|temp2|update_interval|total_run_times|uppercase|max_specials|max_user_text|text_buffer_size|max_port_monitor_connections)\>" +color green "\<(alias|alignment|background|show_graph_range|show_graph_scale|border_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|default_color|default_shade_color|default_shadecolor|default_outline_color|default_outlinecolor|imap|pop3|mpd_host|mpd_port|mpd_password|music_player_interval|sensor_device|cpu_avg_samples|net_avg_samples|double_buffer|override_utf8_locale|draw_borders|draw_graph_borders|draw_shades|draw_outline|out_to_console|out_to_stderr|out_to_x|overwrite_file|append_file|use_spacer|use_xft|font|xftalpha|xftfont|use_xft|gap_x|gap_y|mail_spool|minimum_size|maximum_width|no_buffers|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|top_cpu_separate|short_units|pad_percents|own_window|own_window_class|own_window_title|own_window_transparent|own_window_colour|own_window_hints|own_window_type|stippled_borders|temp1|temp2|update_interval|total_run_times|uppercase|max_specials|max_user_text|text_buffer_size|max_port_monitor_connections)\>" ## Configuration item constants color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index a314bf96..e7446366 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -13,6 +13,7 @@ endif syn region ConkyrcComment start=/^\s*#/ end=/$/ syn keyword ConkyrcSetting + \ alias \ alignment \ background \ show_graph_scale diff --git a/src/conky.c b/src/conky.c index 21328cc6..33544f2f 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2795,39 +2795,40 @@ static int extract_variable_text_internal(struct text_object *retval, const char s = p; var = getenv(buf); + if (var) { + strncpy(buf, var, 255); + } - /* if variable wasn't found in environment, use some special */ - if (!var) { - char *tmp_p; - char *arg = 0; + char *tmp_p; + char *arg = 0; - /* split arg */ - if (strchr(buf, ' ')) { - arg = strchr(buf, ' '); - *arg = '\0'; + /* split arg */ + if (strchr(buf, ' ')) { + arg = strchr(buf, ' '); + *arg = '\0'; + arg++; + while (isspace((int) *arg)) { arg++; - while (isspace((int) *arg)) { - arg++; - } - if (!*arg) { - arg = 0; - } } - - /* lowercase variable name */ - tmp_p = buf; - while (*tmp_p) { - *tmp_p = tolower(*tmp_p); - tmp_p++; - } - - obj = construct_text_object(buf, arg, - line, allow_threaded, - &ifblock_opaque); - if (obj != NULL) { - append_object(retval, obj); + if (!*arg) { + arg = 0; } } + + /* lowercase variable name */ + tmp_p = buf; + while (*tmp_p) { + *tmp_p = tolower(*tmp_p); + tmp_p++; + } + + obj = construct_text_object(buf, arg, + line, allow_threaded, + &ifblock_opaque); + if (obj != NULL) { + append_object(retval, obj); + } + continue; } else { obj = create_plain_text("$"); @@ -7230,6 +7231,25 @@ static void load_config_file(const char *f) } } + CONF("alias") { + if (value) { + char *skey, *svalue, *oldvalue; + if (sscanf(value, "%a[0-9a-zA-Z_] %a[^\n]", &skey, &svalue) == 2) { + oldvalue = getenv(skey); + if(oldvalue == NULL) { + setenv(skey, svalue, 0); + free(skey); + free(svalue); + } + //PS: Don't free oldvalue, it's the real envvar, not a copy + } else { + CONF_ERR; + } + } else { + CONF_ERR; + } + } + else { ERR("%s: %d: no such configuration: '%s'", f, line, name); }