Skip to content

Commit

Permalink
add luastatus widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
safocl committed Mar 12, 2017
1 parent 62c72aa commit 69c47b7
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .config/htop/htoprc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1
sort_key=1
sort_key=38
sort_direction=1
hide_threads=0
hide_kernel_threads=1
Expand Down
11 changes: 6 additions & 5 deletions .config/i3/config
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ bindsym $mod+Ctrl+c exec "urxvtc -e vim $HOME/.config/i3/config"



bindsym XF86AudioLowerVolume exec "amixer set Master 3Db->/dev/null"
bindsym XF86AudioRaiseVolume exec "amixer set Master 3Db+>/dev/null"
bindsym XF86AudioMute exec "pamixer -t;pamixer --get-volume > ~/.curr_vol"
#bindsym XF86AudioLowerVolume exec "amixer set Master 3Db->/dev/null"
#bindsym XF86AudioRaiseVolume exec "amixer set Master 3Db+>/dev/null"
bindsym XF86AudioMute exec "pamixer -t"
#;pamixer --get-volume > ~/.curr_vol"


#change volume with pactl
#bindsym XF86AudioLowerVolume exec "pamixer -d 5"
bindsym XF86AudioLowerVolume exec "pamixer -d 5"
#";pamixer --get-volume > ~/.curr_vol"
#bindsym XF86AudioRaiseVolume exec "pamixer -i 5"
bindsym XF86AudioRaiseVolume exec "pamixer -i 5"
#";pamixer --get-volume > ~/.curr_vol"
#bindsym XF86AudioMute exec "pamixer -t;pamixer --get-volume > ~/.curr_vol"

Expand Down
21 changes: 21 additions & 0 deletions .config/luastatus/alsa.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function pulse()
local pulse_vol = io.popen('pamixer --get-volume')
pulse_vol:setvbuf('no')
repeat
cur_vol = pulse_vol:read("*l")
until
nil == pulse_vol:read("*l")
pulse_vol:close()
return cur_vol
end

widget = {
plugin = 'alsa',
cb = function(t)
if t.mute then
return {full_text = '[mute]', color = '#e03838'}
else
return {full_text = pulse(), color = '#718ba6'}
end
end,
}
28 changes: 28 additions & 0 deletions .config/luastatus/mem-free.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
mem_uev = assert(io.open('/proc/meminfo', 'r'))
mem_uev:setvbuf('no')

function get_mem_seg()
local result = '[-?-]'
mem_uev:seek('set', 0)
for line in mem_uev:lines() do
local key, value, um = string.match(line, '(.*): +(.*) +(.*)')
if key == 'MemFree' then
value = tonumber(value)
if um == 'kB' then
value = value / 1024.0 / 1024.0
um = 'GiB'
end
result = string.format('[%3.2f %s]', value, um)
break
end
end
return {full_text = result, color = '#af8ec3'}
end

widget = {
plugin = 'timer',
opts = {period = 2},
cb = function(t)
return {get_mem_seg()}
end,
}
40 changes: 40 additions & 0 deletions .config/luastatus/time-battery.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
bat_uev = io.open('/sys/class/power_supply/BAT0/uevent', 'r')
if bat_uev then
bat_uev:setvbuf('no')
end

function get_bat_seg()
if not bat_uev then
return {full_text = '[-?-]'}
end
bat_uev:seek('set', 0) -- yes, seeking on sysfs files is OK
local status, capa
for line in bat_uev:lines() do
local key, value = string.match(line, '(.-)=(.*)')
if key == 'POWER_SUPPLY_STATUS' then
status = value
elseif key == 'POWER_SUPPLY_CAPACITY' then
capa = tonumber(value)
end
end
if status == 'Unknown' or status == 'Full' then
return nil
end
local sym, color = '?', '#dcdcdc'
if status == 'Discharging' then
sym = ''
color = '#dca3a3'
elseif status == 'Charging' then
sym = ''
color = '#60b48a'
end
return {full_text = string.format('[%3d%%%s]', capa, sym), color = color}
end

widget = {
plugin = 'timer',
opts = {period = 2},
cb = function(t)
return {{full_text = os.date('[%H:%M]'), color = '#dc8cc3'}, get_bat_seg()}
end,
}
32 changes: 32 additions & 0 deletions .config/luastatus/update-on-click.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- A Rube Goldberg machine widget that updates itself on click.

fifo_path = assert(os.getenv('HOME')) .. '/.luastatus-timer-fifo'

assert(0 == luastatus.rc{
'/bin/sh',
'-c',
'set -e; rm -f -- "$1"; mkfifo -m600 -- "$1"',
'', -- this is $0
fifo_path, -- and this is $1
})

widget = {
plugin = 'timer',
opts = {
fifo = fifo_path,
period = 2.0,
},
cb = function(t)
if t == 'fifo' then
return {full_text = 'Thanks!'}
else
return {full_text = 'Click me'}
end
end,
event = function(t)
-- opening the FIFO for writing here may, in some rare cases, block (and doing this from
-- this process would lead to a deadlock), so we spawn another process to do it and do not
-- wait for its termination (which would also lead to a deadlock).
luastatus.spawn{'touch', '--', fifo_path}
end,
}
12 changes: 12 additions & 0 deletions .config/luastatus/xkb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
widget = {
plugin = 'xkb',
cb = function(t)
if t.name == 'us' then
return {full_text = '[En]', color = '#9c9c9c'}
elseif t.name == 'ru(winkeys)' then
return {full_text = '[Ru]', color = '#eab93d'}
else
return {full_text = '[' .. t.id .. ']'}
end
end,
}
4 changes: 2 additions & 2 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
mkdir -p .config
cp -rv $HOME/.{bash_profile,bashrc,saf-scrypt,vimrc,Xresources,zprofile,zshrc} .
cp -rv $HOME/.config/{compton.conf,fontconfig,htop,i3} .config/
cp -v $HOME/.{bash_profile,bashrc,saf-scrypt,vimrc,Xresources,zprofile,zshrc} .
cp -rv $HOME/.config/{luastatus,compton.conf,fontconfig,htop,i3} .config/

0 comments on commit 69c47b7

Please sign in to comment.