Initial commit with fish, i3, nvim and polybar configuration

This commit is contained in:
Marc Sastre Rienitz
2020-05-17 20:00:08 +02:00
commit e15ad6aa30
30 changed files with 4032 additions and 0 deletions

333
.config/polybar/config Normal file
View File

@@ -0,0 +1,333 @@
;==========================================================
;
;
; ██████╗ ██████╗ ██╗ ██╗ ██╗██████╗ █████╗ ██████╗
; ██╔══██╗██╔═══██╗██║ ╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗
; ██████╔╝██║ ██║██║ ╚████╔╝ ██████╔╝███████║██████╔╝
; ██╔═══╝ ██║ ██║██║ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗
; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║
; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
;
;
; To learn more about how to configure Polybar
; go to https://github.com/polybar/polybar
;
; The README contains a lot of information
;
;==========================================================
[colors]
background = #222
background-alt = #444
foreground = #dfdfdf
foreground-alt = #555
primary = #ffb52a
secondary = #e60053
alert = #bd2c40
################################################################################
################################################################################
############ MAINBAR-I3 ############
################################################################################
################################################################################
[bar/mainbar-i3]
;https://github.com/jaagr/polybar/wiki/Configuration
monitor = ${env:MONITOR}
;monitor-fallback = HDMI1
monitor-strict = false
bottom = false
fixed-center = true
width = 100%
height = 20
;offset-x = 1%
;offset-y = 1%
background = ${colors.background}
foreground = ${colors.foreground}
; Background gradient (vertical steps)
; background-[0-9]+ = #aarrggbb
radius = 0.0
line-size = 2
line-color = #000000
;border-size = 0
;border-left-size = 25
;border-right-size = 25
;border-top-size = 10
;border-bottom-size = 25
border-color = #000000
padding-left = 1
padding-right = 1
module-margin-left = 0
module-margin-right = 0
;https://github.com/jaagr/polybar/wiki/Fonts
font-0 = "UbuntuMono Nerd Font Mono:style=Regular:size=10;2"
font-1 = "UbuntuMono Nerd Font:size=16;3"
font-2 = "Font Awesome 5 Free:style=Regular:pixelsize=8;1"
font-3 = "Font Awesome 5 Free:style=Solid:pixelsize=8;1"
font-4 = "Font Awesome 5 Brands:pixelsize=8;1"
modules-left = i3 spotify1
modules-center = date
modules-right = xkeyboard wifi pulseaudio battery
separator = " : "
tray-position = left
tray-detached = false
tray-maxsize = 20
tray-background = ${colors.background}
tray-offset-x = 0
tray-offset-y = 0
tray-padding = 4
tray-scale = 1.0
; Enable support for inter-process messaging
; See the Messaging wiki page for more details.
enable-ipc = true
; Fallback click handlers that will be called if
; there's no matching module handler found.
click-left =
click-middle =
click-right =
scroll-up = i3wm-wsnext
scroll-down = i3wm-wsprev
double-click-left =
double-click-middle =
double-click-right =
; Requires polybar to be built with xcursor support (xcb-util-cursor)
; Possible values are:
; - default : The default pointer as before, can also be an empty string (default)
; - pointer : Typically in the form of a hand
; - ns-resize : Up and down arrows, can be used to indicate scrolling
cursor-click =
cursor-scroll =
[module/xwindow]
type = internal/xwindow
label = %title:0:30:...%
[module/xkeyboard]
type = internal/xkeyboard
blacklist-0 = num lock
format = <label-indicator> <label-layout>
format-foreground = ${colors.foreground-alt}
format-prefix =
format-prefix-foreground = ${colors.background}
format-prefix-underline = ${colors.secondary}
label-layout = %layout%
;label-layout-underline = ${colors.secondary}
label-indicator-padding = 2
label-indicator-margin = 1
label-indicator-background = ${colors.secondary}
label-indicator-underline = ${colors.secondary}
[module/filesystem]
type = internal/fs
interval = 25
mount-0 = /
label-mounted = %{F#0a81f5}%mountpoint%%{F-}: %percentage_used%%
label-unmounted = %mountpoint% not mounted
label-unmounted-foreground = ${colors.foreground-alt}
[module/bspwm]
type = internal/bspwm
label-focused = %index%
label-focused-background = ${colors.background-alt}
label-focused-underline= ${colors.primary}
label-focused-padding = 2
label-occupied = %index%
label-occupied-padding = 2
label-urgent = %index%!
label-urgent-background = ${colors.alert}
label-urgent-padding = 2
label-empty = %index%
label-empty-foreground = ${colors.foreground-alt}
label-empty-padding = 2
; Separator in between workspaces
; label-separator = |
[module/i3]
type = internal/i3
format = <label-state> <label-mode>
index-sort = true
wrapping-scroll = false
; Only show workspaces on the same output as the bar
;pin-workspaces = true
label-mode-padding = 2
label-mode-foreground = #000
label-mode-background = ${colors.primary}
; focused = Active workspace on focused monitor
label-focused = %index%
label-focused-background = ${colors.background-alt}
label-focused-underline= ${colors.secondary}
label-focused-padding = 2
; unfocused = Inactive workspace on any monitor
label-unfocused = %index%
label-unfocused-padding = 2
; visible = Active workspace on unfocused monitor
label-visible = %index%
label-visible-background = ${self.label-focused-background}
label-visible-underline = ${colors.primary}
label-visible-padding = ${self.label-focused-padding}
; urgent = Workspace with urgency hint set
label-urgent = %index%
label-urgent-background = ${colors.alert}
label-urgent-padding = 2
[module/xbacklight]
type = internal/xbacklight
format = <label> <bar>
label = BL
bar-width = 10
bar-indicator = |
bar-indicator-foreground = #fff
bar-indicator-font = 2
bar-fill = ─
bar-fill-font = 2
bar-fill-foreground = #9f78e1
bar-empty = ─
bar-empty-font = 2
bar-empty-foreground = ${colors.foreground-alt}
[module/date]
type = internal/date
interval = 1
date = %A, %d %B %Y
time = %H:%M:%S
time-alt = %H:%M:%S %Z (%z)
date-alt = %Y-%m-%d
format-prefix =
format-prefix-foreground = ${colors.foreground-alt}
format-underline =
label = %date% · %time%
[module/pulseaudio]
type = internal/pulseaudio
format-volume = <label-volume> <bar-volume>
label-volume = VOL %percentage%%
label-volume-foreground = ${colors.foreground-alt}
label-muted = muted
label-muted-foreground = #666
bar-volume-width = 10
bar-volume-foreground-0 = #55aa55
bar-volume-foreground-1 = #55aa55
bar-volume-foreground-2 = #55aa55
bar-volume-foreground-3 = #55aa55
bar-volume-foreground-4 = #55aa55
bar-volume-foreground-5 = #f5a70a
bar-volume-foreground-6 = #ff5555
bar-volume-gradient = false
bar-volume-indicator = |
bar-volume-indicator-font = 0
bar-volume-fill = -
bar-volume-fill-font = 0
bar-volume-empty = -
bar-volume-empty-font = 0
bar-volume-empty-foreground = ${colors.foreground-alt}
[module/battery]
type = internal/battery
battery = BAT0
adapter = AC
full-at = 98
format-charging-prefix = "▴"
format-charging = <label-charging>
format-charging-foreground = #55aa55
;format-charging = <animation-charging> <label-charging>
format-charging-underline =
;format-discharging = <animation-discharging> <label-discharging>
format-discharging-prefix = "▾"
format-discharging = <label-discharging>
format-discharging-foreground = #f5a70a
format-discharging-underline =
format-full = FULL BATTERY
;format-full-prefix = "▪"
format-full-foreground = #55aa55
format-full-underline = ${self.format-charging-underline}
ramp-capacity-0 = 
ramp-capacity-1 = 
ramp-capacity-2 = 
ramp-capacity-foreground = ${colors.foreground-alt}
[module/spotify1]
type = custom/script
interval = 1
exec = ~/.config/polybar/scripts/spotify.sh
;format = <label>
format-foreground = ${colors.foreground-alt}
format-background = ${colors.background}
format-padding = 2
format-underline =
format-prefix = " "
format-prefix-foreground = ${colors.foreground-alt}
label = %output:0:70%
[module/wifi]
type = custom/script
;tail = false
interval = 5
exec = ~/.config/polybar/scripts/wifi_status.py
;double-click-right = nmcli device wifi rescan
double-click-left = ~/.config/polybar/scripts/wifi_connect.py
;format = <label>
format-foreground = ${colors.foreground-alt}
format-background = ${colors.background}
format-padding = 0
format-underline =
format-prefix-foreground = ${colors.foreground-alt}
label = %output:0:40%
[settings]
screenchange-reload = true
;compositing-background = xor
;compositing-background = screen
;compositing-foreground = source
;compositing-border = over
;pseudo-transparency = false
[global/wm]
margin-top = 5
margin-bottom = 5

14
.config/polybar/launch.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Terminate already running bar instances
killall -q polybar
# Wait until the processes have been shut down
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
for m in $(polybar --list-monitors | cut -d":" -f1); do
WIRELESS=$(ls /sys/class/net/ | grep ^wl | awk 'NR==1{print $1}') MONITOR=$m polybar --reload mainbar-i3 &
done
echo "Bars launched..."

View 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)

View 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 "$@"

View 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)

View 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)