From d2386bca8da95705e028db000eddcc7f831c8132 Mon Sep 17 00:00:00 2001 From: Mahesh Asolkar Date: Sun, 16 May 2021 11:31:19 -0700 Subject: [PATCH] Changes for DWL on Arch --- dwl.session | 37 ++++++++++++ dwltags.pl | 122 ++++++++++++++++++++++++++++++++++++++++ leave_session.laptop.sh | 10 +++- tmux_status.laptop | 5 +- user.bash_aliases | 2 + user.conkyrc | 4 +- 6 files changed, 175 insertions(+), 5 deletions(-) create mode 100755 dwl.session create mode 100755 dwltags.pl diff --git a/dwl.session b/dwl.session new file mode 100755 index 0000000..33d1e48 --- /dev/null +++ b/dwl.session @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +export WLR_LIBINPUT_NO_DEVICES=1 +export PATH=~/bin:$PATH + +export DWLTAGS_FILE=/tmp/dwl.tags.$USER.out +# export DWLTAGS_FMT=TXT # Waybar uses this +export DWLTAGS_FMT=DZEN + +# Clean up +ps aux | grep $USER | grep wl_show_bars | awk '{ print $2 }' | xargs -n 1 kill -9 +ps aux | grep $USER | grep dtao | awk '{ print $2 }' | xargs -n 1 kill -9 +rm $DWLTAGS_FILE + +(/usr/local/bin/dwl | dwltags.pl) & + +# Let DWL start +while [ ! -e "$XDG_RUNTIME_DIR/wayland-0.lock" ] +do + echo "DWL getting ready..." + sleep 1 +done +echo "DWL ready!" + +# Top bar for displaying DWL tags +# TODO: Dependency - needs inotify-tools package +inotifywait -q -m -e close_write $DWLTAGS_FILE | + (cat $DWLTAGS_FILE ; + while read -r filename event; do + cat $DWLTAGS_FILE + done) | dtao -z -z -ta l -h 22 -fn 'Iosevka Term:style=Regular:size=12' & + +# Bottom bar for displaying context information +(conky -c ~/.conkyrc) | dtao -b -z -z -ta r -h 20 -fn 'Iosevka Term:style=Regular:size=12' & + +# Background +swaybg --mode fill --image ~/.config/wallpaper.jpg & diff --git a/dwltags.pl b/dwltags.pl new file mode 100755 index 0000000..bafef6b --- /dev/null +++ b/dwltags.pl @@ -0,0 +1,122 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Data::Dumper; +use Term::ANSIColor; +use FileHandle; + +my $info = {}; + +# Color scheme is only used in ANSI mode +# _f/_g: class is used in JSON mode to be used in style.css for styling +my $colorscheme = { + 'norm_f' => '#ffffff', + 'norm_b' => '#111111', + 'sel_f' => '#ffffff', + 'sel_b' => '#aa4444', + 'mon_f' => '#000000', + 'mon_b' => '#777777', + 'lay_f' => '#111111', + 'lay_b' => '#77aaaa', + 'title_f' => '#ffcccc', + 'title_b' => '#111111' + # 'norm_f' => 'white', + # 'norm_b' => 'black', + # 'sel_f' => 'black', + # 'sel_b' => 'red', + # 'mon_f' => 'black', + # 'mon_b' => 'grey23', + # 'lay_f' => 'black', + # 'lay_b' => 'cyan', + # 'title_f' => 'red', + # 'title_b' => 'black' +}; + +print_tags({ + 'selmon' => '1', + 'tags' => '1 1', + 'title' => '', + 'layout' => '[]=' + }); + +while (<>) { + my $line = $_; + chomp $line; + + if (my ($mon, $key, $val) = $line =~ /^(\S+)\s+(\S+)\s(.*)$/) { + $info->{$key} = $val; + if ($key eq "layout") { + # Commit a status + # Assumption: layout is the last piece of information dumped by DWL + $info->{'mon'} = $mon; + print_tags($info); + + $info = {}; + } + } else { + print "DWL: Printed out of format\n"; + } +} + +sub print_tags { + my ($info) = @_; + my $numtags = 10; + + return if ($info->{'selmon'} ne "1"); + + if (my ($tuse, $tsel) = $info->{'tags'} =~ /(\d+)\s+(\d+)/) { + my $tags = ""; + + for (my $i = 0; $i < $numtags; $i++) { + my $sel = "norm"; + if (($tuse & (1 << $i))) { + if ($tsel & (1 << $i)) { + $sel = "sel"; + } + $tags .= getformatted($sel, " ". ($i+1) . " "); + } + } + + if (exists $ENV{'DWLTAGS_SHOW_MON'}) { + $tags .= getformatted("mon", " $info->{'mon'} "); + } + + $tags .= getformatted("lay", " $info->{'layout'} "); + $tags .= getformatted("title", " $info->{'title'} "); + + my $fh = FileHandle->new("> " . $ENV{'DWLTAGS_FILE'}); + if (defined $fh) { + print $fh $tags . "\n"; + $fh->close; + } + } else { + print "DWL: Printed out of format - tags\n"; + } +} + +sub getformatted { + my ($c, $txt) = @_; + + if ((exists $ENV{'DWLTAGS_FMT'}) && ($ENV{'DWLTAGS_FMT'} eq "DZEN")) { + return dzen_colored($c, $txt); + } elsif ((exists $ENV{'DWLTAGS_FMT'}) && ($ENV{'DWLTAGS_FMT'} eq "ANSI")) { + return colored([$colorscheme->{$c . '_f'} . " on_" . $colorscheme->{$c . '_b'}], $txt); + } elsif ((exists $ENV{'DWLTAGS_FMT'}) && ($ENV{'DWLTAGS_FMT'} eq "JSON")) { + return '{"text": "' . $txt . '", "class": "dwltags-' . $c . '"}'; + } else { + if ($c eq "sel") { + $txt =~ s/\s+//g; + $txt = "[$txt]"; + } + return $txt; + } +} + +sub dzen_colored { + my ($class, $txt) = @_; + my $fc = $colorscheme->{$class . '_f'}; + my $bc = $colorscheme->{$class . '_b'}; + # return colored([$colorscheme->{$c . '_f'} . " on_" . $colorscheme->{$c . '_b'}], $txt); + return "^fg(" . $fc . ")^bg(" . $bc . ")" . $txt . "^fg()^bg()"; +} diff --git a/leave_session.laptop.sh b/leave_session.laptop.sh index a5446ce..4da8368 100755 --- a/leave_session.laptop.sh +++ b/leave_session.laptop.sh @@ -6,8 +6,14 @@ # # username ALL=(ALL:ALL) NOPASSWD:/usr/sbin/pm-suspend,/usr/sbin/pm-hibernate,/sbin/reboot,/sbin/shutdown # +if [[ -v WAYLAND_DISPLAY ]]; then + DMCMD='wofi -d -p' +else + DMCMD='dmenu -p' +fi + confirm() { - ans=$(echo -e "Yes\nNo" | dmenu -p "$1 - Confirm?") + ans=$(echo -e "Yes\nNo" | $DMCMD "$1 - Confirm?") echo $ans if [ "$ans" = "Yes" ]; then echo "Leaving..." @@ -17,7 +23,7 @@ confirm() { fi } -cmd=$(echo -e "hibernate\nsuspend\nreboot\nshutdown" | dmenu -p "Leave session:") +cmd=$(echo -e "hibernate\nsuspend\nreboot\nshutdown" | $DMCMD "Leave session:") echo $cmd diff --git a/tmux_status.laptop b/tmux_status.laptop index 4685d5d..3b98873 100755 --- a/tmux_status.laptop +++ b/tmux_status.laptop @@ -7,10 +7,11 @@ VOL=$(amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/') LOCALTIME=$(date +"%Y %h %d %I:%M%p %Z") IP=$(for i in `ip r`; do echo $i; done | grep -A 1 src | tail -n1) -WEATHER=$(weather fips4105192520 | grep Tempera | awk '{print $2}') +# WEATHER=$(weather fips4105192520 | grep Tempera | awk '{print $2}') +WEATHER=$(curl wttr.in/45.54,-122.83?format="%c%t") BAT=$(acpi -b | awk '{ print $4 " " $5 }' | tr -d ',') -echo "$IP  ${WEATHER}°F" +echo "$IP  ${WEATHER}" #sleep 30 diff --git a/user.bash_aliases b/user.bash_aliases index 8eb05d5..e09ae63 100644 --- a/user.bash_aliases +++ b/user.bash_aliases @@ -4,6 +4,8 @@ # If git-prompt does not exist, get it with following command: # # $ wget https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh +[ -r /usr/share/bash-completion/completions/git ] && . /usr/share/bash-completion/completions/git + if [ -f /etc/bash_completion.d/git-prompt ]; then source /etc/bash_completion.d/git-prompt fi diff --git a/user.conkyrc b/user.conkyrc index fe36189..8d4f4e0 100644 --- a/user.conkyrc +++ b/user.conkyrc @@ -43,12 +43,14 @@ ${if_existing /sys/class/net/enp3s0/operstate up}🌐 ${addr enp3s0}${else}\ ${if_existing /sys/class/net/wlp4s0/operstate up}📶 ${addr wlp4s0}${else}\ ${if_up eth0}🌐 ${addr eth0}${else}\ network down ${endif}${endif}${endif} | \ -🌡 ${execi 600 weather fips4105192520 | grep Tempera | awk '{print $2}'}°F | \ +${execi 600 curl wttr.in/45.54,-122.83?format="%c%t"} | \ 🔊 ${execi 10 amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/'} | \ 🔋 ${battery_percent}% | \ ${time %Y %h %d %I:%M%p %Z} ]] --[[ +🌡 ${execi 600 weather fips4105192520 | grep Tempera | awk '{print $2}'}°F | \ +${execi 1 cat /tmp/dwl.tags.mahesh.out} | \ 🌦 ${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ KHIO temperature 10} | \ 🔋apcupsd_charge${execi 60 acpi -b | awk '{ print " " $5 }' | tr -d ','} | \ ${color grey}Info:$color ${scroll 32 Conky $conky_version - $sysname $nodename $kernel $machine}