Skip to content

Commit

Permalink
refactor: extract conky script logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sstojkovic committed Nov 6, 2020
1 parent 7f5fa7a commit 081ea72
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 60 deletions.
60 changes: 2 additions & 58 deletions Light
Original file line number Diff line number Diff line change
@@ -1,60 +1,4 @@
require 'config';
require 'base';

conky.text = [[
${goto 90}${voffset 25}${font adele:size=25} ${time %A, %d %B}
${goto 90}${voffset -}${font LG Weather_Z:size=100}${time %H:%M}${image ./icons/white/line.png -p 354,23 -s 3x189}
${offset 370}${voffset -183}${font ADELE:size=22}
\
# --- Weather --- #
###################
\
# --- WOEID (Location id) --- #
${execi 300 ./scripts/weather.sh}\
\
# --- Temperature --- #
#######################
\
${font ADELE :size=30}${offset 375}${voffset 10}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp')}°${font ADELE :size=15}C${font ADELE :size=30}${voffset -20} |
\
# --- Weather icon --- #
########################
\
${execi 300 ./scripts/weather-icon.sh white $(cat ~/.cache/eleg-weather.json | jq -r '.weather[0].icon')}${image ~/.cache/eleg-weather-icon.png -p 410,8 -s 100x100}
\
# --- Textual condition (e.g. Partly cloudy) --- #
##################################################
\
${font Roboto Light:size=18}${offset 462}${voffset -82}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.weather[0].main'}
\
# --- Icon - high temperature --- #
###################################
\
${image ./icons/white/arrow-up.png -p 375,172 -s 12x12}
\
# --- High temperature --- #
############################
\
${font Roboto Light:size=12}${offset 395}${voffset -25}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_max')}°
\
# --- Icon - low temperature icon --- #
#######################################
\
${image ./icons/white/arrow-down.png -p 422,172 -s 12x12}
\
# --- Low temperature --- #
###########################
\
${font Roboto Light:size=12}${offset 438}${voffset -44}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_min')}°
\
# --- Icon - map marker --- #
#############################
\
${image ./icons/white/map-marker.png -p 463,168 -s 16x16}
\
# --- Location name (city) --- #
############################################
\
${font Roboto Light:size=12}${offset 485}${voffset -45}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.name'}

${goto 285}${voffset -35}${font adele:bold:size=25}${time %p}
]];
conky.text = load('light', '#FFFFFF');
75 changes: 75 additions & 0 deletions base.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
script = [[
${color #{color}}
${goto 90}${voffset 25}${font adele:size=25} ${time %A, %d %B}
\
# --- Separator line --- #
${goto 90}${voffset -}${font LG Weather_Z:size=100}${time %H:%M}${image ./icons/#{theme}/line.png -p 360,30 -s 3x189}
\
${offset 370}${voffset -183}${font ADELE:size=22}
\
# --- Weather --- #
###################
\
# --- WOEID (Location id) --- #
${execi 300 ./scripts/weather.sh}\
\
# --- Temperature --- #
#######################
\
${font ADELE :size=30}${offset 260}${voffset 10}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp')}°${font ADELE :size=15}C${font ADELE :size=30}${voffset -20} |
\
# --- Weather icon --- #
########################
\
${execi 300 ./scripts/weather-icon.sh #{theme} $(cat ~/.cache/eleg-weather.json | jq -r '.weather[0].icon')}${image ~/.cache/eleg-weather-icon.png -p 410,30 -s 100x100}
\
# --- Textual condition (e.g. Partly cloudy) --- #
##################################################
\
${font Roboto Light:size=18}${offset 380}${voffset -82}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.weather[0].main'}
\
# --- Icon - high temperature --- #
###################################
\
${image ./icons/#{theme}/arrow-up.png -p 375,190 -s 12x12}
\
# --- High temperature --- #
############################
\
${font Roboto Light:size=12}${offset 330}${voffset -25}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_max')}°
\
# --- Icon - low temperature icon --- #
#######################################
\
${image ./icons/#{theme}/arrow-down.png -p 422,190 -s 12x12}
\
# --- Low temperature --- #
###########################
\
${font Roboto Light:size=12}${offset 400}${voffset -44}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_min')}°
\
# --- Icon - map marker --- #
#############################
\
${image ./icons/#{theme}/map-marker.png -p 463,187 -s 16x16}
\
# --- Location name (city) --- #
############################################
\
${font Roboto Light:size=12}${offset 440}${voffset -45}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.name'}
${goto 285}${voffset -35}${font adele:bold:size=25}${time %p}
]];

local function interp (s, t)
return s:gsub('(#%b{})', function (w)
return t[w:sub(3, -2)] or w
end)
end

function load(theme, color)
return interp(script, {
theme = theme,
color = color
})
end
2 changes: 0 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
conky.config = {
alignment = 'top_middle',
background = false,
border_margin = 5,
border_width = 5,
cpu_avg_samples = 2,
default_color = '#ffffff',
Expand All @@ -14,7 +13,6 @@ conky.config = {
draw_shades = false,
gap_x = 0,
gap_y = 100,
max_specials = 1024,
max_user_text = 10000,
maximum_width = 900,
net_avg_samples = 2,
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 081ea72

Please sign in to comment.