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