Initial commit with fish, i3, nvim and polybar configuration
This commit is contained in:
42
.config/polybar/scripts/ibus_select.py
Executable file
42
.config/polybar/scripts/ibus_select.py
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import subprocess
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
IbusEngine = namedtuple('IbusEngine', ('code', 'name'))
|
||||
|
||||
|
||||
# ---------- BEGINNING OF SCRIPT ----------
|
||||
|
||||
# Get available engines
|
||||
list_engines_command = ['ibus', 'list-engine']
|
||||
list_engines_result = subprocess.run(list_engines_command, stdout=subprocess.PIPE)
|
||||
list_engines_output = list_engines_result.stdout.decode('utf-8')
|
||||
engines = [IbusEngine(*[l.strip() for l in line.split(' - ')])
|
||||
for line in list_engines_output.split('\n') if line and not line.startswith('language:')]
|
||||
|
||||
# Use rofi to ask the user which ibus engine to use
|
||||
ROFI_IBUS_PROMPT = "layout: "
|
||||
rofi_command = ['rofi', '-dmenu', '-i', '-format', 'i', '-p', ROFI_IBUS_PROMPT]
|
||||
|
||||
input_str = '\n'.join([engine.name for engine in engines])
|
||||
|
||||
rofi_result = subprocess.run(rofi_command, input=input_str, stdout=subprocess.PIPE, encoding='utf-8')
|
||||
|
||||
if rofi_result.returncode != 0:
|
||||
exit(rofi_result.returncode)
|
||||
|
||||
rofi_output = rofi_result.stdout.split(":")
|
||||
index = int(rofi_output[0])
|
||||
|
||||
if index < 0:
|
||||
exit(-1)
|
||||
|
||||
change_layout_command = ['ibus', 'engine', engines[index].code]
|
||||
change_layout_result = subprocess.run(change_layout_command)
|
||||
|
||||
if change_layout_result.returncode != 0:
|
||||
subprocess.run(['notify-send', '"{}"'.format(change_layout_result.stdout)])
|
||||
|
||||
exit(change_layout_result.returncode)
|
||||
41
.config/polybar/scripts/spotify.sh
Executable file
41
.config/polybar/scripts/spotify.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
main() {
|
||||
if ! pgrep -x spotify >/dev/null; then
|
||||
echo ""
|
||||
exit
|
||||
fi
|
||||
|
||||
cmd="org.freedesktop.DBus.Properties.Get"
|
||||
domain="org.mpris.MediaPlayer2"
|
||||
path="/org/mpris/MediaPlayer2"
|
||||
|
||||
meta=$(dbus-send --print-reply --dest=${domain}.spotify \
|
||||
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:${domain}.Player string:Metadata)
|
||||
|
||||
ttype=$(echo "$meta" | sed -nr '/mpris:trackid"/,+2s/^ +variant +string "[^:]*:(.*):.*"$/\1/p')
|
||||
|
||||
if [ "$ttype" = "ad" ]; then
|
||||
if [ $(pactl list sinks | sed -n 's/.*Mute:\s*//p' | tail -n 1) = "no" ]; then
|
||||
echo "TRUE" > /tmp/spotify_mute
|
||||
pactl set-sink-mute @DEFAULT_SINK@ 1
|
||||
echo "MUTING AN AD ;)"
|
||||
fi
|
||||
else
|
||||
if [ -f "/tmp/spotify_mute" ] ; then
|
||||
if [ $(cat /tmp/spotify_mute) = "TRUE" ]; then
|
||||
echo "FALSE" > /tmp/spotify_mute
|
||||
pactl set-sink-mute @DEFAULT_SINK@ 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Normal track
|
||||
artist=$(echo "$meta" | sed -nr '/xesam:artist"/,+2s/^ +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g' | sed 's#\/#\\/#g')
|
||||
album=$(echo "$meta" | sed -nr '/xesam:album"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1| sed 's/\&/\\&/g'| sed 's#\/#\\/#g')
|
||||
title=$(echo "$meta" | sed -nr '/xesam:title"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g'| sed 's#\/#\\/#g')
|
||||
|
||||
echo "${*:-%artist% - %title%}" | sed "s/%artist%/$artist/g;s/%title%/$title/g;s/%album%/$album/g"i | sed "s/\&/\&/g" | sed "s#\/#\/#g"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
114
.config/polybar/scripts/wifi_connect.py
Executable file
114
.config/polybar/scripts/wifi_connect.py
Executable file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import subprocess
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
APListItem = namedtuple('APListItem', ('active', 'ssid', 'mode', 'channel', 'rate', 'signal', 'bars', 'security'))
|
||||
ConListItem = namedtuple('ConListItem', ('name', 'uuid', 'type', 'device'))
|
||||
|
||||
# ---------- ACTIONS ----------
|
||||
Action = namedtuple('Action', ('action', 'item'))
|
||||
|
||||
# Action types
|
||||
ACT_CONNECT_WLAN = 'connect_wlan'
|
||||
ACT_DISCONNECT_WLAN = 'disconnect_wlan'
|
||||
ACT_CONNECT_VPN = 'connect_vpn'
|
||||
ACT_DISCONNECT_VPN = 'disconnect_vpn'
|
||||
|
||||
|
||||
WLAN_ITEM_FORMAT = '{bars} ({signal:>3}%) -- {ssid} ({rate})'
|
||||
VPN_ITEM_FORMAT = 'VPN -- {name}'
|
||||
|
||||
|
||||
def format_action(action):
|
||||
item = action.item
|
||||
if action.action == ACT_CONNECT_VPN:
|
||||
return '[con] ' + VPN_ITEM_FORMAT.format(name=item.name)
|
||||
if action.action == ACT_CONNECT_WLAN:
|
||||
return '[con] ' + WLAN_ITEM_FORMAT.format(bars=item.bars, signal=item.signal, ssid=item.ssid, rate=item.rate)
|
||||
if action.action == ACT_DISCONNECT_VPN:
|
||||
return '[dis] ' + VPN_ITEM_FORMAT.format(name=item.name)
|
||||
if action.action == ACT_DISCONNECT_WLAN:
|
||||
return '[dis] ' + WLAN_ITEM_FORMAT.format(bars=item.bars, signal=item.signal, ssid=item.ssid, rate=item.rate)
|
||||
|
||||
def get_command(action):
|
||||
item = action.item
|
||||
if action.action == ACT_CONNECT_VPN:
|
||||
return ['nmcli', 'connection', 'up', item.name], None
|
||||
if action.action == ACT_CONNECT_WLAN:
|
||||
return ['nmcli', 'connection', 'up', item.ssid], ['nmcli', 'device', 'wifi', 'connect', item.ssid]
|
||||
if action.action == ACT_DISCONNECT_VPN:
|
||||
return ['nmcli', 'connection', 'down', item.name], None
|
||||
if action.action == ACT_DISCONNECT_WLAN:
|
||||
return ['nmcli', 'connection', 'down', item.ssid], None
|
||||
|
||||
# ---------- BEGINNING OF SCRIPT ----------
|
||||
|
||||
# Get available wifi APs with nmcli
|
||||
list_aps_command = ['nmcli', '-t', 'device', 'wifi', 'list']
|
||||
list_aps_result = subprocess.run(list_aps_command, stdout=subprocess.PIPE)
|
||||
list_aps_output = list_aps_result.stdout.decode('utf-8')
|
||||
nm_items = [APListItem(*line.split(':')) for line in list_aps_output.split('\n') if line]
|
||||
|
||||
# Get VPN status
|
||||
list_con_command = ['nmcli', '-t', 'connection', 'show']
|
||||
list_con_result = subprocess.run(list_con_command, stdout=subprocess.PIPE)
|
||||
list_con_output = list_con_result.stdout.decode('utf-8')
|
||||
con_items = [ConListItem(*line.split(':')) for line in list_con_output.split('\n') if line]
|
||||
|
||||
available_vpns = [item for item in con_items if item.type == 'vpn' and item.device.strip() == '']
|
||||
active_vpns = [item for item in con_items if item.type == 'vpn' and item.device.strip() != '']
|
||||
|
||||
# Make a unique list of ssids
|
||||
ssids = set()
|
||||
unique_wlans = []
|
||||
active_wlans = []
|
||||
|
||||
for item in nm_items:
|
||||
if item.active == '*':
|
||||
active_wlans.append(item)
|
||||
elif item.ssid not in ssids and item.ssid != '':
|
||||
unique_wlans.append(item)
|
||||
ssids.add(item.ssid)
|
||||
|
||||
# Build all available actions
|
||||
actions = []
|
||||
actions.extend(Action(ACT_DISCONNECT_WLAN, item) for item in active_wlans)
|
||||
actions.extend(Action(ACT_DISCONNECT_VPN, item) for item in active_vpns)
|
||||
actions.extend(Action(ACT_CONNECT_WLAN, item) for item in unique_wlans)
|
||||
actions.extend(Action(ACT_CONNECT_VPN, item) for item in available_vpns)
|
||||
|
||||
actions_format = [format_action(action) for action in actions]
|
||||
|
||||
# Use rofi to ask the user which AP to connect to
|
||||
ROFI_WIFI_PROMPT = "wifi: "
|
||||
rofi_command = ['rofi', '-dmenu', '-i', '-format', 'i:s', '-p', ROFI_WIFI_PROMPT]
|
||||
active_len = len(active_wlans) + len(active_vpns)
|
||||
if active_len:
|
||||
rofi_command.extend(['-a', '0-{}'.format(active_len - 1)])
|
||||
|
||||
input_str = '\n'.join(actions_format)
|
||||
|
||||
rofi_result = subprocess.run(rofi_command, input=input_str, stdout=subprocess.PIPE, encoding='utf-8')
|
||||
|
||||
if rofi_result.returncode != 0:
|
||||
exit(rofi_result.returncode)
|
||||
|
||||
rofi_output = rofi_result.stdout.split(":")
|
||||
index = int(rofi_output[0])
|
||||
|
||||
fallback_code = None
|
||||
|
||||
if index < 0:
|
||||
exit(-1)
|
||||
|
||||
command, fallback_command = get_command(actions[index])
|
||||
|
||||
connect_result = subprocess.run(command)
|
||||
|
||||
if connect_result.returncode == 10:
|
||||
connect_result = subprocess.run(fallback_command)
|
||||
|
||||
exit(connect_result.returncode)
|
||||
|
||||
39
.config/polybar/scripts/wifi_status.py
Executable file
39
.config/polybar/scripts/wifi_status.py
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import time
|
||||
import subprocess
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
APListItem = namedtuple('APListItem', ('active', 'ssid', 'mode', 'channel', 'rate', 'signal', 'bars', 'security'))
|
||||
ConListItem = namedtuple('ConListItem', ('name', 'uuid', 'type', 'device'))
|
||||
|
||||
|
||||
if True:
|
||||
# Get available wifi APs with nmcli
|
||||
list_aps_command = ['nmcli', '-t', 'device', 'wifi', 'list']
|
||||
list_aps_result = subprocess.run(list_aps_command, stdout=subprocess.PIPE)
|
||||
list_aps_output = list_aps_result.stdout.decode('utf-8')
|
||||
nm_items = [APListItem(*line.split(':')) for line in list_aps_output.split('\n') if line]
|
||||
|
||||
active_items = [item for item in nm_items if item.active == '*']
|
||||
|
||||
|
||||
# Get VPN status
|
||||
list_con_command = ['nmcli', '-t', 'connection', 'show']
|
||||
list_con_result = subprocess.run(list_con_command, stdout=subprocess.PIPE)
|
||||
list_con_output = list_con_result.stdout.decode('utf-8')
|
||||
con_items = [ConListItem(*line.split(':')) for line in list_con_output.split('\n') if line]
|
||||
|
||||
active_vpn = [item for item in con_items if item.type == 'vpn' and item.device.strip() != '']
|
||||
|
||||
if active_items:
|
||||
active_item = active_items[0]
|
||||
wifi_status = '{ssid} [{signal}%]'.format(signal=active_item.signal, ssid=active_item.ssid)
|
||||
else:
|
||||
wifi_status = 'disconnected'
|
||||
|
||||
vps_status = '[VPN]' if active_vpn else ''
|
||||
|
||||
print(''.join([wifi_status, vps_status]).strip())
|
||||
# time.sleep(3)
|
||||
Reference in New Issue
Block a user