Merge branch 'master' of ssh://git@git.john.me.tz:223/jpm/scripts.git

This commit is contained in:
John Mertz 2023-01-08 22:53:51 -05:00
commit d1fbad9b82
14 changed files with 374 additions and 362 deletions

View File

@ -125,11 +125,11 @@ it to be *hidden*.
``` ```
"sway/workspaces": { "sway/workspaces": {
"format": "{icon}", "format": "{icon}",
"format-icons": { "format-icons": {
"0": "0 \uf073", // Example of workspace with a label "0": "0 \uf073", // Example of workspace with a label
"grave": "", "grave": "",
... ...
``` ```
[**sway/swayidle.sh**](https://git.john.me.tz/jpm/scripts/src/branch/master/sway/swayidle.sh) [**sway/swayidle.sh**](https://git.john.me.tz/jpm/scripts/src/branch/master/sway/swayidle.sh)

View File

@ -21,7 +21,7 @@ my @default_feeds = (
# It requires FIFO to stream. For a player that does support STDIN, uncomment # It requires FIFO to stream. For a player that does support STDIN, uncomment
# above and delete the following 4 lines # above and delete the following 4 lines
unless (-e "/tmp/fifo.mp3") { unless (-e "/tmp/fifo.mp3") {
system("mkfifo /tmp/fifo.mp3"); system("mkfifo /tmp/fifo.mp3");
} }
my $player = "> /tmp/fifo.mp3 & omxplayer /tmp/fifo.mp3"; my $player = "> /tmp/fifo.mp3 & omxplayer /tmp/fifo.mp3";

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
if [ -e /bin/which ] && [ "`which flatpak 2>/dev/null`" ]; then if [ -e /bin/which ] && [ "`which flatpak 2>/dev/null`" ]; then
flatpak run io.neovim.nvim $@ 2>/dev/null flatpak run io.neovim.nvim $@ 2>/dev/null
else else
nvim $@ nvim $@
fi fi

View File

@ -16,7 +16,7 @@ local_port=12345
show_help() show_help()
{ {
cat<<EOF cat<<EOF
Sends a video URL to Kodi Sends a video URL to Kodi
Usage: send-to-kodi.sh [URL] Usage: send-to-kodi.sh [URL]
@ -35,24 +35,24 @@ EOF
error() error()
{ {
if type zenity &>/dev/null; then if type zenity &>/dev/null; then
zenity --error --ellipsize --text "$*" zenity --error --ellipsize --text "$*"
else else
echo "$*" 1>&2 echo "$*" 1>&2
fi fi
exit 1 exit 1
} }
send_json() send_json()
{ {
curl \ curl \
${user:+--user "$user:$pass"} \ ${user:+--user "$user:$pass"} \
-X POST \ -X POST \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \ -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \
http://$host:$port/jsonrpc \ http://$host:$port/jsonrpc \
|| error "Failed to send link - is Kodi running?" || error "Failed to send link - is Kodi running?"
} }
ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid=' ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
@ -63,35 +63,35 @@ ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
# Dialog box? # Dialog box?
input=$1 input=$1
until [[ $input ]]; do until [[ $input ]]; do
input="$(zenity --entry --title "Send to Kodi" --text \ input="$(zenity --entry --title "Send to Kodi" --text \
"Paste a video link here")" || exit "Paste a video link here")" || exit
done done
if [[ $input =~ ^file:// ]]; then if [[ $input =~ ^file:// ]]; then
# Remove file:// and carrige return (\r) at the end # Remove file:// and carrige return (\r) at the end
input="$(sed 's%^file://%%;s/\r$//' <<< "$input")" input="$(sed 's%^file://%%;s/\r$//' <<< "$input")"
fi fi
# Get URL for... # Get URL for...
# Local media # Local media
if [[ -e $input ]]; then if [[ -e $input ]]; then
type nc &>/dev/null || error "netcat required" type nc &>/dev/null || error "netcat required"
[[ $local_hostname && $local_port ]] || \ [[ $local_hostname && $local_port ]] || \
error "Please set local hostname and port in configuration" error "Please set local hostname and port in configuration"
# Start netcat in background and kill it when we exit # Start netcat in background and kill it when we exit
nc -lp $local_port < "$input" & nc -lp $local_port < "$input" &
trap "kill $!" EXIT trap "kill $!" EXIT
url="tcp://$local_hostname:$local_port" url="tcp://$local_hostname:$local_port"
# youtube.com / youtu.be # youtube.com / youtu.be
elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then
url="$ytplugin$(\ url="$ytplugin$(\
sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\ sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\
<<< "$input"\ <<< "$input"\
)" )"
# Playable formats # Playable formats
elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jpg|png|gif|jpeg|tiff)(\?.*)?$ ]]; then elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jpg|png|gif|jpeg|tiff)(\?.*)?$ ]]; then
@ -99,9 +99,9 @@ elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jp
# Youtube-dl # Youtube-dl
else else
type youtube-dl &>/dev/null || error "youtube-dl required" type youtube-dl &>/dev/null || error "youtube-dl required"
url="$(youtube-dl -gf best "$input")" || \ url="$(youtube-dl -gf best "$input")" || \
error "No videos found, or site not supported by youtube-dl" error "No videos found, or site not supported by youtube-dl"
fi fi
[[ $url ]] && send_json "$url" [[ $url ]] && send_json "$url"

View File

@ -53,6 +53,7 @@ elif [ $1 == "fade" ]; then
elif [ $1 == "unfade" ]; then elif [ $1 == "unfade" ]; then
if [ -e $HOME/.spool/sway-hidden ]; then if [ -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency` kill -USR2 `cat $HOME/.spool/sway-transparency`
/home/jpm/scripts/sway/displays.pl -w
fi fi
elif [ $1 == "dim" ]; then elif [ $1 == "dim" ]; then
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE

View File

@ -32,10 +32,10 @@ elif [ "$res" == "↹ Restart i3" ]; then
i3 restart i3 restart
elif [ "$res" == "↻ Reload Sway" ]; then elif [ "$res" == "↻ Reload Sway" ]; then
sway reload sway reload
/home/jpm/scripts/sway/displays.pl /home/jpm/scripts/distrobox/debian12/displays.sh
elif [ "$res" == "↻ Reload Waybar" ]; then elif [ "$res" == "↻ Reload Waybar" ]; then
# Need to integrate with sway/displays.pl for alternative outputs # Need to integrate with sway/displays.pl for alternative outputs
/home/jpm/scripts/sway/displays.pl -w /home/jpm/scripts/distrobox/debian12/displays.sh -w
elif [ "$res" == "🡙 Reboot" ]; then elif [ "$res" == "🡙 Reboot" ]; then
rm $SSH_AUTH_SOCK rm $SSH_AUTH_SOCK
sudo systemctl reboot -i sudo systemctl reboot -i

View File

@ -20,7 +20,7 @@ export FLATPAK_IDE_LOG_LEVEL="0"
export "$( gnome-keyring-daemon --start )" export "$( gnome-keyring-daemon --start )"
#WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog #WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
WLR_RENDERER=gles2 sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog; export SWAYSOCK=`sway --get-socketpath` WLR_RENDERER=gles2 sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
#WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog #WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
#WLR_RENDERER=gles2 $HOME/build/sway/build/sway/sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog #WLR_RENDERER=gles2 $HOME/build/sway/build/sway/sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
export SWAYSOCK=`sway --get-socketpath` export SWAYSOCK=`sway --get-socketpath`

View File

@ -32,19 +32,19 @@ Sets a wallpaper by cropping an appropriate sized section of a larger image.\n
All arguments other than the below are assumed to be output names, as defined All arguments other than the below are assumed to be output names, as defined
in my sway/displays.pl script. If no outputs are provided, all available that in my sway/displays.pl script. If no outputs are provided, all available that
are currently enabled will be set.\n are currently enabled will be set.\n
--path=<path> Path to wallpaper directory. --path=<path> Path to wallpaper directory.
-p <path> Default: $ENV{HOME}/wallpapers\n -p <path> Default: $ENV{HOME}/wallpapers\n
--daemon=N Configures the wallpaper to be periodically rotated for all --daemon=N Configures the wallpaper to be periodically rotated for all
-d N of the given outputs. N indicates the number of seconds between -d N of the given outputs. N indicates the number of seconds between
each rotation, if provided (default: 300).\n each rotation, if provided (default: 300).\n
--nocrop Don't crop a selection from the image. Instead, pass the whole --nocrop Don't crop a selection from the image. Instead, pass the whole
-n image to swaybg and let it handle the scaling\n -n image to swaybg and let it handle the scaling\n
--verbose=N Define minimum log level. Counting from 1: LOG_DEBUG, LOG_INFO, --verbose=N Define minimum log level. Counting from 1: LOG_DEBUG, LOG_INFO,
-v N LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT, LOG_ALERT, LOG_EMERG -v N LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT, LOG_ALERT, LOG_EMERG
Default: 5; If provided without a value for N then all (1). Default: 5; If provided without a value for N then all (1).
--recursive=N Enumerate images recursively through directories in the path. --recursive=N Enumerate images recursively through directories in the path.
-r N N indicates the directory depth, unlimited if no N is provided. -r N N indicates the directory depth, unlimited if no N is provided.
--help This menu --help This menu
-h\n -h\n
You can send SIGUSR1 to force the daemon to reload immediately. Rotation timer You can send SIGUSR1 to force the daemon to reload immediately. Rotation timer
will be reset.\n"); will be reset.\n");
@ -66,6 +66,64 @@ sub new
return bless { %args }; return bless { %args };
} }
$args{pidfile} = "/tmp/$ENV{USER}-wallpaper.pid";
if (-e $wp->{pidfile}) {
if (-r $wp->{pidfile}) {
if (open(my $fh, '<', $wp->{pidfile})) {
my $pid = <$fh>;
chomp($pid);
use Proc::ProcessTable;
my $pt = Proc::ProcessTable->new();
foreach my $p ( @{ $pt->table() } ) {
if ($p->{pid} eq $pid) {
my $name = $0;
$name =~ s/$ENV{PWD}//;
if ($p->{'cmndline'} =~ m#$name#) {
$wp->do_log("LOG_CRIT", "Another process is already running with PID: $pid (running and listed in $wp->{pidfile})");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
} else {
$wp->do_log("LOG_CRIT", "Found matching $pid with different cmdline: $p->{cmndline} (not $0)",1);
# PID in pidfile doesn't look like it is another wallpaper
unlink($wp->{pidfile});
last;
}
return $p->{'pid'};
}
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but cannot be opened. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but is not readable. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
}
}
# SIGUSR reset the timer, force immediate reload, continue looping
$SIG{USR1} = sub {
alarm 0;
$wp->do_log("LOG_INFO", "Reloading due to SIGUSR1");
};
# SIGTERM reset the timer, clean pid, and allow for the main loop to finish run
$SIG{TERM} = sub {
$wp->do_log("LOG_INFO", "Going down clean due to SIGTERM");
clean($wp);
$wp->{daemon} = 0;
};
# SIGKILL clean pid then exit immediately
$SIG{KILL} = sub {
$wp->do_log("LOG_INFO", "Hard kill with SIGKILL, attempting to remove pidfile");
clean($wp);
exit(0);
};
# simply returns the array of hashes provided by swaymsg # simply returns the array of hashes provided by swaymsg
sub get_outputs sub get_outputs
{ {
@ -223,12 +281,12 @@ sub do_log
# Journald is borked. Just don't bother logging # Journald is borked. Just don't bother logging
return 0; return 0;
if ($self->{daemon}) { if ($self->{daemon}) {
#use Log::Journald qw(send); use Log::Journald qw(send);
#send( send(
#PRIORITY => ERROR->{$level}, PRIORITY => ERROR->{$level},
#MESSAGE => $msg, MESSAGE => $msg,
#PERL_PACKAGE => 'Sway Wallpapers' PERL_PACKAGE => 'Sway Wallpapers'
#) || warn "Could not send log ($level $msg): $!"; ) || warn "Could not send log ($level $msg): $!";
if ($die) { if ($die) {
$msg = '(FATAL) ' . $msg; $msg = '(FATAL) ' . $msg;
exit(1); exit(1);
@ -250,7 +308,6 @@ sub run
$self->do_log("LOG_DEBUG", "Fetching outputs from IPC"); $self->do_log("LOG_DEBUG", "Fetching outputs from IPC");
$self->{outputs} = $self->get_outputs(); $self->{outputs} = $self->get_outputs();
# Local copy of targets so that it will re-check active every time # Local copy of targets so that it will re-check active every time
print "Changing $_\n" foreach(@{$self->{targets}});
my @t = @{$self->{targets}} if (scalar(@{$self->{targets}})); my @t = @{$self->{targets}} if (scalar(@{$self->{targets}}));
$self->do_log("LOG_DEBUG", "Removing inactive ouputs"); $self->do_log("LOG_DEBUG", "Removing inactive ouputs");
my $active = $self->get_active(); my $active = $self->get_active();
@ -261,7 +318,6 @@ sub run
} }
$self->do_log("LOG_DEBUG", "Looping desired ouputs"); $self->do_log("LOG_DEBUG", "Looping desired ouputs");
foreach my $target (@t) { foreach my $target (@t) {
print $target."\n";
$self->do_log("LOG_DEBUG", "Ensuring that desired output is active"); $self->do_log("LOG_DEBUG", "Ensuring that desired output is active");
unless (defined($active->{$target})) { unless (defined($active->{$target})) {
$self->do_log('LOG_DEBUG', "Target $target is not an active output"); $self->do_log('LOG_DEBUG', "Target $target is not an active output");
@ -371,47 +427,7 @@ while (my $arg = shift(@ARGV)) {
} elsif ($arg =~ m/^-/) { } elsif ($arg =~ m/^-/) {
die "Unrecognized argument: $arg\n"; die "Unrecognized argument: $arg\n";
} else { } else {
print "Adding $arg to targets\n";
push(@targets,$arg); push(@targets,$arg);
print "Setting $_\n" foreach(@targets);
$wp->{targets} = \@targets || undef;
print "Set $_\n" foreach(@{$wp->{targets}});
}
}
if (-e $wp->{pidfile}) {
if (-r $wp->{pidfile}) {
if (open(my $fh, '<', $wp->{pidfile})) {
my $pid = <$fh>;
chomp($pid);
use Proc::ProcessTable;
my $pt = Proc::ProcessTable->new();
foreach my $p ( @{ $pt->table() } ) {
if ($p->{pid} eq $pid) {
my $name = $0;
$name =~ s/$ENV{PWD}//;
if ($p->{'cmndline'} =~ m#$name#) {
$wp->do_log("LOG_CRIT", "Another process is already running with PID: $pid (running and listed in $wp->{pidfile})");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
} else {
$wp->do_log("LOG_CRIT", "Found matching $pid with different cmdline: $p->{cmndline} (not $0)",1);
# PID in pidfile doesn't look like it is another wallpaper
unlink($wp->{pidfile});
last;
}
return $p->{'pid'};
}
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but cannot be opened. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but is not readable. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
} }
} }

View File

@ -15,18 +15,18 @@ sub usage()
{ {
print("$0 [value] [-p|--plus] [-m|--minus] [-a x|--attribute=x] [-d N|--delay=N] print("$0 [value] [-p|--plus] [-m|--minus] [-a x|--attribute=x] [-d N|--delay=N]
Fade the opacity of one or more windows via the Sway IPC interface.\n Fade the opacity of one or more windows via the Sway IPC interface.\n
value The target opacity or offset between 0 (full transparency) and 1 value The target opacity or offset between 0 (full transparency) and 1
(fully opaque). Change will be made in increments of 0.01 with a (fully opaque). Change will be made in increments of 0.01 with a
delay between each.\n delay between each.\n
--attribute=x Attribute of window(s) to fade. --attribute=x Attribute of window(s) to fade.
-a x Default: [title="*"]\n -a x Default: [title="*"]\n
--plus Increases opacity by increment instead of setting it directly --plus Increases opacity by increment instead of setting it directly
-p to that increment.\n -p to that increment.\n
--minus Decreases opacity by increment instead of setting it directly --minus Decreases opacity by increment instead of setting it directly
-m to that increment.\n -m to that increment.\n
--delay=N Change the delay in ms between each percentage point change in --delay=N Change the delay in ms between each percentage point change in
-d N opacity. Default: 20\n -d N opacity. Default: 20\n
--help This menu --help This menu
-h\n"); -h\n");
exit(0); exit(0);
} }

View File

@ -16,26 +16,26 @@
# $0 + "+%c" -= 10 +=4 =1 =100 "+%p" # $0 + "+%c" -= 10 +=4 =1 =100 "+%p"
# [ # [
# { # {
# "action" => "increment", # "action" => "increment",
# "value" => 1 # "value" => 1
# },{ # },{
# "action" => "print", # "action" => "print",
# "value" => "+%c" # "value" => "+%c"
# },{ # },{
# "action" => "decrement", # "action" => "decrement",
# "value" => 10 # "value" => 10
# },{ # },{
# "action" => "increment", # "action" => "increment",
# "value" => 4 # "value" => 4
# },{ # },{
# "action" => "set", # "action" => "set",
# "value" => 1 # "value" => 1
# },{ # },{
# "action" => "set", # "action" => "set",
# "value" => 100 # "value" => 100
# },{ # },{
# "action" => "print", # "action" => "print",
# "value" => "+%p" # "value" => "+%p"
# } # }
# ] # ]
# #
@ -57,7 +57,7 @@
# --delay-increment=0 --delay-action=1000 # --delay-increment=0 --delay-action=1000
# #
# With the latter, you could even have the backlight do morse code: # With the latter, you could even have the backlight do morse code:
# clear | S ( . . . ) |pause| O ( _ _ _ ) |pause| # clear | S ( . . . ) |pause| O ( _ _ _ ) |pause|
# =0 =100 =0 =100 =0 =100 =0 =0 =100 =100 =0 =100 =100 =0 =100 =100 =0 =0 ... # =0 =100 =0 =100 =0 =100 =0 =0 =100 =100 =0 =100 =100 =0 =100 =100 =0 =0 ...
# #
# Perhaps add an argument to repeat indefinitely. This is all getting a bit # Perhaps add an argument to repeat indefinitely. This is all getting a bit
@ -71,114 +71,114 @@ my $last_log = $ENV{HOME}."/.spool/blc.last";
sub to_percent sub to_percent
{ {
my $value = shift; my $value = shift;
return int($value/get_max()*100); return int($value/get_max()*100);
} }
sub get_offset sub get_offset
{ {
return int(get_max()/100); return int(get_max()/100);
} }
sub get_current sub get_current
{ {
open(my $c,'<',"$cur_file"); open(my $c,'<',"$cur_file");
my $current = <$c>; my $current = <$c>;
close $c; close $c;
chomp $current; chomp $current;
return $current; return $current;
} }
sub get_max sub get_max
{ {
open(my $m,'<',"$max_file"); open(my $m,'<',"$max_file");
my $max = <$m>; my $max = <$m>;
close $m; close $m;
chomp $max; chomp $max;
return $max; return $max;
} }
sub get_min sub get_min
{ {
return int((get_max()/100)+2); return int((get_max()/100)+2);
} }
sub writable sub writable
{ {
if (! -w $cur_file) { if (! -w $cur_file) {
die "You don't have permission to write $cur_file\n"; die "You don't have permission to write $cur_file\n";
} }
return 1; return 1;
} }
sub logger sub logger
{ {
my ($current, $target) = @_; my ($current, $target) = @_;
open(my $fh,'>',$last_log); open(my $fh,'>',$last_log);
print $fh to_percent($current); print $fh to_percent($current);
close($fh); close($fh);
open($fh,'>',$cur_log); open($fh,'>',$cur_log);
print $fh to_percent($target); print $fh to_percent($target);
close($fh); close($fh);
} }
sub writef sub writef
{ {
my $target = shift; my $target = shift;
open(my $fh,'>',$cur_file); open(my $fh,'>',$cur_file);
print $fh $target; print $fh $target;
close($fh); close($fh);
} }
sub increment sub increment
{ {
if (writable()) { if (writable()) {
my $current = get_current(); my $current = get_current();
my $max = get_max(); my $max = get_max();
my $target = $current+get_offset(); my $target = $current+get_offset();
if ($target > $max) { if ($target > $max) {
$target = $max; $target = $max;
}
return $target;
} }
return $target;
}
} }
sub decrement sub decrement
{ {
if (writable()) { if (writable()) {
my $current = get_current(); my $current = get_current();
my $min = get_min(); my $min = get_min();
my $target = $current-get_offset(); my $target = $current-get_offset();
if ($target < $min) { if ($target < $min) {
$target = $min; $target = $min;
}
set($target);
return $target;
} }
set($target);
return $target;
}
} }
sub set sub set
{ {
my $value = shift; my $value = shift;
if (writable()) { if (writable()) {
my $current = get_current(); my $current = get_current();
logger($current,$value); logger($current,$value);
if ($value > $current) { if ($value > $current) {
for (my $i=$current;$i<=$value;$i++) { for (my $i=$current;$i<=$value;$i++) {
writef($i); writef($i);
} }
} else { } else {
for (my $i=$current;$i>=$value;$i--) { for (my $i=$current;$i>=$value;$i--) {
writef($i); writef($i);
} }
}
return $value;
} }
return $value;
}
} }
sub help sub help
{ {
print " print "
Backlight Control Backlight Control
Usage: blc.pl [--silent|--notify] [OPTION] [VALUE] Usage: blc.pl [--silent|--notify] [OPTION] [VALUE]
@ -189,18 +189,18 @@ Output printed to STDOUT unless:
--silent Do not display output (overrides --notify) --silent Do not display output (overrides --notify)
--notify Send output to notification daemon. --notify=N will --notify Send output to notification daemon. --notify=N will
change the display duration in ms. Default is 200ms change the display duration in ms. Default is 200ms
Output option must preceed the first Action option. Output option must preceed the first Action option.
Actions: Actions:
= VALUE Set backlight to specific value. VALUE greater than = VALUE Set backlight to specific value. VALUE greater than
100 will be treated as absolute value. VALUE eqaul to 100 will be treated as absolute value. VALUE eqaul to
or less than 100 will be treated as a percentage or less than 100 will be treated as a percentage
+ Increment by 1% + Increment by 1%
+= VALUE Increment by VALUE percent += VALUE Increment by VALUE percent
- Decrement by 1% - Decrement by 1%
-= VALUE Decrement by VALUE percent -= VALUE Decrement by VALUE percent
Actions corrected to 1% or 100% if over or under. All actions Actions corrected to 1% or 100% if over or under. All actions
@ -210,9 +210,9 @@ Final percentage printed as below, skipping other options.
Print: Print:
== Print current absolute value == Print current absolute value
^ Print maximum absolute value ^ Print maximum absolute value
% Print current percentage (does not include % symbol) % Print current percentage (does not include % symbol)
--help Help (not impacted by --silent or --notify) --help Help (not impacted by --silent or --notify)
--HELP Advanced help (same as above) --HELP Advanced help (same as above)
@ -221,28 +221,28 @@ Any other option will be printed literally";
sub advanced sub advanced
{ {
$current = get_current(); $current = get_current();
$max = get_max(); $max = get_max();
print ". print ".
Print functions can be strung together but command will exit Print functions can be strung together but command will exit
with the first non-print option. eg. with the first non-print option. eg.
\$ blc.pl == / ^ \$ blc.pl == / ^
21/100 21/100
\$ blc.pl == ++ \$ blc.pl == ++
('==' ignored) ('==' ignored)
(Backlight incremented) (Backlight incremented)
Escape options with \\ in quotes to display them literally. eg. Escape options with \\ in quotes to display them literally. eg.
\$ blc.pl == / ^ '\\=' % \'\\%\' \$ blc.pl == / ^ '\\=' % \'\\%\'
" . $current . "/" . $max . "=" . int($current/$max*100) . "% " . $current . "/" . $max . "=" . int($current/$max*100) . "%
Only one \'\\' is removed per block. eg. Only one \'\\' is removed per block. eg.
\$ blc.pl '\\% \\' \$ blc.pl '\\% \\'
% \\ % \\
"; ";
} }
@ -252,140 +252,140 @@ my (@output, $target, $silent, $notify);
my $operation_found = 0; my $operation_found = 0;
if (scalar @ARGV) { if (scalar @ARGV) {
while ($arg = shift) { while ($arg = shift) {
if ($arg eq '%') { if ($arg eq '%') {
push @output,to_percent(get_current); push @output,to_percent(get_current);
} elsif ($arg eq '^') { } elsif ($arg eq '^') {
push @output,get_max(); push @output,get_max();
} elsif ($arg eq '==') { } elsif ($arg eq '==') {
push @output,get_current(); push @output,get_current();
} elsif ($arg eq '--help') { } elsif ($arg eq '--help') {
help(); help();
print " (see --HELP).\n\n"; print " (see --HELP).\n\n";
exit(); exit();
} elsif ($arg eq '--HELP') { } elsif ($arg eq '--HELP') {
help(); help();
advanced(); advanced();
exit(); exit();
} elsif ($arg eq '--silent') { } elsif ($arg eq '--silent') {
$silent = 1; $silent = 1;
} elsif ($arg =~ /^--notify/) { } elsif ($arg =~ /^--notify/) {
$notify = 1; $notify = 1;
if ($arg =~ /=[0-9]+$/) { if ($arg =~ /=[0-9]+$/) {
$duration = $arg; $duration = $arg;
$duration =~ s/.*=([0-9]+)/$1/; $duration =~ s/.*=([0-9]+)/$1/;
} else { } else {
$duration = 1000; $duration = 1000;
} }
} elsif ($arg eq '+') { } elsif ($arg eq '+') {
unshift(@ARGV,1); unshift(@ARGV,1);
unshift(@ARGV,'+='); unshift(@ARGV,'+=');
} elsif ($arg =~ /^\+=/) { } elsif ($arg =~ /^\+=/) {
my $offset; my $offset;
if ($arg =~ m/^\+=(.+)$/) { if ($arg =~ m/^\+=(.+)$/) {
$offset = $1; $offset = $1;
} else { } else {
$offset = shift || die "+= without accompanying offset value\n"; $offset = shift || die "+= without accompanying offset value\n";
} }
unless ($offset =~ /^\d+$/) { unless ($offset =~ /^\d+$/) {
die "+= <value> is not a number ($offset)\n"; die "+= <value> is not a number ($offset)\n";
} }
for (my $j=0;$j<$offset;$j++) { for (my $j=0;$j<$offset;$j++) {
$target = increment(); $target = increment();
@output = to_percent($target); @output = to_percent($target);
} }
$operation_found = 1; $operation_found = 1;
} elsif ($arg eq '-') { } elsif ($arg eq '-') {
unshift(@ARGV,1); unshift(@ARGV,1);
unshift(@ARGV,'-='); unshift(@ARGV,'-=');
} elsif ($arg =~ /^-=/) { } elsif ($arg =~ /^-=/) {
my $offset; my $offset;
if ($arg =~ m/^-=(.+)$/) { if ($arg =~ m/^-=(.+)$/) {
$offset = $1; $offset = $1;
} else { } else {
$offset = shift || die "-= without accompanying offset value\n"; $offset = shift || die "-= without accompanying offset value\n";
} }
unless ($offset =~ /^\d+$/) { unless ($offset =~ /^\d+$/) {
die "-= <value> is not a number ($offset)\n"; die "-= <value> is not a number ($offset)\n";
} }
for (my $j=0;$j<$offset;$j++) { for (my $j=0;$j<$offset;$j++) {
$target = decrement(); $target = decrement();
@output = to_percent($target); @output = to_percent($target);
} }
$operation_found = 1; $operation_found = 1;
} elsif ($arg =~ m/^=/) { } elsif ($arg =~ m/^=/) {
my $value; my $value;
if ($arg =~ m/^=(.+)$/) { if ($arg =~ m/^=(.+)$/) {
$target = $1; $target = $1;
} else { } else {
$target = shift || die "= without accompanying absolute value\n"; $target = shift || die "= without accompanying absolute value\n";
} }
unless ($target =~ /^\d+$/) { unless ($target =~ /^\d+$/) {
die "= <value> is not a number ($target)\n"; die "= <value> is not a number ($target)\n";
} }
if ($target < 1) { if ($target < 1) {
$target = set(get_min()); $target = set(get_min());
} elsif ($target > get_max()) { } elsif ($target > get_max()) {
$target = set(get_max()); $target = set(get_max());
} elsif ($target > 100) { } elsif ($target > 100) {
$target = set($target); $target = set($target);
} else { } else {
$target = set( $target = set(
int((get_max()*$target/100)+1) int((get_max()*$target/100)+1)
); );
} }
@output = to_percent($target); @output = to_percent($target);
$operation_found = 1; $operation_found = 1;
} else { } else {
push(@output,$arg); push(@output,$arg);
}
} }
}
} else { } else {
@output = ( @output = (
'{"Backlight":{"Max":"' '{"Backlight":{"Max":"'
. get_max() . get_max()
. '","Current":"' . '","Current":"'
. get_current() . get_current()
. '","Percentage","' . '","Percentage","'
. int(get_current()/get_max()*100) . int(get_current()/get_max()*100)
. '%"}}' . '%"}}'
); );
} }
if ($silent) { if ($silent) {
exit(); exit();
} elsif ($notify) { } elsif ($notify) {
my $concat = ''; my $concat = '';
foreach (@output) { foreach (@output) {
$concat .= $_; $concat .= $_;
} }
=pod =pod
use Gtk2::Notify -init, "Backlight"; use Gtk2::Notify -init, "Backlight";
my $notification = Gtk2::Notify::new('Backlight', $concat, '', "notification-display-brightness"); my $notification = Gtk2::Notify::new('Backlight', $concat, '', "notification-display-brightness");
$notification->set_hint_string('x-canonical-private-synchronous','blc'); $notification->set_hint_string('x-canonical-private-synchronous','blc');
$notification->set_urgency('NOTIFY_URGENCY_LOW'); $notification->set_urgency('NOTIFY_URGENCY_LOW');
$notification->set_hint_int32('value',(split('%',$concat))[0]); $notification->set_hint_int32('value',(split('%',$concat))[0]);
$notification->set_timeout($duration); $notification->set_timeout($duration);
$notification->show(); $notification->show();
exit; exit;
print "notify-send --urgency=normal" print "notify-send --urgency=normal"
. ' --icon="notification-display-brightness"' . ' --icon="notification-display-brightness"'
. ' --hint=string:x-canonical-private-synchronous:blc' . ' --hint=string:x-canonical-private-synchronous:blc'
. ' --expire-time=' . $duration . ' --expire-time=' . $duration
. ' "Backlight"' . ' "Backlight"'
. ' "' . $concat . " '" . join("','", @output) . "'\""; . ' "' . $concat . " '" . join("','", @output) . "'\"";
system "notify-send --urgency=normal" system "notify-send --urgency=normal"
. ' --icon="notification-display-brightness"' . ' --icon="notification-display-brightness"'
. ' --hint=string:x-canonical-private-synchronous:blc' . ' --hint=string:x-canonical-private-synchronous:blc'
. ' --hint=int:value:' . (split('%',$concat))[0] . ' --hint=int:value:' . (split('%',$concat))[0]
. ' --expire-time=' . $duration . ' --expire-time=' . $duration
. ' "' . $concat . "\""; . ' "' . $concat . "\"";
=cut =cut
exit(); exit();
} else { } else {
print foreach @output; print foreach @output;
print "\n"; print "\n";
exit(); exit();
} }

View File

@ -47,7 +47,6 @@ foreach (@devices) {
close $t; close $t;
$output .= '"Type":"' . $type . '"'; $output .= '"Type":"' . $type . '"';
if ($name =~ /BAT[0-9]+/) { if ($name =~ /BAT[0-9]+/) {
$nobat = 0;
open(my $s,'<',"$_/status"); open(my $s,'<',"$_/status");
my $status = <$s>; my $status = <$s>;
chomp $status; chomp $status;
@ -86,10 +85,6 @@ foreach (@devices) {
} }
$output .= "},"; $output .= "},";
} }
unless ($nobat) {
print('{"AC":{"Type":"AC","Status":"Plugged-In"}}');
exit();
}
$battery_total{'percentage'} = sprintf("%0d", $battery_total{'percentage'} = sprintf("%0d",
$battery_total{'current'} / $battery_total{'max'} * 100 $battery_total{'current'} / $battery_total{'max'} * 100
@ -109,13 +104,13 @@ if ($bar) {
my $class = 'discharging'; my $class = 'discharging';
$output = ''; $output = '';
if ($powref->{AC}->{Status} eq "Plugged-In") { if ($powref->{AC}->{Status} eq "Plugged-In") {
$class = 'charging'; $class = 'charging';
$output .= ""; $output .= "";
} elsif ($powref->{Total}->{Percentage} <= 10) { } elsif ($powref->{Total}->{Percentage} <= 10) {
$class = 'critical'; $class = 'critical';
$output .= ""; $output .= "";
} elsif ($powref->{Total}->{Percentage} <= 35) { } elsif ($powref->{Total}->{Percentage} <= 35) {
$class = 'low'; $class = 'low';
$output .= ""; $output .= "";
} elsif ($powref->{Total}->{Percentage} <= 60) { } elsif ($powref->{Total}->{Percentage} <= 60) {
$output .= ""; $output .= "";
@ -138,11 +133,11 @@ if ($bar) {
my $total = ''; my $total = '';
$output = "Device Status Percentage\n"; $output = "Device Status Percentage\n";
foreach my $device (keys %{$powref}) { foreach my $device (keys %{$powref}) {
my $status; my $status;
if ($powref->{$device}->{Status} eq "Plugged-In") { if ($powref->{$device}->{Status} eq "Plugged-In") {
$status = ""; $status = "";
} elsif (!defined($powref->{$device}->{Percentage}) || $powref->{$device}->{Percentage} == 0) { } elsif (!defined($powref->{$device}->{Percentage}) || $powref->{$device}->{Percentage} == 0) {
$status = " "; $status = " ";
} elsif ($powref->{$device}->{Percentage} <= 10) { } elsif ($powref->{$device}->{Percentage} <= 10) {
$status = " " . $powref->{$device}->{'Percentage'} . "%"; $status = " " . $powref->{$device}->{'Percentage'} . "%";
} elsif ($powref->{$device}->{Percentage} <= 35) { } elsif ($powref->{$device}->{Percentage} <= 35) {
@ -153,19 +148,19 @@ if ($bar) {
$status = " " . $powref->{$device}->{'Percentage'} . "%"; $status = " " . $powref->{$device}->{'Percentage'} . "%";
} else { } else {
$status = " " . $powref->{$device}->{'Percentage'} . "%"; $status = " " . $powref->{$device}->{'Percentage'} . "%";
}
if ($device eq 'Total') {
$total .= sprintf("%-24s %-12s", $device, $status);
} else {
#$output .= sprintf("%".length($powref->{$device->{'Type'}})."s (%".length($powref->{$device->{'Type'}})."s): %3d\%\n", $device, $device->{'Type'}, $device->{'Percentage'});
my $name = ' ('.$powref->{$device}->{'Type'}.')';
if ((length($device)+length($name)) >= 24) {
$name = substr($device, 0, (21-length($name))) . '...' . $name;
} else {
$name = substr(($device.$name), 0, 24);
} }
$output .= sprintf("%-24s %-12s %-12s\n", $name, $powref->{$device}->{Status}, $status); if ($device eq 'Total') {
} $total .= sprintf("%-24s %-12s", $device, $status);
} else {
#$output .= sprintf("%".length($powref->{$device->{'Type'}})."s (%".length($powref->{$device->{'Type'}})."s): %3d\%\n", $device, $device->{'Type'}, $device->{'Percentage'});
my $name = ' ('.$powref->{$device}->{'Type'}.')';
if ((length($device)+length($name)) >= 24) {
$name = substr($device, 0, (21-length($name))) . '...' . $name;
} else {
$name = substr(($device.$name), 0, 24);
}
$output .= sprintf("%-24s %-12s %-12s\n", $name, $powref->{$device}->{Status}, $status);
}
} }
$output .= $total; $output .= $total;
} }

View File

@ -23,9 +23,9 @@ elif [ "$1" == 'upgrade' ]; then
COUNT=`apt list --upgradable 2> /dev/null | wc -l` COUNT=`apt list --upgradable 2> /dev/null | wc -l`
let COUNT-- let COUNT--
echo $COUNT > /home/jpm/.spool/apt-upgradeable echo $COUNT > /home/jpm/.spool/apt-upgradeable
if [ -e /var/run/reboot-required ]; then if [ -e /var/run/reboot-required ]; then
grep -B1 -A4 upgrade /var/log/apt/history.log | tail -n 6 | swaynag --config=${HOME}/.dotfiles/sway/swaynag --edge=bottom --message="New packages require restart" --button="Restart Now" "sudo systemctl reboot" --dismiss-button="Later" --detailed-message --detailed-button "Show/Hide Upgrade Details" grep -B1 -A4 upgrade /var/log/apt/history.log | tail -n 6 | swaynag --config=${HOME}/.dotfiles/sway/swaynag --edge=bottom --message="New packages require restart" --button="Restart Now" "sudo systemctl reboot" --dismiss-button="Later" --detailed-message --detailed-button "Show/Hide Upgrade Details"
fi fi
elif [ "$1" == 'update' ]; then elif [ "$1" == 'update' ]; then
sudo apt update >/dev/null 2>/dev/null sudo apt update >/dev/null 2>/dev/null
COUNT=`apt list --upgradable 2> /dev/null | wc -l` COUNT=`apt list --upgradable 2> /dev/null | wc -l`

View File

@ -6,7 +6,7 @@ swaymsg -t get_tree |
sed -e 's/^\(.*\) [—-] .*$/\1/'| sed -e 's/^\(.*\) [—-] .*$/\1/'|
sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' | sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' |
wofi -s $HOME/.dotfiles/wofi/style.css -c \ wofi -s $HOME/.dotfiles/wofi/style.css -c \
$HOME/.dotfiles/wofi/sidebar -d | { $HOME/.dotfiles/wofi/sidebar -d | {
read -r read -r
id=`echo $REPLY | rev | cut -d' ' -f1 | rev` id=`echo $REPLY | rev | cut -d' ' -f1 | rev`
swaymsg "[con_id=$id]" focus swaymsg "[con_id=$id]" focus

View File

@ -37,7 +37,7 @@ fi
CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | wofi -s $HOME/.dotfiles/wofi/style.css -i -d --prompt "Wi-Fi SSID: " -c $HOME/.dotfiles/wofi/sidebar) CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | wofi -s $HOME/.dotfiles/wofi/style.css -i -d --prompt "Wi-Fi SSID: " -c $HOME/.dotfiles/wofi/sidebar)
if [[ $CHENTRY == "" ]]; then if [[ $CHENTRY == "" ]]; then
exit exit
fi fi
#echo "$CHENTRY" #echo "$CHENTRY"
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}') CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}')