~aodag/dotfiles

cf265dc2ba4fefe5751dd1d46602e38e95cd9264 — Atsushi Odagiri 4 months ago 21647e8
i3blocks
A config/i3blocks/config => config/i3blocks/config +153 -0
@@ 0,0 1,153 @@
# i3blocks config file
#
# Please see man i3blocks for a complete reference!
# The man page is also hosted at http://vivien.github.io/i3blocks
#
# List of valid properties:
#
# align
# color
# command
# full_text
# instance
# interval
# label
# min_width
# name
# separator
# separator_block_width
# short_text
# signal
# urgent

# Global properties
#
# The top properties below are applied to every block, but can be overridden.
# Each block command defaults to the script name to avoid boilerplate.
command=/usr/share/i3blocks/$BLOCK_NAME
separator_block_width=15
markup=none

[sway-focusedwindow]
command=$SCRIPT_DIR/sway-focusedwindow 200 center
interval=persist

[mediaplayer]
command=$SCRIPT_DIR/mediaplayer
label=♪
instance=spotify
interval=5
signal=10

# Volume indicator
#
# The first parameter sets the step (and units to display)
# The second parameter overrides the mixer selection
# See the script for details.
[volume]
label=VOL
label=♪
instance=Master
#instance=PCM
interval=once
signal=10

# Memory usage
#
# The type defaults to "mem" if the instance is not specified.
[memory]
label=MEM
separator=false
interval=30

[memory]
label=SWAP
instance=swap
separator=false
interval=30

# Disk usage
#
# The directory defaults to $HOME if the instance is not specified.
# The script may be called with a optional argument to set the alert
# (defaults to 10 for 10%).
[disk]
label=HOME
#instance=/mnt/data
interval=30

# Network interface monitoring
#
# If the instance is not specified, use the interface used for default route.
# The address can be forced to IPv4 or IPv6 with -4 or -6 switches.
[iface]
#instance=wlan0
color=#00FF00
interval=10
separator=false

[wifi]
#instance=wlp3s0
interval=10
separator=false

[bandwidth]
#instance=eth0
interval=5

# CPU usage
#
# The script may be called with -w and -c switches to specify thresholds,
# see the script for details.
[cpu_usage]
label=CPU
interval=10
min_width=CPU: 100.00%
separator=false

[load_average]
interval=10

# Battery indicator
#
# The battery instance defaults to 0.
# [battery]
# label=BAT
# #label=⚡
# #instance=1
# interval=30

# Date Time
#
[time]
command=date '+%Y-%m-%d %H:%M'
interval=5

# Support multiple VPN, with colors.
#[openvpn]
#interval=20

# Temperature
#
# Support multiple chips, though lm-sensors.
# The script may be called with -w and -c switches to specify thresholds,
# see the script for details.
#[temperature]
#label=TEMP
#interval=10

# Key indicators
#
# Add the following bindings to i3 config file:
#
# bindsym --release Caps_Lock exec pkill -SIGRTMIN+11 i3blocks
# bindsym --release Num_Lock  exec pkill -SIGRTMIN+11 i3blocks
#[keyindicator]
#instance=CAPS
#interval=once
#signal=11

#[keyindicator]
#instance=NUM
#interval=once
#signal=11

A config/i3blocks/mediaplayer => config/i3blocks/mediaplayer +159 -0
@@ 0,0 1,159 @@
#!/usr/bin/env perl
# Copyright (C) 2014 Tony Crisci <tony@dubstepdish.com>
# Copyright (C) 2015 Thiago Perrotta <perrotta dot thiago at poli dot ufrj dot br>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# For all media players except mpd/cmus/rhythmbox, MPRIS support should be
# enabled and the playerctl binary should be in your path.
# See https://github.com/acrisci/playerctl

# Set instance=NAME in the i3blocks configuration to specify a music player
# (playerctl will attempt to connect to org.mpris.MediaPlayer2.[NAME] on your
# DBus session). If instance is empty, playerctl will connect to the first
# supported media player it finds.

use Time::HiRes qw(usleep);
use Env qw(BLOCK_INSTANCE);

use constant DELAY => 50; # Delay in ms to let network-based players (spotify) reflect new data.
use constant SPOTIFY_STR => 'spotify';

my @metadata = ();
my $player_arg = "";

if ($BLOCK_INSTANCE) {
    $player_arg = "--player='$BLOCK_INSTANCE'";
}

sub buttons {
    my $method = shift;

    if($method eq 'mpd') {
        if ($ENV{'BLOCK_BUTTON'} == 1) {
            system("mpc prev &>/dev/null");
        } elsif ($ENV{'BLOCK_BUTTON'} == 2) {
            system("mpc toggle &>/dev/null");
        } elsif ($ENV{'BLOCK_BUTTON'} == 3) {
            system("mpc next &>/dev/null");
        } elsif ($ENV{'BLOCK_BUTTON'} == 4) {
            system("mpc volume +10 &>/dev/null");
        } elsif ($ENV{'BLOCK_BUTTON'} == 5) {
            system("mpc volume -10 &>/dev/null");
        }
    } elsif ($method eq 'cmus') {
        if ($ENV{'BLOCK_BUTTON'} == 1) {
            system("cmus-remote --prev");
        } elsif ($ENV{'BLOCK_BUTTON'} == 2) {
            system("cmus-remote --pause");
        } elsif ($ENV{'BLOCK_BUTTON'} == 3) {
            system("cmus-remote --next");
        }
    } elsif ($method eq 'playerctl') {
        if ($ENV{'BLOCK_BUTTON'} == 1) {
            system("playerctl $player_arg previous");
            usleep(DELAY * 1000) if $BLOCK_INSTANCE eq SPOTIFY_STR;
        } elsif ($ENV{'BLOCK_BUTTON'} == 2) {
            system("playerctl $player_arg play-pause");
        } elsif ($ENV{'BLOCK_BUTTON'} == 3) {
            system("playerctl $player_arg next");
            usleep(DELAY * 1000) if $BLOCK_INSTANCE eq SPOTIFY_STR;
        } elsif ($ENV{'BLOCK_BUTTON'} == 4) {
            system("playerctl $player_arg volume 0.01+");
        } elsif ($ENV{'BLOCK_BUTTON'} == 5) {
            system("playerctl $player_arg volume 0.01-");
        }
    } elsif ($method eq 'rhythmbox') {
        if ($ENV{'BLOCK_BUTTON'} == 1) {
            system("rhythmbox-client --previous");
        } elsif ($ENV{'BLOCK_BUTTON'} == 2) {
            system("rhythmbox-client --play-pause");
        } elsif ($ENV{'BLOCK_BUTTON'} == 3) {
            system("rhythmbox-client --next");
        }
    }
}

sub cmus {
    my @cmus = split /^/, qx(cmus-remote -Q);
    if ($? == 0) {
        foreach my $line (@cmus) {
            my @data = split /\s/, $line;
            if (shift @data eq 'tag') {
                my $key = shift @data;
                my $value = join ' ', @data;

                @metadata[0] = $value if $key eq 'artist';
                @metadata[1] = $value if $key eq 'title';
            }
        }

        if (@metadata) {
            buttons('cmus');

            # metadata found so we are done
            print(join ' - ', @metadata);
            print("\n");
            exit 0;
        }
    }
}

sub mpd {
    my $data = qx(mpc current);
    if (not $data eq '') {
        buttons("mpd");
        print($data);
        exit 0;
    }
}

sub playerctl {
    buttons('playerctl');

    my $artist = qx(playerctl $player_arg metadata artist 2>/dev/null);
    chomp $artist;
    # exit status will be nonzero when playerctl cannot find your player
    exit(0) if $? || $artist eq '(null)';

    push(@metadata, $artist) if $artist;

    my $title = qx(playerctl $player_arg metadata title);
    exit(0) if $? || $title eq '(null)';

    push(@metadata, $title) if $title;

    print(join(" - ", @metadata)) if @metadata;
}

sub rhythmbox {
    buttons('rhythmbox');

    my $data = qx(rhythmbox-client --print-playing --no-start);
    print($data);
}

if ($player_arg =~ /mpd/) {
    mpd;
}
elsif ($player_arg =~ /cmus/) {
    cmus;
}
elsif ($player_arg =~ /rhythmbox/) {
    rhythmbox;
}
else {
    playerctl;
}
print("\n");
\ No newline at end of file

A config/i3blocks/sway-focusedwindow => config/i3blocks/sway-focusedwindow +47 -0
@@ 0,0 1,47 @@
#!/usr/bin/env bash

maxlen=0
if [[ $1 ]]; then
  maxlen=$1
fi

align="center"
if [[ $2 ]]; then
  align=$2
fi

format() {
  if [[ $maxlen == 0 ]]; then
    echo "$1"
    return 0
  fi
  len=${#1}
  if [[ $len -ge $maxlen ]]; then
    echo "${1:0:${maxlen}}"
  else
    pad=$(( maxlen - len ))
    case "$align" in
      "center" )
        pad=$(( pad / 2 ))
        printf "%*s%s%*s\n" $pad "" "$1" $pad ""
        ;;
      "left" )
        printf "%s%*s\n" "$1" $pad "" 
        ;;
      "right" )
        printf "%*s%s\n" $pad "" "$1"
        ;;
    esac
  fi
}

process() {
  while read -r LINE; do
    format "$LINE"
  done
}

swaymsg -t get_tree | jq --unbuffered -r '.. | select(.focused?) | .name' | process

subscribe_query='select(.container.focused and (.change == "focus" or .change == "title")) | .container.name'
swaymsg -m -t SUBSCRIBE "['window']" | jq --unbuffered -r "$subscribe_query" | process
\ No newline at end of file

M config/sway/config => config/sway/config +16 -14
@@ 31,6 31,7 @@ include /etc/sway/config-vars.d/*
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
# output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
output * bg ~/Pictures/1920x1080xd6abd539a5856c02825889.jpg fill
#
# Example configuration:
#


@@ 226,22 227,23 @@ bindsym $mod+Ctrl+p  exec grimshot save window
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
# bar {
#     position top
# 
#     # When the status_command prints a new line to stdout, swaybar updates.
#     # The default just shows the current date and time.
#     status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
# 
#     colors {
#         statusline #ffffff
#         background #323232
#         inactive_workspace #32323200 #32323200 #5c5c5c
#     }
# }
bar {
    swaybar_command waybar
    position top

    # When the status_command prints a new line to stdout, swaybar updates.
    # The default just shows the current date and time.
    # status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
    status_command SCRIPT_DIR=~/.config/i3blocks i3blocks

    colors {
        statusline #ffffff
        background #323232
        inactive_workspace #32323200 #32323200 #5c5c5c
    }
}
# bar {
#     swaybar_command waybar
# }

include /etc/sway/config.d/*
for_window [class="Conky"] border none