summaryrefslogtreecommitdiff
path: root/polybar
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2019-12-02 12:21:04 +0000
committerShubham Saini <shubham6405@gmail.com>2019-12-02 12:21:04 +0000
commita42df546ce34429759a20bc2c4c240de045dbd0a (patch)
tree4e7153d41d6a1b710f8002f2eb7b64231889b6cf /polybar
using stow
Diffstat (limited to 'polybar')
-rwxr-xr-xpolybar/.config/polybar/cmus.sh20
-rw-r--r--polybar/.config/polybar/config201
-rwxr-xr-xpolybar/.config/polybar/launch.sh12
-rw-r--r--polybar/.config/polybar/spotify.py123
4 files changed, 356 insertions, 0 deletions
diff --git a/polybar/.config/polybar/cmus.sh b/polybar/.config/polybar/cmus.sh
new file mode 100755
index 0000000..7917d4c
--- /dev/null
+++ b/polybar/.config/polybar/cmus.sh
@@ -0,0 +1,20 @@
1#!/bin/bash
2
3prepend_zero () {
4 seq -f "%02g" $1 $1
5}
6
7artist=$(echo -n $(cmus-remote -C status | grep "tag artist" | cut -c 12-))
8
9if [[ $artist = *[!\ ]* ]]; then
10 song=$(echo -n $(cmus-remote -C status | grep title | cut -c 11-))
11 position=$(cmus-remote -C status | grep position | cut -c 10-)
12 minutes1=$(prepend_zero $(($position / 60)))
13 seconds1=$(prepend_zero $(($position % 60)))
14 duration=$(cmus-remote -C status | grep duration | cut -c 10-)
15 minutes2=$(prepend_zero $(($duration / 60)))
16 seconds2=$(prepend_zero $(($duration % 60)))
17 echo -n "$artist - $song [$minutes1:$seconds1/$minutes2:$seconds2]"
18else
19 echo
20fi
diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config
new file mode 100644
index 0000000..440e75a
--- /dev/null
+++ b/polybar/.config/polybar/config
@@ -0,0 +1,201 @@
1[settings]
2screenchange-reload = true
3
4[colors]
5#background = ${xrdb:color0:#222}
6background = ${xrdb:background:#09090d}
7background-alt = ${xrdb:color0:#000}
8;foreground = ${xrdb:color7:#222}
9foreground = ${xrdb:foreground:#dfdfdf}
10foreground-alt = ${xrdb:colorBD:#444}
11primary = ${xrdb:color4:#ffb52a}
12secondary = ${xrdb:color3:#e60053}
13alert = ${xrdb:color1:#bd2c40}
14
15[bar/top]
16;monitor = ${env:MONITOR:HDMI-1}
17width = 100%
18height = 20
19;offset-x = 1%
20;offset-y = 1%
21radius = 0
22fixed-center = false
23bottom = false
24background = ${colors.background}
25foreground = ${colors.foreground}
26line-size = 3
27line-color = #f00
28border-size = 0
29border-color = #00000000
30padding-left = 2
31padding-right = 2
32module-margin-left = 1.5
33module-margin-right = 1.5
34font-0 = Hermit:style=medium:pixelsize=10;1
35font-1 = Font Awesome:style=Regular:size=10;0
36font-2 = fixed:pixelsize=10;1
37font-3 = unifont:fontformat=truetype:size=15:antialias=false;0
38font-4 = siji:pixelsize=10;1
39modules-left = pulseaudio battery date time bspwm
40modules-center =
41modules-right = spotify cmus xwindow
42tray-position = right
43cursor-click = pointer
44cursor-scroll = ns-resize
45
46[module/xwindow]
47type = internal/xwindow
48label = %title:0:20:...%
49
50
51[module/bspwm]
52type = internal/bspwm
53format = <label-state> <label-mode>
54index-sort = true
55wrapping-scroll = false
56
57; Only show workspaces on the same output as the bar
58pin-workspaces = true
59
60ws-icon-0 = term;
61ws-icon-1 = web;
62ws-icon-2 = music;ﱘ
63ws-icon-3 = files;
64ws-icon-4 = code;
65ws-icon-5 = virt;ﮊ
66ws-icon-6 = chat;
67ws-icon-7 = game;戮
68ws-icon-default = 
69
70label-focused = %name%
71label-focused-foreground = ${xrdb:color4:#8c5760}
72label-focused-padding = 1
73;label-focused-font = 10
74
75label-occupied = %name%
76label-occupied-foreground = ${xrdb:color15:#839496}
77label-occupied-padding = 1
78
79label-empty =
80label-empty-foreground = ${xrdb:color1:#bd2c40}
81label-empty-padding = 1
82
83; urgent = Workspace with urgency hint set
84label-urgent = 
85label-urgent-foreground = ${xrdb:color1:#bd2c40}
86label-urgent-padding = 1
87
88; Separator in between workspaces
89;label-separator = |
90
91[module/wlan]
92type = internal/network
93interface = wlo1
94interval = 3.0
95format-connected = <label-connected>
96label-connected =  %essid%
97label-font = 1
98label-connected-background = ${colors.background}
99label-connected-padding = 0
100format-disconnected =
101
102[module/eth]
103type = internal/network
104interface = eno1
105interval = 3.0
106format-connected-underline = ${xrdb:color11:#55aa55}
107;format-connected-prefix =
108format-connected-prefix-foreground = ${colors.foreground-alt}
109label-connected =  %local_ip% ↑%upspeed% ↓%downspeed%
110format-disconnected =
111
112[module/time]
113type = internal/date
114interval = 1.0
115date = %I:%M %p
116
117[module/date]
118type = internal/date
119date = %a, %d %b
120label = %date%
121
122[module/battery]
123type = internal/battery
124battery = BAT0
125adapter = ADP1
126poll-interval = 1
127full-at = 98
128label-discharging = %percentage%%
129label-charging = %percentage%%
130label-full = %percentage%%
131format-discharging = <ramp-capacity> <label-discharging>
132format-full = <ramp-capacity> <label-full>
133format-charging =  <label-charging>
134ramp-capacity-0 = 
135ramp-capacity-1 = 
136ramp-capacity-2 = 
137ramp-capacity-3 = 
138ramp-capacity-4 = 
139
140[module/pulseaudio]
141type = internal/pulseaudio
142format-volume = <ramp-volume> <label-volume>
143label-volume = %percentage%%
144label-muted =  muted
145ramp-volume-0 = 
146ramp-volume-1 = 
147ramp-volume-2 = 
148
149[module/spotify]
150type = custom/script
151interval = 1
152format-prefix = " "
153format = <label>
154format-foreground = #7b8c58
155exec = python ~/.config/polybar/spotify.py -f '{artist}: {song}'
156
157[module/cmus]
158type = custom/script
159exec = ~/.config/polybar/cmus.sh
160exec-if = pgrep -x cmus
161interval = 1
162click-left = cmus-remote --next
163click-right = cmus-remote --prev
164click-middle = cmus-remote --pause
165scroll-up = cmus-remote --volume +5%
166scroll-down = cmus-remote --volume -5%
167format = <label>
168format-prefix = " "
169format-foreground = #7b8c58
170label = %output%
171label-maxlen = 50
172
173[module/mpd]
174type = internal/mpd
175label-offline = mpd is offline
176format-online = <label-song> <icon-prev> <toggle> <icon-next>
177format-offline = <label-offline>
178host = 127.0.0.1
179port = 6600
180icon-prev = 
181icon-stop = 
182icon-play = 
183icon-pause = 
184icon-next = 
185label-song-maxlen = 25
186label-song-ellipsis = true
187bar-progress-width = 10
188bar-progress-indicator = |
189bar-progress-fill = ─
190bar-progress-empty = ─
191
192[module/backlight]
193type = internal/backlight
194; Use the following command to list available cards:
195; $ ls -1 /sys/class/backlight/
196card = intel_backlight
197format = <ramp> <label>
198label = %percentage%%
199ramp-0 = 
200ramp-1 = 
201ramp-2 = 
diff --git a/polybar/.config/polybar/launch.sh b/polybar/.config/polybar/launch.sh
new file mode 100755
index 0000000..c39a374
--- /dev/null
+++ b/polybar/.config/polybar/launch.sh
@@ -0,0 +1,12 @@
1#!/usr/bin/env bash
2
3# Terminate already running bar instances
4killall -q polybar
5
6# Wait until the processes have been shut down
7while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
8
9# Launch bar1 and bar2
10polybar top &
11
12echo "Bars launched..."
diff --git a/polybar/.config/polybar/spotify.py b/polybar/.config/polybar/spotify.py
new file mode 100644
index 0000000..aae6d81
--- /dev/null
+++ b/polybar/.config/polybar/spotify.py
@@ -0,0 +1,123 @@
1#!/bin/python
2
3import sys
4import dbus
5import argparse
6
7
8parser = argparse.ArgumentParser()
9parser.add_argument(
10 '-t',
11 '--trunclen',
12 type=int,
13 metavar='trunclen'
14)
15parser.add_argument(
16 '-f',
17 '--format',
18 type=str,
19 metavar='custom format',
20 dest='custom_format'
21)
22parser.add_argument(
23 '-p',
24 '--playpause',
25 type=str,
26 metavar='play-pause indicator',
27 dest='play_pause'
28)
29parser.add_argument(
30 '--font',
31 type=str,
32 metavar='the index of the font to use for the main label',
33 dest='font'
34)
35parser.add_argument(
36 '--playpause-font',
37 type=str,
38 metavar='the index of the font to use to display the playpause indicator',
39 dest='play_pause_font'
40)
41
42
43args = parser.parse_args()
44
45def fix_string(string):
46 # corrects encoding for the python version used
47 if sys.version_info.major == 3:
48 return string
49 else:
50 return string.encode('utf-8')
51
52# Default parameters
53output = fix_string(u'{play_pause} {artist}: {song}')
54trunclen = 25
55play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused
56
57label_with_font = '%{{T{font}}}{label}%{{T-}}'
58font = args.font
59play_pause_font = args.play_pause_font
60
61# parameters can be overwritten by args
62if args.trunclen is not None:
63 trunclen = args.trunclen
64if args.custom_format is not None:
65 output = args.custom_format
66if args.play_pause is not None:
67 play_pause = args.play_pause
68
69try:
70 session_bus = dbus.SessionBus()
71 spotify_bus = session_bus.get_object(
72 'org.mpris.MediaPlayer2.spotify',
73 '/org/mpris/MediaPlayer2'
74 )
75
76 spotify_properties = dbus.Interface(
77 spotify_bus,
78 'org.freedesktop.DBus.Properties'
79 )
80
81 metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
82 status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
83
84 # Handle play/pause label
85
86 play_pause = play_pause.split(',')
87
88 if status == 'Playing':
89 play_pause = play_pause[0]
90 elif status == 'Paused':
91 play_pause = play_pause[1]
92 else:
93 play_pause = str()
94
95 if play_pause_font:
96 play_pause = label_with_font.format(font=play_pause_font, label=play_pause)
97
98 # Handle main label
99
100 artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else ''
101 song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else ''
102
103 if not artist and not song:
104 print('')
105 else:
106 if len(song) > trunclen:
107 song = song[0:trunclen]
108 song += '...'
109 if ('(' in song) and (')' not in song):
110 song += ')'
111
112 if font:
113 artist = label_with_font.format(font=font, label=artist)
114 song = label_with_font.format(font=font, label=song)
115
116 print(output.format(artist=artist, song=song, play_pause=play_pause))
117
118except Exception as e:
119 if isinstance(e, dbus.exceptions.DBusException):
120 print('')
121 else:
122 print(e)
123