New Setup 📦
This commit is contained in:
parent
d16174b447
commit
415dbd08a1
10194 changed files with 1368647 additions and 4 deletions
BIN
home/.config/waybar/scripts/KeyHints$Column.class
Normal file
BIN
home/.config/waybar/scripts/KeyHints$Column.class
Normal file
Binary file not shown.
BIN
home/.config/waybar/scripts/KeyHints.class
Normal file
BIN
home/.config/waybar/scripts/KeyHints.class
Normal file
Binary file not shown.
100
home/.config/waybar/scripts/KeyHints.java
Normal file
100
home/.config/waybar/scripts/KeyHints.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class KeyHints {
|
||||
private static final int STEP = 50;
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
args = new String[]{"/home/owpk/.config/sway/config.d/default"};
|
||||
if (args.length != 1) {
|
||||
System.err.println("pass path to sway keybind config as first arg");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
var lines = Files.lines(Paths.get(args[0]))
|
||||
.map(String::strip)
|
||||
.filter(x -> x.contains("$mod"))
|
||||
.map(x -> x.replaceAll("[ |\t]+", " ")
|
||||
.replaceAll("\"", "").substring(x.indexOf("$"))).collect(Collectors.toList());
|
||||
|
||||
var splittedSource = splitToSublist(lines.stream()
|
||||
.sorted(Comparator.comparing(x -> x.toLowerCase())).collect(Collectors.toList()));
|
||||
|
||||
var splittedListOfMap = splittedSource.stream()
|
||||
.map(x -> {
|
||||
var map = x.stream().map(s -> s.split(" ", 2))
|
||||
.collect(Collectors.toMap(x1 -> x1[0], x2 -> x2[1]));
|
||||
var tree = new TreeMap<String, String>(
|
||||
Comparator.comparing(c -> c, String.CASE_INSENSITIVE_ORDER));
|
||||
tree.putAll(map);
|
||||
return tree;
|
||||
}).map(x -> {
|
||||
var longestKey = getLongestStringFormat(
|
||||
streamToLongestWordLength(x.keySet().stream()));
|
||||
return x.entrySet().stream()
|
||||
.map(s -> (String.format(longestKey, s.getKey()) + s.getValue())
|
||||
.replaceAll(" ", "."))
|
||||
.collect(Collectors.toList());
|
||||
}).map(x -> new Column(x, streamToLongestWordLength(x.stream())))
|
||||
.collect(Collectors.toList());
|
||||
var sb = new StringBuilder();
|
||||
var longestColumn = splittedListOfMap.stream()
|
||||
.max(Comparator.comparing(x -> x.content.size()))
|
||||
.orElse(new Column()).content;
|
||||
|
||||
for (int i = 0; i < longestColumn.size(); i++) {
|
||||
for (Column currentColumn : splittedListOfMap) {
|
||||
String currentLine = "";
|
||||
if (i < currentColumn.content.size()) {
|
||||
currentLine = currentColumn.content.get(i);
|
||||
}
|
||||
sb.append(String.format(getLongestStringFormat(currentColumn.width) + " | ", currentLine));
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
System.out.println(sb);
|
||||
}
|
||||
|
||||
private static class Column {
|
||||
List<String> content = new ArrayList<>();
|
||||
int width;
|
||||
|
||||
public Column() {
|
||||
}
|
||||
|
||||
public Column(List<String> content, int width) {
|
||||
this.content = content;
|
||||
this.width = width;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLongestStringFormat(int size) {
|
||||
return "%-" + size + "s";
|
||||
}
|
||||
|
||||
private static int streamToLongestWordLength(Stream<String> st) {
|
||||
return st.max(Comparator.comparing(String::length))
|
||||
.orElse("").length() + 2;
|
||||
}
|
||||
|
||||
private static List<List<String>> splitToSublist(List<String> baseList) {
|
||||
var list = new ArrayList<List<String>>();
|
||||
int start = 0;
|
||||
int step = Math.min(STEP, baseList.size());
|
||||
int end = step;
|
||||
while (start < end) {
|
||||
var sublist = baseList.subList(start, end);
|
||||
list.add(sublist);
|
||||
start = end + 1;
|
||||
step = Math.min(baseList.size() - end, step);
|
||||
end += step;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
Binary file not shown.
18
home/.config/waybar/scripts/kblayout.sh
Executable file
18
home/.config/waybar/scripts/kblayout.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
KEYBOARD=`swaymsg -r -t get_inputs | grep -i identifier | grep -i keyboard | tail -1| sed 's/"identifier": //; s/ //g; s/,//'`
|
||||
|
||||
if [[ $1 ]]
|
||||
then
|
||||
KEYBOARD="\"$1\""
|
||||
fi
|
||||
|
||||
swaymsg -r -t get_inputs | jq -r \
|
||||
"first(.[]|select(.identifier == $KEYBOARD and .type == \"keyboard\")) \
|
||||
| .xkb_active_layout_name"
|
||||
|
||||
swaymsg -mrt subscribe '["input"]' | jq -r --unbuffered \
|
||||
"select(.change == \"xkb_layout\")
|
||||
| .input
|
||||
| select(.identifier == $KEYBOARD and .type == \"keyboard\") \
|
||||
| .xkb_active_layout_name"
|
||||
|
4
home/.config/waybar/scripts/keyhint.sh
Normal file
4
home/.config/waybar/scripts/keyhint.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
KH=$(java -cp $HOME/.config/waybar/scripts/ KeyHints $HOME/.config/sway/config.d/default)
|
||||
echo $KH
|
BIN
home/.config/waybar/scripts/keyhints
Executable file
BIN
home/.config/waybar/scripts/keyhints
Executable file
Binary file not shown.
3
home/.config/waybar/scripts/keyhints.build_artifacts.txt
Normal file
3
home/.config/waybar/scripts/keyhints.build_artifacts.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
[EXECUTABLE]
|
||||
keyhints
|
||||
|
131
home/.config/waybar/scripts/mediaplayer.py
Executable file
131
home/.config/waybar/scripts/mediaplayer.py
Executable file
|
@ -0,0 +1,131 @@
|
|||
#!/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}
|
||||
|
||||
dump = json.dumps(output) + '\n'
|
||||
logger.info(':: Dumped info: ' + dump)
|
||||
|
||||
sys.stdout.write(dump)
|
||||
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().replace("&", "&"),
|
||||
title=player.get_title().replace("&", "&"))
|
||||
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 occurence 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)
|
||||
|
||||
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()
|
11
home/.config/waybar/scripts/user_location.py
Executable file
11
home/.config/waybar/scripts/user_location.py
Executable file
|
@ -0,0 +1,11 @@
|
|||
import requests
|
||||
|
||||
|
||||
def get_location():
|
||||
response = requests.get(f'https://ipinfo.io').json()
|
||||
location_data = {
|
||||
"city": response.get("city"),
|
||||
"region": response.get("region"),
|
||||
"country": response.get("country")
|
||||
}
|
||||
return location_data
|
117
home/.config/waybar/scripts/waybar-wttr.py
Executable file
117
home/.config/waybar/scripts/waybar-wttr.py
Executable file
|
@ -0,0 +1,117 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import json
|
||||
import requests
|
||||
import user_location
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
WEATHER_CODES = {
|
||||
'113': '☀️',
|
||||
'116': '⛅️',
|
||||
'119': '☁️',
|
||||
'122': '☁️',
|
||||
'143': '🌫',
|
||||
'176': '🌦',
|
||||
'179': '🌧',
|
||||
'182': '🌧',
|
||||
'185': '🌧',
|
||||
'200': '⛈',
|
||||
'227': '🌨',
|
||||
'230': '❄️',
|
||||
'248': '🌫',
|
||||
'260': '🌫',
|
||||
'263': '🌦',
|
||||
'266': '🌦',
|
||||
'281': '🌧',
|
||||
'284': '🌧',
|
||||
'293': '🌦',
|
||||
'296': '🌦',
|
||||
'299': '🌧',
|
||||
'302': '🌧',
|
||||
'305': '🌧',
|
||||
'308': '🌧',
|
||||
'311': '🌧',
|
||||
'314': '🌧',
|
||||
'317': '🌧',
|
||||
'320': '🌨',
|
||||
'323': '🌨',
|
||||
'326': '🌨',
|
||||
'329': '❄️',
|
||||
'332': '❄️',
|
||||
'335': '❄️',
|
||||
'338': '❄️',
|
||||
'350': '🌧',
|
||||
'353': '🌦',
|
||||
'356': '🌧',
|
||||
'359': '🌧',
|
||||
'362': '🌧',
|
||||
'365': '🌧',
|
||||
'368': '🌨',
|
||||
'371': '❄️',
|
||||
'374': '🌧',
|
||||
'377': '🌧',
|
||||
'386': '⛈',
|
||||
'389': '🌩',
|
||||
'392': '⛈',
|
||||
'395': '❄️'
|
||||
}
|
||||
|
||||
data = {}
|
||||
|
||||
user_loc = user_location.get_location()
|
||||
weather = requests.get("https://wttr.in/?format=j1&location={}".format(user_loc)).json()
|
||||
|
||||
|
||||
def format_time(time):
|
||||
return time.replace("00", "").zfill(2)
|
||||
|
||||
|
||||
def format_temp(temp):
|
||||
return (hour['FeelsLikeC']+"°").ljust(3)
|
||||
|
||||
|
||||
def format_chances(hour):
|
||||
chances = {
|
||||
"chanceoffog": "Fog",
|
||||
"chanceoffrost": "Frost",
|
||||
"chanceofovercast": "Overcast",
|
||||
"chanceofrain": "Rain",
|
||||
"chanceofsnow": "Snow",
|
||||
"chanceofsunshine": "Sunshine",
|
||||
"chanceofthunder": "Thunder",
|
||||
"chanceofwindy": "Wind"
|
||||
}
|
||||
|
||||
conditions = []
|
||||
for event in chances.keys():
|
||||
if int(hour[event]) > 0:
|
||||
conditions.append(chances[event]+" "+hour[event]+"%")
|
||||
return ", ".join(conditions)
|
||||
|
||||
|
||||
data['text'] = WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \
|
||||
"" + weather['current_condition'][0]['FeelsLikeC']+"°"
|
||||
|
||||
data['tooltip'] = f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°</b>\n"
|
||||
data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°\n"
|
||||
data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n"
|
||||
data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n"
|
||||
data['tooltip'] += f"Location: {weather['nearest_area'][0]['areaName'][0]['value']}\n"
|
||||
for i, day in enumerate(weather['weather']):
|
||||
data['tooltip'] += f"\n<b>"
|
||||
if i == 0:
|
||||
data['tooltip'] += "Today, "
|
||||
if i == 1:
|
||||
data['tooltip'] += "Tomorrow, "
|
||||
data['tooltip'] += f"{day['date']}</b>\n"
|
||||
data['tooltip'] += f"⬆️ {day['maxtempC']}° ⬇️ {day['mintempC']}° "
|
||||
data['tooltip'] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {day['astronomy'][0]['sunset']}\n"
|
||||
for hour in day['hourly']:
|
||||
if i == 0:
|
||||
if int(format_time(hour['time'])) < datetime.now().hour-2:
|
||||
continue
|
||||
data['tooltip'] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n"
|
||||
|
||||
|
||||
print(json.dumps(data))
|
Loading…
Add table
Add a link
Reference in a new issue