mirror of
https://github.com/kristoferssolo/solorice.git
synced 2026-02-04 06:32:03 +00:00
Use dotter
This commit is contained in:
245
config/waybar/config
Normal file
245
config/waybar/config
Normal file
@@ -0,0 +1,245 @@
|
||||
{
|
||||
"layer": "top", // Waybar at top layer
|
||||
/* "position": "bottom", // Waybar position (top|bottom|left|right) */
|
||||
"height": 30, // Waybar height (to be removed for auto height)
|
||||
/* "width": 1280, // Waybar width */
|
||||
"spacing": 4, // Gaps between modules (4px)
|
||||
// Choose the order of the modules
|
||||
"modules-left": ["wlr/workspaces", "custom/media"],
|
||||
"modules-center": ["hyprland/window"],
|
||||
"modules-right": ["network", "custom/pacman", "backlight", "temperature", "pulseaudio", "battery", "custom/dunst", "custom/weather", "tray", "clock"],
|
||||
// Modules configuration
|
||||
"wlr/workspaces": {
|
||||
"format": "{icon}",
|
||||
"on-click": "activate",
|
||||
"format-icons": {
|
||||
/* "1": "1", */
|
||||
/* "2": "2", */
|
||||
/* "3": "3", */
|
||||
/* "4": "4", */
|
||||
/* "5": "5", */
|
||||
/* "6": "6", */
|
||||
/* "7": "7", */
|
||||
/* "8": "8", */
|
||||
/* "9": "9", */
|
||||
/* "10": "10", */
|
||||
/* "urgent": "", */
|
||||
/* "active": "", */
|
||||
/* "default": "" */
|
||||
},
|
||||
"sort-by-number": true
|
||||
},
|
||||
|
||||
"hyprland/window": {
|
||||
"format": "{}",
|
||||
"separate-outputs": true
|
||||
},
|
||||
|
||||
"hyprland/language": {
|
||||
"format": "{}",
|
||||
"format-us": "us",
|
||||
"format-lv": "lv",
|
||||
"keyboard-name": "AT Translated Set 2 keyboard"
|
||||
},
|
||||
|
||||
"keyboard-state": {
|
||||
"numlock": true,
|
||||
"capslock": true,
|
||||
"format": "{name} {icon}",
|
||||
"format-icons": {
|
||||
"locked": "",
|
||||
"unlocked": ""
|
||||
}
|
||||
},
|
||||
|
||||
"mpd": {
|
||||
"format": "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) ⸨{songPosition}|{queueLength}⸩ {volume}% ",
|
||||
"format-disconnected": "Disconnected ",
|
||||
"format-stopped": "{consumeIcon}{randomIcon}{repeatIcon}{singleIcon}Stopped ",
|
||||
"unknown-tag": "N/A",
|
||||
"interval": 2,
|
||||
"consume-icons": {
|
||||
"on": " "
|
||||
},
|
||||
"random-icons": {
|
||||
"off": "<span color=\"#f53c3c\"></span> ",
|
||||
"on": " "
|
||||
},
|
||||
"repeat-icons": {
|
||||
"on": " "
|
||||
},
|
||||
"single-icons": {
|
||||
"on": "1 "
|
||||
},
|
||||
"state-icons": {
|
||||
"paused": "",
|
||||
"playing": ""
|
||||
},
|
||||
"tooltip-format": "MPD (connected)",
|
||||
"tooltip-format-disconnected": "MPD (disconnected)"
|
||||
},
|
||||
|
||||
"idle_inhibitor": {
|
||||
"format": "{icon}",
|
||||
"format-icons": {
|
||||
"activated": "",
|
||||
"deactivated": ""
|
||||
}
|
||||
},
|
||||
|
||||
"tray": {
|
||||
"icon-size": 21,
|
||||
"spacing": 10
|
||||
},
|
||||
|
||||
"clock": {
|
||||
"format": "{:%d.%m.%Y %H:%M:%S}",
|
||||
"tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
|
||||
"interval": 1
|
||||
},
|
||||
|
||||
"cpu": {
|
||||
"format": "{usage}% ",
|
||||
"tooltip": false
|
||||
},
|
||||
|
||||
"memory": {
|
||||
"interval": 30,
|
||||
"format": "{used:0.1f}G/{total:0.1f}G"
|
||||
},
|
||||
|
||||
"temperature": {
|
||||
/* "thermal-zone": 2, */
|
||||
/* "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input", */
|
||||
"critical-threshold": 80,
|
||||
"format-critical": "{temperatureC}°C ",
|
||||
"format": "{temperatureC}°C ",
|
||||
"format-icons": ["", "", ""]
|
||||
},
|
||||
|
||||
"backlight": {
|
||||
/* "device": "acpi_video1", */
|
||||
"format": "{percent}% {icon}",
|
||||
"format-icons": ["", "", "", "", "", "", "", "", ""],
|
||||
"on-click": "brightnessctl -q set 60%",
|
||||
"on-scroll-down": "brightnessctl -q set +1%",
|
||||
"on-scroll-up": "brightnessctl -q set 1%-",
|
||||
|
||||
},
|
||||
|
||||
"battery": {
|
||||
"states": {
|
||||
"good": 95,
|
||||
"warning": 30,
|
||||
"critical": 10
|
||||
},
|
||||
"format": "{capacity}% {icon}",
|
||||
"format-charging": "{capacity}% ",
|
||||
"format-plugged": "{capacity}% ",
|
||||
"format-alt": "{time} {icon}",
|
||||
/* "format-good": "", // An empty format will hide the module */
|
||||
/* "format-full": "", */
|
||||
"format-icons": ["", "", "", "", ""]
|
||||
},
|
||||
|
||||
"network": {
|
||||
"format-wifi": "{essid} ({signalStrength}%) ",
|
||||
"format-ethernet": "{ipaddr}/{cidr} ",
|
||||
"tooltip-format": "{ifname} via {gwaddr} ",
|
||||
"format-linked": "{ifname} (No IP) ",
|
||||
"format-disconnected": "Disconnected ⚠",
|
||||
"format-alt": "{ifname}: {ipaddr}/{cidr}"
|
||||
},
|
||||
|
||||
"wireplumber": {
|
||||
"format": "{volume}% {icon}",
|
||||
"format-muted": "",
|
||||
"on-click": "pulsemixer --toggle-mute",
|
||||
"format-icons": ["", "", ""]
|
||||
},
|
||||
|
||||
"pulseaudio": {
|
||||
"scroll-step": 1, // %, can be a float
|
||||
"format": "{volume}% {icon} {format_source}",
|
||||
"format-bluetooth": "{volume}% {icon} {format_source}",
|
||||
"format-bluetooth-muted": "{volume}% {icon} {format_source}",
|
||||
"format-muted": "{volume}% {icon} {format_source}",
|
||||
"format-source": "{volume}% ",
|
||||
"format-source-muted": "",
|
||||
"format-icons": {
|
||||
"headphone": "",
|
||||
"hands-free": "",
|
||||
"headset": "",
|
||||
"phone": "",
|
||||
"portable": "",
|
||||
"car": "",
|
||||
"default": ["", "", ""]
|
||||
},
|
||||
"on-click": "pulsemixer --toggle-mute"
|
||||
},
|
||||
|
||||
"custom/media": {
|
||||
"format": "{icon} {}",
|
||||
"return-type": "json",
|
||||
/* "max-length": 40, */
|
||||
"on-click": "playerctl play-pause",
|
||||
"on-click-right": "playerctl stop",
|
||||
"on-scroll-up": "playerctl next",
|
||||
"on-scroll-down": "playerctl previous",
|
||||
"format-icons": {
|
||||
"spotify": "",
|
||||
"default": "🎜"
|
||||
},
|
||||
"escape": true,
|
||||
"smooth-scrolling-threshold": 10, // This value was tested using a trackpad, it should be lowered if using a mouse.
|
||||
"exec": "$HOME/.config/waybar/scripts/mediaplayer.py 2> /dev/null" // Script in resources folder
|
||||
/* "exec": "$HOME/.config/waybar/scripts/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name */
|
||||
},
|
||||
|
||||
|
||||
"custom/pacman": {
|
||||
"format": "{} ",
|
||||
"interval": 600, // every hour
|
||||
"exec": "checkupdates | wc -l", // # of updates
|
||||
"exec-if": "exit 0", // always run; consider advanced run conditions
|
||||
"on-click": "alacritty -e paru -Syu --noconfirm; pkill -RTMIN+8 waybar", // update system
|
||||
"signal": 8
|
||||
},
|
||||
|
||||
"custom/weather": {
|
||||
"exec": "curl 'https://wttr.in/?format=1'",
|
||||
"interval": 600,
|
||||
"on-click": "curl 'https://wttr.in/?format=1'",
|
||||
},
|
||||
|
||||
"custom/vpn": {
|
||||
"format": "VPN ",
|
||||
"exec": "echo '{\"class\": \"connected\"}'",
|
||||
"exec-if": "test -d /proc/sys/net/ipv4/conf/tun0",
|
||||
"return-type": "json",
|
||||
"interval": 5
|
||||
},
|
||||
|
||||
"custom/pipewire": {
|
||||
"tooltip": true,
|
||||
"max-length": 10,
|
||||
"exec": "$HOME/.config/waybar/scripts/pipewire.sh",
|
||||
"on-click": "pulsemixer --toggle-mute",
|
||||
"on-click-right": "qpwgraph"
|
||||
},
|
||||
|
||||
"custom/github": {
|
||||
"format": "{} ",
|
||||
"return-type": "json",
|
||||
"interval": 60,
|
||||
"exec": "$HOME/.config/waybar/scripts/github.sh",
|
||||
"on-click": "xdg-open https://github.com/notifications"
|
||||
},
|
||||
|
||||
"custom/dunst": {
|
||||
"exec": "~/.config/waybar/scripts/dunst.sh",
|
||||
"on-click": "dunstctl set-paused toggle",
|
||||
"restart-interval": 1,
|
||||
},
|
||||
}
|
||||
|
||||
130
config/waybar/mediaplayer.py
Normal file
130
config/waybar/mediaplayer.py
Normal file
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
import signal
|
||||
import json
|
||||
import gi
|
||||
from gi.repository import Playerctl, GLib
|
||||
gi.require_version('Playerctl', '2.0')
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def write_output(text, player):
|
||||
logger.info('Writing output')
|
||||
|
||||
output = {'text': text,
|
||||
'class': 'custom-' + player.props.player_name,
|
||||
'alt': player.props.player_name}
|
||||
|
||||
sys.stdout.write(json.dumps(output) + '\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def on_play(player, status, manager):
|
||||
logger.info('Received new playback status')
|
||||
on_metadata(player, player.props.metadata, manager)
|
||||
|
||||
|
||||
def on_metadata(player, metadata, manager):
|
||||
logger.info('Received new metadata')
|
||||
track_info = ''
|
||||
|
||||
if player.props.player_name == 'spotify' and \
|
||||
'mpris:trackid' in metadata.keys() and \
|
||||
':ad:' in player.props.metadata['mpris:trackid']:
|
||||
track_info = 'AD PLAYING'
|
||||
elif player.get_artist() != '' and player.get_title() != '':
|
||||
track_info = '{artist} - {title}'.format(artist=player.get_artist(),
|
||||
title=player.get_title())
|
||||
else:
|
||||
track_info = player.get_title()
|
||||
|
||||
if player.props.status != 'Playing' and track_info:
|
||||
track_info = ' ' + track_info
|
||||
write_output(track_info, player)
|
||||
|
||||
|
||||
def on_player_appeared(manager, player, selected_player=None):
|
||||
if player is not None and (selected_player is None or player.name == selected_player):
|
||||
init_player(manager, player)
|
||||
else:
|
||||
logger.debug(
|
||||
"New player appeared, but it's not the selected player, skipping")
|
||||
|
||||
|
||||
def on_player_vanished(manager, player):
|
||||
logger.info('Player has vanished')
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def init_player(manager, name):
|
||||
logger.debug('Initialize player: {player}'.format(player=name.name))
|
||||
player = Playerctl.Player.new_from_name(name)
|
||||
player.connect('playback-status', on_play, manager)
|
||||
player.connect('metadata', on_metadata, manager)
|
||||
manager.manage_player(player)
|
||||
on_metadata(player, player.props.metadata, manager)
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logger.debug('Received signal to stop, exiting')
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
# loop.quit()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
# Increase verbosity with every occurrence of -v
|
||||
parser.add_argument('-v', '--verbose', action='count', default=0)
|
||||
|
||||
# Define for which player we're listening
|
||||
parser.add_argument('--player')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
arguments = parse_arguments()
|
||||
|
||||
# Initialize logging
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
|
||||
format='%(name)s %(levelname)s %(message)s')
|
||||
|
||||
# Logging is set by default to WARN and higher.
|
||||
# With every occurrence of -v it's lowered by one
|
||||
logger.setLevel(max((3 - arguments.verbose) * 10, 0))
|
||||
|
||||
# Log the sent command line arguments
|
||||
logger.debug('Arguments received {}'.format(vars(arguments)))
|
||||
|
||||
manager = Playerctl.PlayerManager()
|
||||
loop = GLib.MainLoop()
|
||||
|
||||
manager.connect('name-appeared',
|
||||
lambda *args: on_player_appeared(*args, arguments.player))
|
||||
manager.connect('player-vanished', on_player_vanished)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
|
||||
for player in manager.props.player_names:
|
||||
if arguments.player is not None and arguments.player != player.name:
|
||||
logger.debug('{player} is not the filtered player, skipping it'
|
||||
.format(player=player.name)
|
||||
)
|
||||
continue
|
||||
|
||||
init_player(manager, player)
|
||||
|
||||
loop.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
7
config/waybar/scripts/dunst.sh
Normal file
7
config/waybar/scripts/dunst.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
COUNT=$(dunstctl count waiting)
|
||||
ENABLED=
|
||||
DISABLED=
|
||||
if [ "$COUNT" != 0 ]; then DISABLED=" $COUNT"; fi
|
||||
if dunstctl is-paused | grep -q "false" ; then echo $ENABLED; else echo "$DISABLED"; fi
|
||||
11
config/waybar/scripts/github.sh
Normal file
11
config/waybar/scripts/github.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
token=$(cat "${HOME}"/.config/github/notifications.token)
|
||||
count=$(curl -u kristoferssolo:"${token}" https://api.github.com/notifications | jq '. | length')
|
||||
|
||||
# if [[ "$count" != "0" ]]; then
|
||||
# echo "{'text':$(count),'tooltip':$(tooltip),'class':$(class)}"
|
||||
# fi
|
||||
if [[ "$count" != "0" ]]; then
|
||||
echo '{"text":'$count',"tooltip":"$tooltip","class":"$class"}'
|
||||
fi
|
||||
128
config/waybar/scripts/mediaplayer.py
Normal file
128
config/waybar/scripts/mediaplayer.py
Normal file
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
import signal
|
||||
import gi
|
||||
import json
|
||||
gi.require_version('Playerctl', '2.0')
|
||||
from gi.repository import Playerctl, GLib
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def write_output(text, player):
|
||||
logger.info('Writing output')
|
||||
|
||||
output = {'text': text,
|
||||
'class': 'custom-' + player.props.player_name,
|
||||
'alt': player.props.player_name}
|
||||
|
||||
sys.stdout.write(json.dumps(output) + '\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def on_play(player, status, manager):
|
||||
logger.info('Received new playback status')
|
||||
on_metadata(player, player.props.metadata, manager)
|
||||
|
||||
|
||||
def on_metadata(player, metadata, manager):
|
||||
logger.info('Received new metadata')
|
||||
track_info = ''
|
||||
|
||||
if player.props.player_name == 'spotify' and \
|
||||
'mpris:trackid' in metadata.keys() and \
|
||||
':ad:' in player.props.metadata['mpris:trackid']:
|
||||
track_info = 'AD PLAYING'
|
||||
elif player.get_artist() != '' and player.get_title() != '':
|
||||
track_info = '{artist} - {title}'.format(artist=player.get_artist(),
|
||||
title=player.get_title())
|
||||
else:
|
||||
track_info = player.get_title()
|
||||
|
||||
if player.props.status != 'Playing' and track_info:
|
||||
track_info = ' ' + track_info
|
||||
write_output(track_info, player)
|
||||
|
||||
|
||||
def on_player_appeared(manager, player, selected_player=None):
|
||||
if player is not None and (selected_player is None or player.name == selected_player):
|
||||
init_player(manager, player)
|
||||
else:
|
||||
logger.debug("New player appeared, but it's not the selected player, skipping")
|
||||
|
||||
|
||||
def on_player_vanished(manager, player):
|
||||
logger.info('Player has vanished')
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def init_player(manager, name):
|
||||
logger.debug('Initialize player: {player}'.format(player=name.name))
|
||||
player = Playerctl.Player.new_from_name(name)
|
||||
player.connect('playback-status', on_play, manager)
|
||||
player.connect('metadata', on_metadata, manager)
|
||||
manager.manage_player(player)
|
||||
on_metadata(player, player.props.metadata, manager)
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logger.debug('Received signal to stop, exiting')
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
# loop.quit()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
# Increase verbosity with every occurrence of -v
|
||||
parser.add_argument('-v', '--verbose', action='count', default=0)
|
||||
|
||||
# Define for which player we're listening
|
||||
parser.add_argument('--player')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
arguments = parse_arguments()
|
||||
|
||||
# Initialize logging
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
|
||||
format='%(name)s %(levelname)s %(message)s')
|
||||
|
||||
# Logging is set by default to WARN and higher.
|
||||
# With every occurrence of -v it's lowered by one
|
||||
logger.setLevel(max((3 - arguments.verbose) * 10, 0))
|
||||
|
||||
# Log the sent command line arguments
|
||||
logger.debug('Arguments received {}'.format(vars(arguments)))
|
||||
|
||||
manager = Playerctl.PlayerManager()
|
||||
loop = GLib.MainLoop()
|
||||
|
||||
manager.connect('name-appeared', lambda *args: on_player_appeared(*args, arguments.player))
|
||||
manager.connect('player-vanished', on_player_vanished)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
|
||||
for player in manager.props.player_names:
|
||||
if arguments.player is not None and arguments.player != player.name:
|
||||
logger.debug('{player} is not the filtered player, skipping it'
|
||||
.format(player=player.name)
|
||||
)
|
||||
continue
|
||||
|
||||
init_player(manager, player)
|
||||
|
||||
loop.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
41
config/waybar/scripts/pipewire.sh
Normal file
41
config/waybar/scripts/pipewire.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# https://blog.dhampir.no/content/sleeping-without-a-subprocess-in-bash-and-how-to-sleep-forever
|
||||
snore() {
|
||||
local IFS
|
||||
[[ -n "${_snore_fd:-}" ]] || exec {_snore_fd}<> <(:)
|
||||
read -r ${1:+-t "$1"} -u $_snore_fd || :
|
||||
}
|
||||
|
||||
DELAY=0.2
|
||||
|
||||
while snore $DELAY; do
|
||||
WP_OUTPUT=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
|
||||
|
||||
if [[ $WP_OUTPUT =~ ^Volume:[[:blank:]]([0-9]+)\.([0-9]{2})([[:blank:]].MUTED.)?$ ]]; then
|
||||
if [[ -n ${BASH_REMATCH[3]} ]]; then
|
||||
printf "MUTED\n"
|
||||
else
|
||||
VOLUME=$((10#${BASH_REMATCH[1]}${BASH_REMATCH[2]}))
|
||||
ICON=(
|
||||
""
|
||||
""
|
||||
""
|
||||
)
|
||||
|
||||
if [[ $VOLUME -gt 50 ]]; then
|
||||
printf "%s" "${ICON[0]} "
|
||||
elif [[ $VOLUME -gt 25 ]]; then
|
||||
printf "%s" "${ICON[1]} "
|
||||
elif [[ $VOLUME -ge 0 ]]; then
|
||||
printf "%s" "${ICON[2]} "
|
||||
fi
|
||||
|
||||
printf "$VOLUME%%\n"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
54
config/waybar/scripts/wireguard-rofi.sh
Normal file
54
config/waybar/scripts/wireguard-rofi.sh
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# WireGuard custom menu script to manage NetworkManager WireGuard connections using rofi
|
||||
# install to the same directory as wireguard.sh
|
||||
# example usage with rofi: rofi -modi 'WireGuard:~/.config/rofi/wireguard-rofi.sh' -show WireGuard
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
if [[ $# != 0 ]]
|
||||
then
|
||||
if [[ "$@" == "quit" ]]
|
||||
then
|
||||
exit 0
|
||||
elif [[ "$1" != "reload" ]]
|
||||
then
|
||||
connection=$(echo $1 | cut -d: -f1)
|
||||
message="$($SCRIPT_DIR/wireguard.sh toggle $connection)"
|
||||
if command -v notify-send >/dev/null 2>&1; then
|
||||
notify-send "wireguard" "$message"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
active=-1
|
||||
urgent=-1
|
||||
|
||||
while read -r state connection IP
|
||||
do
|
||||
if [[ "$state" == "connected:" ]]
|
||||
then
|
||||
active=$(($active+1))
|
||||
elif [[ "$state" == "available:" ]]
|
||||
then
|
||||
urgent=$(($urgent+1))
|
||||
fi
|
||||
if [[ "$IP" != "" ]]
|
||||
then
|
||||
connection="$connection [$IP]"
|
||||
fi
|
||||
echo -en "$connection\0icon\x1fwireguard\n"
|
||||
done < <($SCRIPT_DIR/wireguard.sh menu)
|
||||
|
||||
if [[ $active -ge 0 ]]
|
||||
then
|
||||
echo -en "\0active\x1f0-$active\n"
|
||||
fi
|
||||
if [[ $urgent -ge 0 ]]
|
||||
then
|
||||
echo -en "\0urgent\x1f$(($active+1))-$(($active+1+$urgent))\n"
|
||||
fi
|
||||
|
||||
echo "reload"
|
||||
echo "quit"
|
||||
165
config/waybar/scripts/wireguard.sh
Normal file
165
config/waybar/scripts/wireguard.sh
Normal file
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# nmcli WireGuard abstraction layer for use with my waybar module and rofi custom menu script
|
||||
#
|
||||
# requires nmcli on your path
|
||||
# install to the same directory as wireguard-rofi.sh
|
||||
#
|
||||
# usage: ./wireguard.sh [short|menu|toggle NAME]
|
||||
# no argument: print current connections
|
||||
# short: print current connections in short format
|
||||
# menu: print all connections
|
||||
# toggle NAME: toggle connection NAME
|
||||
|
||||
if ! command -v nmcli >/dev/null 2>&1; then
|
||||
echo "ERROR: 'nmcli' not found"
|
||||
echo "This tool is a 'nmcli' frontend, hence you should install NetworkManager before trying to use it."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nargs=$#
|
||||
get="no"
|
||||
showmenu="no"
|
||||
short="no"
|
||||
dotoggle="no"
|
||||
if [[ $nargs == 0 ]]
|
||||
then
|
||||
get="yes"
|
||||
elif [[ $nargs == 1 ]]
|
||||
then
|
||||
if [[ $1 == "menu" ]]
|
||||
then
|
||||
showmenu="yes"
|
||||
elif [[ $1 == "short" ]]
|
||||
then
|
||||
if ! command -v sed >/dev/null 2>&1; then
|
||||
echo "ERROR: 'sed' not found"
|
||||
echo "Please install 'sed' to enable the 'short' option."
|
||||
exit 1
|
||||
fi
|
||||
get="yes"
|
||||
short="short"
|
||||
fi
|
||||
elif [[ $nargs == 2 ]]
|
||||
then
|
||||
if [[ $1 == "toggle" ]]
|
||||
then
|
||||
dotoggle="yes"
|
||||
conn="$2"
|
||||
fi
|
||||
fi
|
||||
|
||||
nmclicmd="nmcli connection"
|
||||
wgconns="$nmclicmd show"
|
||||
wgactive="$wgconns --active"
|
||||
|
||||
connected=()
|
||||
available=()
|
||||
|
||||
function get_conns {
|
||||
while read -r name uuid type device
|
||||
do
|
||||
if [[ $type != "wireguard" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ $device != "--" ]]
|
||||
then
|
||||
while read -r key value
|
||||
do
|
||||
if [[ $key != "ipv4.addresses:" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
connected+=("$name: $value")
|
||||
done < <($wgconns $name)
|
||||
else
|
||||
available+=("$name")
|
||||
fi
|
||||
done < <($1)
|
||||
}
|
||||
|
||||
function print_conns {
|
||||
local first="yes"
|
||||
local array_print="$1[@]"
|
||||
local array_print=("${!array_print}")
|
||||
local text=""
|
||||
local tooltip=""
|
||||
if [ "${#array_print[@]}" -le 0 ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
if [[ "$2" == "list" ]]
|
||||
then
|
||||
for c in "${array_print[@]}"
|
||||
do
|
||||
echo "$1: $c"
|
||||
done
|
||||
else
|
||||
for c in "${array_print[@]}"
|
||||
do
|
||||
if [[ "$first" != "yes" ]]
|
||||
then
|
||||
text="$text | "
|
||||
tooltip="$tooltip\n"
|
||||
fi
|
||||
if [[ "$2" == "short" ]]
|
||||
then
|
||||
text="$text$(echo -n $c | sed -E 's/^(.+): ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]+)$/\1/')"
|
||||
else
|
||||
text="$text$c"
|
||||
fi
|
||||
tooltip="$tooltip$c"
|
||||
first="no"
|
||||
done
|
||||
echo "{\"text\": \"$text\", \"tooltip\": \"$tooltip\"}"
|
||||
fi
|
||||
}
|
||||
|
||||
function array_contains {
|
||||
local array_has="$1[@]"
|
||||
local array_has=("${!array_has}")
|
||||
local element="$2"
|
||||
for e in "${array_has[@]}"
|
||||
do
|
||||
if [[ "$e" == *"$element"* ]]
|
||||
then
|
||||
echo "yes"
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo "no"
|
||||
}
|
||||
|
||||
if [[ $get == "yes" ]]
|
||||
then
|
||||
get_conns "$wgactive"
|
||||
print_conns connected "$short"
|
||||
|
||||
elif [[ $showmenu == "yes" ]]
|
||||
then
|
||||
get_conns "$wgconns"
|
||||
print_conns connected "list"
|
||||
print_conns available "list"
|
||||
|
||||
|
||||
elif [[ $dotoggle == "yes" ]]
|
||||
then
|
||||
get_conns "$wgconns"
|
||||
|
||||
if [[ "$(array_contains connected $conn)" == "yes" ]]
|
||||
then
|
||||
$nmclicmd down "$conn"
|
||||
elif [[ "$(array_contains available $conn)" == "yes" ]]
|
||||
then
|
||||
$nmclicmd up "$conn"
|
||||
else
|
||||
echo "err: connection not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
echo "err: wrong args"
|
||||
exit 1
|
||||
fi
|
||||
157
config/waybar/style.css
Normal file
157
config/waybar/style.css
Normal file
@@ -0,0 +1,157 @@
|
||||
* {
|
||||
/* `otf-font-awesome` is required to be installed for icons */
|
||||
font-family:
|
||||
JetBrains Mono NF,
|
||||
FontAwesome,
|
||||
Roboto,
|
||||
Helvetica,
|
||||
Arial,
|
||||
sans-serif;
|
||||
font-size: 13px;
|
||||
color: #c0caf5;
|
||||
}
|
||||
|
||||
window#waybar {
|
||||
border-top: 3px solid transparent;
|
||||
color: #c0caf5;
|
||||
transition-property: background-color;
|
||||
transition-duration: 0.5s;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#window {
|
||||
border-radius: 20px;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
window#waybar.hidden {
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
window#waybar.chromium {
|
||||
background-color: #000;
|
||||
border: none;
|
||||
}
|
||||
|
||||
button {
|
||||
/* Use box-shadow instead of border so the text isn't offset */
|
||||
box-shadow: inset 0 3px transparent;
|
||||
/* Avoid rounded borders under each button name */
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
||||
button:hover {
|
||||
background: inherit;
|
||||
box-shadow: inset 0 3px #c0caf5;
|
||||
}
|
||||
|
||||
#workspaces button {
|
||||
padding: 0 5px;
|
||||
color: #c0caf5;
|
||||
}
|
||||
|
||||
#workspaces button.active {
|
||||
box-shadow: inset 0 3px #c0caf5;
|
||||
}
|
||||
|
||||
#workspaces button.urgent {
|
||||
background-color: #db4b4b;
|
||||
}
|
||||
|
||||
#mode {
|
||||
border-bottom: 3px solid #c0caf5;
|
||||
}
|
||||
|
||||
#clock,
|
||||
#battery,
|
||||
#cpu,
|
||||
#memory,
|
||||
#disk,
|
||||
#temperature,
|
||||
#backlight,
|
||||
#network,
|
||||
#pulseaudio,
|
||||
#custom-media,
|
||||
#tray,
|
||||
#mode,
|
||||
#idle_inhibitor,
|
||||
#scratchpad,
|
||||
#mpd,
|
||||
#custom-wireguard,
|
||||
#custom-github,
|
||||
#custom-dunst {
|
||||
padding: 0 10px;
|
||||
font-weight: bold;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#custom-pipewire.muted {
|
||||
color: #414868;
|
||||
}
|
||||
|
||||
#window,
|
||||
#workspaces {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
/* If workspaces is the leftmost module, omit left margin */
|
||||
.modules-left > widget:first-child > #workspaces {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
/* If workspaces is the rightmost module, omit right margin */
|
||||
.modules-right > widget:last-child > #workspaces {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
#battery.charging,
|
||||
#battery.plugged {
|
||||
color: #1abc9c;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
to {
|
||||
color: #c0caf5;
|
||||
}
|
||||
}
|
||||
|
||||
#battery.warning:not(.charging) {
|
||||
color: #e0af68;
|
||||
}
|
||||
|
||||
#battery.critical:not(.charging) {
|
||||
color: #db4b4b;
|
||||
animation-name: blink;
|
||||
animation-duration: 0.5s;
|
||||
animation-timing-function: linear;
|
||||
animation-iteration-count: infinite;
|
||||
animation-direction: alternate;
|
||||
}
|
||||
|
||||
#pulseaudio.muted {
|
||||
color: #414868;
|
||||
}
|
||||
|
||||
#custom-media {
|
||||
color: #41a6b5;
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
#temperature.critical {
|
||||
color: #db4b4b;
|
||||
}
|
||||
|
||||
#tray > .passive {
|
||||
-gtk-icon-effect: dim;
|
||||
}
|
||||
|
||||
#tray > .needs-attention {
|
||||
-gtk-icon-effect: highlight;
|
||||
}
|
||||
|
||||
#network.disconnected {
|
||||
color: #db4b4b;
|
||||
}
|
||||
Reference in New Issue
Block a user