1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2025-07-01 19:49:25 +00:00

First commit

This commit is contained in:
2019-07-18 18:45:46 +02:00
commit 9f98ffc84d
14 changed files with 962 additions and 0 deletions

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
while true; do
UPDATES=$(checkupdates 2>/dev/null | wc -l)
[[ $UPDATES -gt 0 ]] && echo " $UPDATES" && sleep 30
[[ $UPDATES -eq 0 ]] && echo "" && sleep 300
done

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
OUTPUT=""
openvpn=$(pgrep -c openvpn$)
[[ $openvpn -gt 0 ]] && OUTPUT=$(eval printf "%.0s" {1..$openvpn})
openfortivpn=$(pgrep -c openfortivpn$)
[[ $openfortivpn -gt 0 ]] && OUTPUT=${OUTPUT}$(eval printf '%.0s' {1..$openfortivpn})
echo $OUTPUT | sed -e 's/\(.\)/\1 /g'

View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
import os
import subprocess
colors = {
'us': '#43A047', # us, user : time running un-niced user processes
'sy': '#87CEFA', # sy, system : time running kernel processes
'ni': '#FFFFFF', # ni, nice : time running niced user processes
'wa': '#E53935', # wa, IO-wait : time waiting for I/O completion
'hi': '#66CDAA', # hi : time spent servicing hardware interrupts
'si': '#7FFFD4', # si : time spent servicing software interrupts
'st': '#7B2B4E', # st : time stolen from this vm by the hypervisor
'id': '#555555'
}
def show_cpu_usage():
new_env = dict(os.environ)
new_env['LANG'] = 'en_US.UTF-8' # ensure that the decimal separator is a point
top = subprocess.run(["top", "-bn1"], capture_output=True, env=new_env)
raw_cpu_usages = top.stdout.decode("utf-8").split('\n')[2]
cpu_usage = str.replace(raw_cpu_usages, '%Cpu(s):', '')
bar = ''
global_count = 0
for usage in cpu_usage.split(','):
value, key = str.lstrip(usage).split(' ')
count = round(float(value) / 10)
if count > 0 and key != 'id':
global_count += count
bar += '%{F' + colors[key] + '}' + '_' * count + '%{F-}'
padding = ''
if global_count < 10:
padding = '%{F' + colors['id'] + '}' + '_' * (10 - global_count) + '%{F-}'
print("%{A1:$TERMINAL_CMD 'top -o %CPU' &:}%{T5}" + bar + padding + "%{T-}%{A-}")
if __name__ == "__main__":
show_cpu_usage()

View File

@ -0,0 +1,77 @@
#!/usr/bin/env bash
#
# nmcli connection switching from a rofi menu.
# When a network is selected its status is switched from UP to DOWN or vice versa.
#
# WARNING, connection name can't contain a # or | symbol
#
ROFI="rofi -dmenu
-sep #
-i -p Network:
-theme orange
-location 3
-yoffset +45
-xoffset -80
-width 30
"
function build_rofi_menu()
{
local menu
local name
local dtype
local device
local option
while read -r line
do
name="$(cut -d':' -f1 <<< $line)"
dtype="$(cut -d':' -f2 <<< $line)"
device="$(cut -d':' -f3 <<< $line)"
[[ -z $device ]] && status=DOWN || status=UP
dtype=${dtype##*-}
option="$name $dtype is $status"
option=$(printf '%-45s | %s | %s\n' "$name" $dtype $status)
menu="$menu # $option"
done < <(nmcli -c no --terse -f NAME,TYPE,DEVICE connection show)
echo "$(cut -c 3- <<< $menu)"
}
function switch_connections()
{
local name="$1"
local status=$2
if [[ "$status" == "UP" ]]; then
nmcli connection down "$name"
else
nmcli connection up "$name"
fi
}
function main()
{
local menu
local choice
local name
local stat
menu=$(build_rofi_menu)
choice=$($ROFI <<< $menu)
[[ $? -ne 0 ]] && return 1
name=$(cut -d '|' -f 1 <<< $choice | awk '{$1=$1;print}')
stat=$(cut -d '|' -f 3 <<< $choice | awk '{$1=$1;print}')
switch_connections "$name" $stat
}
main

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import dbus
bus_name = 'org.mpris.MediaPlayer2.spotify'
def get_spotify_song():
output = ''
try:
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object(bus_name, '/org/mpris/MediaPlayer2')
spotify_properties = dbus.Interface(spotify_bus, 'org.freedesktop.DBus.Properties')
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player", "Metadata")
artist = metadata['xesam:artist'][0]
title = metadata['xesam:title']
window_title = artist + ' - ' + title
output = "%{A1:$WM_CONTROL '" + window_title + "' &:}" + window_title + "%{A-}"
except dbus.DBusException as e:
if (e.get_dbus_message() == f'The name {bus_name} was not provided by any .service files'):
pass
else:
output = e.get_dbus_message()
except Exception as e:
output = str(e)
print(output)
if __name__ == "__main__":
get_spotify_song()