PDA

View Full Version : [SOLVED] How to mark in conky in calender current day+centered?



vickoxy
February 10th, 2010, 01:59 AM
Hi,
i just want to have simple calender in my conky. I found here how to add it, but want to know is it possible to have marked current day and have calendar centered?
At the end there is line that marks current day but i can not get it centered.

http://solutionsandtips.blogspot.com/2009/03/how-to-add-calendar-in-conky-linux.html

Thanks

So, the line for calendar is

${font DejaVu Sans Mono :size=8}${exec cal -m | cut -c23-44 --complement}
The line for calendar with the current day marked is:
$
{execpi 60 DJS=`date +%_d`; cal | sed '1d' | sed '/./!d' | sed 's/$/ /' | fold -w 21 | sed -n '/^.\{21\}/p' | sed 's/^/ /' | sed /" $DJS "/s/" $DJS "/" "'${color #b7d1ea}'"$DJS"'${color}'" "/}

But if i try to add center the second line i get the calendar messed up.

vickoxy
February 10th, 2010, 08:40 PM
So this is my conky:


# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# fiddle with window
use_spacer yes


# Update interval in seconds
update_interval 1.0

# Minimum size of text area
minimum_size 186 0
maximum_width 220 0

# Draw shades?
draw_shades no

# Text stuff
draw_outline no # amplifies text if yes
draw_borders no
use_xft yes
xftfont Sans:size=8
xftalpha 0.8

uppercase no # set to yes if you want all text to be in uppercase

# Stippled borders?
stippled_borders 3



# Default colors and also border colors, grey90 == #e5e5e5
default_color ace770

own_window_colour black
own_window_transparent yes

# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
gap_x 10
gap_y 20


#${color blue}FORTUNE ${hr 2}$color
#${execi 120 fortune -s | fold -w50}


#${color blue}LOGGING ${hr 2}$color
#${execi 30 tail -n3 /var/log/messages | fold -w50}



# stuff after 'TEXT' will be formatted on screen

TEXT
${font Sans:size=26}${alignc}${time %H:%M:%S}${font}
${alignc}${time %A, %d.%m.%Y}
$color
${color #5397d6}SYSTEM ${hr 2}$color
${voffset 4}UpTime: ${alignr}${color }$uptime
${voffset 2}Kern: ${alignr}$kernel
${voffset 2}CPU: ${cpu}% ${alignr 1}${cpubar 6,80}
${cpugraph 000000 ffffff}
Intel Atom N270 ${alignr} ${alignr}${freq}MHz ${acpitemp}C
${voffset 2}RAM: $memperc% ${alignc} $mem${alignr 7} ${membar 6,80}
${voffset 2}${alignc -44}CPU% ${alignr}MEM%
${voffset 2}${top_mem name 1}${alignr}${top_mem cpu 1} ${top_mem mem 1}
${voffset 2}${top_mem name 2}${alignr}${top_mem cpu 2} ${top_mem mem 2}
${voffset 2}${top_mem name 3}${alignr}${top_mem cpu 3} ${top_mem mem 3}
${voffset 2}${top_mem name 4}${alignr}${top_mem cpu 4} ${top_mem mem 4}
${voffset 6}${color #5397d6}STORAGE ${hr 2}$color
${voffset 2}HD: ${voffset 0}${fs_free /home}/${fs_size /home} ${alignr 1}${fs_bar 6,50 /home}
${if_mounted /media/DATA}${voffset 2}SD/USB: ${voffset 0}${fs_free /media/DATA}/${fs_size /media/DATA} ${alignr}${fs_bar 6,50 /media/DATA}${endif}
${color #5397d6}NETWORK ${hr 2}$color
${voffset 2}Upload: ${alignr}${upspeedf eth2} KB/s
${voffset 2}Download: ${alignr}${downspeedf eth2} KB/s

and this is also on simple line, but can not adjust it:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'}

mobilediesel
February 10th, 2010, 09:55 PM
So this is my conky:

and this is also on simple line, but can not adjust it:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'}

add |sed 's/^/${alignc}/' to the end like this:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's /^/${alignc}/'}

Bruce M.
February 10th, 2010, 09:58 PM
Hi vickoxy

Rather than look at yours, because I'm sure if you use an ${alignc} on it only the top half gets centred, here is one that does what you want and more:


${font DejaVu Sans Mono:bold:size=9}${execpi 3600 $HOME/Conky/scripts/conkycal.sh -l es|sed 's/^/\${goto 105}/'}${font}


today is a different colour
it is available in various languages.
you can cetnre it with a ${goto} or ${alignc} I use a goto it os much more accurate.
this calendar "always" displays 31 days: Feb ends at 28, the first three days of March are there in a different colour. GREAT for spacing.


I left the font call there as a MONO font is important for this calendar to be displayed correctly (any mono font)

Two things to look at in that line:

Language:

conkycal.sh -l es|sed 's/^/\${goto 105}/'}
and the "spacing" you asked about.

conkycal.sh <<-- make this one executable.

#!/bin/bash
cd $(dirname $0)
# horizontal and vertical calendar for conky by ans
# Updated by: mobilediesel, dk75, Bruce, Crinos512, et al.
# locale depend week day names
DOW=("Mo" "Tu" "We" "Th" "Fr" "Sa" "Su")
while getopts ":vl:" opts; do
case "$opts" in
l) lang=$OPTARG;;
v) orientation="$opts";;
esac
done
if [ -f lang ]; then
. lang
fi
COLOROLD="445566" #MidSlateGrey
COLORTODAY="FF8C00" #Darkorange
COLORREST="445566" #MidSlateGrey
COLORNEXT="778899" #LightSlateGrey
COLORSATURDAY="FFFF00"
COLORSUNDAY="FF8C00"
COLOR=("" "" "" "" "" "\${color $COLORSATURDAY}" "\${color $COLORSUNDAY}")
COLOREND=("" "" "" "" "" "" "\${color}")

TODAY=$(date +%-d)
LASTDAY=$(date -d "-$TODAY days +1 month" +%d)
FIRSTDAY=$(date -d "-$[$TODAY-1] days" +%u)

# horizontal function
h () {
# Build $TOPLINE
k=$FIRSTDAY
for j in {1..31}; do
x=$[j+LASTDAY/j]
case $j in
${j/#$x}) TOPLINE="$TOPLINE ${COLOR[$[k-1]]}${DOW[$[k-1]]}${COLOREND[$[k-1]]}";;
$[LASTDAY+1]) TOPLINE="$TOPLINE \${color $COLORNEXT}${DOW[$[k-1]]}";;
*) TOPLINE="$TOPLINE ${DOW[$[k-1]]}";;
esac
k=$[${k/#7/0}+1]
done

BOTTOM="\${color $COLOROLD}$(seq -w -s ' ' $LASTDAY|sed "0,/[0-3]*$TODAY \?/s//\${color $COLORTODAY}&\${color $COLORREST}/") \${color $COLORNEXT}$(seq -w -s ' ' 0$[31-$LASTDAY])"

echo "${TOPLINE/# /}"
echo "$BOTTOM\${color}"
}

#vertical function
v () {
for i in $(seq 1 $[TODAY-1]); do
TODAYC[$i]="\${color $COLOROLD}"
done
TODAYC[$TODAY]="\${color $COLORTODAY}"
for i in $(seq $[TODAY+1] $LASTDAY); do
TODAYC[$i]="\${color $COLORREST}"
done

k=$FIRSTDAY
for j in $(seq $LASTDAY); do
echo "${COLOR[$[k-1]]}${DOW[$[k-1]]} ${TODAYC[$j]}$(printf "%02d" $j)\${color}"
k=$[${k/#7/0}+1]
done
}

# call function based on "$orientation"
${orientation:-h}

and in the same directory as that script the language file called: lang

case ${lang:-$LANG} in
af* ) DOW=("Ma" "Di" "Wo" "Do" "Vr" "Sa" "So");; # Afrikaans (Afrikaans)
be* ) DOW=("Па" "Аў" "Се" "Ча" "Пя" "Су" "Ня");; # Belarusian (Беларуская)
bs* ) DOW=("Po" "Ut" "Sr" "Če" "Pe" "Su" "Ne");; # Bosnian (Bosanac)
bg* ) DOW=("По" "Вт" "Ср" "Че" "Пе" "Съ" "Не");; # Bulgarian (Български)
zh* ) DOW=("周一" "周二" "周三" "周四" "周五" "周六" "周天");; # Chinese (中文)
hr* ) DOW=("Po" "Ut" "Ut" "Sr" "Če" "Su" "Ne");; # Croatian (Hrvatska)
cs* ) DOW=("Po" "t" "St" "Čt" "P" "So" "Ne");; # Czech (Četina)
da* ) DOW=("Ma" "Ti" "On" "To" "Fr" "L" "S");; # Danish (Dntina)
nl* ) DOW=("Ma" "Di" "Wo" "Do" "Vr" "Za" "Zo");; # Dutch (Nederlandse)
de* ) DOW=("Mo" "Di" "Mi" "Do" "Fr" "Sa" "So");; # German (Deutche)
el* ) DOW=("Δε" "Τρ" "Τε" "Πέ" "Πα" "Σά" "Κυ");; # Greek (Ελληνικά)
et* ) DOW=("Es" "Te" "Ko" "Ne" "Re" "La" "P");; # Estonian (Eesti)
tl* ) DOW=("Lu" "Ma" "Mi" "Hu" "Bi" "Sa" "Li");; # Filipino (Filipino)
fi* ) DOW=("Ma" "Ti" "Ke" "To" "Pe" "La" "Su");; # Finnish (Suomen)
fr* ) DOW=("Lu" "Ma" "Me" "Je" "Ve" "Sa" "Di");; # French (Franais)
gl* ) DOW=("Lu" "Ma" "M" "Xo" "Ve" "S" "Do");; # Galician (Galego)
hi* ) DOW=("सोम" "मंगल" "बुध" "गुरु" "शुक्र" "शनि" "सूर्य") ;; # Hindi (हिन्दी)
hu* ) DOW=("H" "Ke" "Se" "C" "P" "So" "Va");; # Hungarian (Magyar)
is* ) DOW=("M" "r" "Mi" "Fi" "F" "La" "Su");; # Icelandic (slenska)
id* ) DOW=("Se" "Se" "Ra" "Ka" "Ju" "Sa" "Mi");; # Indonesian (Indonesia)
it* ) DOW=("Lu" "Ma" "Me" "Gi" "Ve" "Sa" "Do");; # Italian (Italiano)
ja* ) DOW=("月曜" "火曜" "水曜" "木曜" "金曜" "土曜" "日曜");; # Japanese (日本語) x
ko* ) DOW=("월요" "화요" "수요" "목요" "금요" "토요" "일요");; # Korean (한국어) x
lv* ) DOW=("Pr" "Ot" "Tr" "Ce" "Pe" "Se" "Sv");; # Latvian (Latvieu)
lt* ) DOW=("pi" "an" "tr" "ke" "pe" "e" "se");; # Lithuanian (Lietuvikai)
mk* ) DOW=("По" "Вт" "Ср" "Че" "Пе" "Са" "Не");; # Macedonian (Македонски)
ml* ) DOW=("Is" "Se" "Ra" "Ra" "Ju" "Sa" "Mi");; # Malayam (Bahasa Melayu)
nb* ) DOW=("ma" "ti" "on" "to" "fr" "l" "s");; # Norwegian (Norsk)
pl* ) DOW=("Po" "Wt" "Śr" "Cz" "Pt" "So" "Nd");; # Polish (Polska)
pt* ) DOW=("Sq" "Te" "Qa" "Qi" "Se" "S" "Do");; # Portuguese (Portugus)
ro* ) DOW=("Lu" "Ma" "Mi" "Jo" "Vi" "Sa" "Du");; # Romanian (Romn)
ru* ) DOW=("По" "Вт" "Ср" "Че" "Пя" "Су" "Во");; # Russian (Русский)
sr* ) DOW=("Po" "Ut" "Sr" "Če" "Pe" "Su" "Ne");; # Serbian (Српски)
sk* ) DOW=("Po" "Ut" "St" "t" "Pi" "So" "Ne");; # Slovak (Slovenčina)
sl* ) DOW=("Po" "To" "Sr" "Če" "Pe" "So" "Ne");; # Slovenian (Slovenski)
es* ) DOW=("Lu" "Ma" "Mi" "Ju" "Vi" "S" "Do");; # Spanish (Espaol)
sv* ) DOW=("M" "Ti" "On" "To" "Fr" "L" "S");; # Swedish (Svenska)
tr* ) DOW=("Pa" "Sa" "a" "Pe" "Cu" "Cu" "Pa");; # Turkish (Trke)
uk* ) DOW=("По" "Ві" "Се" "Че" "Пя" "Су" "Не");; # Ukrainian (Українська)
* ) DOW=("Mo" "Tu" "We" "Th" "Fr" "Sa" "Su") ;;
esac

Hope that helps.
Bruce

Bruce M.
February 10th, 2010, 10:03 PM
add |sed 's/^/${center}/' to the end like this:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's /^/${center}/'}

HEY there buddy, you beat me to the punch, but missed one part of his two part quest.

He wanted the day marked differently AND centred. No problem though, I did give him "# Updated by: mobilediesel, dk75, Bruce, Crinos512, et al." so you're still in the game.

CHIMO!
Bruce

vickoxy
February 10th, 2010, 10:22 PM
add |sed 's/^/${alignc}/' to the end like this:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's /^/${alignc}/'}

Unfortunately, this code gives me nothing-as something is missing.. i prefer such a simple solution...

vickoxy
February 10th, 2010, 10:28 PM
HEY there buddy, you beat me to the punch, but missed one part of his two part quest.

He wanted the day marked differently AND centred. No problem though, I did give him "# Updated by: mobilediesel, dk75, Bruce, Crinos512, et al." so you're still in the game.

CHIMO!
Bruce

No- i meant only that calender is centered in conky column-not the day-i just wan simple calender, only wit current day marked.

I made conkycal.sh script in my /home/ directory, made it executable. I made also one lang file in /home/-but got only few letters:

this is the line:

${font DejaVu Sans Mono:bold:size=9}${execpi 3600 $HOME/conkycal.sh -l es|sed 's/^/\${goto 105}/'}${font}

mobilediesel
February 10th, 2010, 10:31 PM
HEY there buddy, you beat me to the punch, but missed one part of his two part quest.

He wanted the day marked differently AND centred. No problem though, I did give him "# Updated by: mobilediesel, dk75, Bruce, Crinos512, et al." so you're still in the game.

CHIMO!
Bruce

This can also work:

#!/bin/bash
################################################## ##########
# This work is licensed under the Creative Commons #
# Attribution-Share Alike 3.0 Unported License. #
# To view a copy of this license, visit #
# http://creativecommons.org/licenses/by-sa/3.0/ #
# or send a letter to Creative Commons, 171 Second Street, #
# Suite 300, San Francisco, California, 94105, USA. #
################################################## ##########

date=$(date '+%F')
DAY=${date:8:2}
# m="-m" # uncomment this line for starting the week on Monday instead of Sunday.
cal=$(cal $m)
prev=$(cal $m $(date '+%-m %Y' --date="${date:0:7}-15 -1 month")|sed 's/ *$//;/^$/d'|tail -1)
next=$(cal $m $(date '+%-m %Y' --date="${date:0:7}-15 +1 month")|sed '/^ *&/d;1,2d;s/^ *//'|head -1)
if [ ${#next} == 19 ] ;then next=$'\n'"\${color blue} $next"
else next="\${color blue} $next"
fi
if [ ${#prev} == 20 ]; then prev="$prev"$'\n '
else prev="$prev "
fi
current=$(echo "${cal:42}"|sed -e '/^ *$/d' -e 's/^/ /' -e 's/$/ /' -e 's/^ *1 / 1 /' )
current=$(echo "$current"|sed -e /" ${DAY/#0/} "/s/" ${DAY/#0/} "/" "'${color white}'"${DAY/#0/}"'${color}'" "/ -e 's/^ //' -e 's/ *$//')
echo -e "\${color}${cal:0:21}${cal:21:21}\${color blue}$prev\${color}$current$next"
so you get the last days of last month and the first days of next month:

February 2010
Su Mo Tu We Th Fr Sa
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 1 2 3 4 5 6
The current day color is white but I made it grey in the code output above since the background is white.

If you want even MORE complicated, I can post the one where the holidays and birthdays are highlighted! :D

mobilediesel
February 10th, 2010, 10:34 PM
Unfortunately, this code gives me nothing-as something is missing.. i prefer such a simple solution...

There was an extra space near the end, my fault!

Try this one:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${alignc}/'}

vickoxy
February 10th, 2010, 11:21 PM
There was an extra space near the end, my fault!

Try this one:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${alignc}/'}

Thanks-that almost did it-but the calender is centered and little bit messed up-is it possible to add right alingment and then to add some offset to make it nice looking?

vickoxy
February 10th, 2010, 11:59 PM
Found solution-Bruce said to use Mono:popcorn:
Thanks mobilediesel for code :popcorn:- i just added offset instead of alignment:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${offset 35}/'}

So, the output is just fine for me.

vickoxy
February 11th, 2010, 12:05 AM
Ha-at 00:00 conky is dead-obviously, the line with calender does something to conky to crash down-i deleted the line

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${offset 35}/'}
and everything is normal again.
If i bring it back, conky crashes.

?!?:-k:-k:-k

mobilediesel
February 11th, 2010, 01:25 AM
Ha-at 00:00 conky is dead-obviously, the line with calender does something to conky to crash down-i deleted the line

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${offset 35}/'}
and everything is normal again.
If i bring it back, conky crashes.

?!?:-k:-k:-k

If you're more interested in keeping fairly simple, try this:

${execpi 300 cal |sed -e "s/\<$(date +%-d)\>/\${color e84448}&\${color}/" -e 's/^/${offset 35}/'}

obviously don't forget the mono-spaced font before the code. :D

vickoxy
February 11th, 2010, 01:37 AM
If you're more interested in keeping fairly simple, try this:

${execpi 300 cal |sed -e "s/\<$(date +%-d)\>/\${color e84448}&\${color}/" -e 's/^/${offset 35}/'}

obviously don't forget the mono-spaced font before the code. :D

Unfortunately-these yours codes are killing my conky-if i add those lines, it can not start any more.

Compare to these one:

${execpi 60 DJS=`date +%_d`; cal | sed '1d' | sed '/./!d' | sed 's/$/ /' | fold -w 21 | sed -n '/^.\{21\}/p' | sed 's/^/ /' | sed /" $DJS "/s/" $DJS "/" "'${color #b7d1ea}'"$DJS"'${color}'" "/}

This is showing everything ok, but i can not achieve offset, and there is no month and year displayed as it is by your lines...

vickoxy
February 11th, 2010, 01:47 AM
I found these simple line:
${execpi 60 DJS=`date +%_d`; cal | sed s/"$DJS"'\b'/'${color orange}'"$DJS"'$color'/}
it works, but i do not know how to put it in the center/offset?

vickoxy
February 11th, 2010, 02:20 AM
Mobilediesel, this is your line whitout offset-it is working, but i do not know how to achieve that centering:

${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^//'}

vickoxy
February 11th, 2010, 02:22 AM
ok-i think i did it with this line:


${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${alignc}/'}

Thanks :popcorn:

mobilediesel
February 11th, 2010, 02:56 AM
ok-i think i did it with this line:


${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'|sed 's/^/${alignc}/'}

Thanks :popcorn:

Hopefully that works without killing conky again. I've found that sometimes just changing the conkyrc file can crash conky. It seems to be random though.