Merge branch 'master' of ssh://git@git.john.me.tz:223/jpm/scripts.git
This commit is contained in:
commit
d1fbad9b82
10
README.md
10
README.md
|
@ -125,11 +125,11 @@ it to be *hidden*.
|
|||
|
||||
```
|
||||
"sway/workspaces": {
|
||||
"format": "{icon}",
|
||||
"format-icons": {
|
||||
"0": "0 \uf073", // Example of workspace with a label
|
||||
"grave": "",
|
||||
...
|
||||
"format": "{icon}",
|
||||
"format-icons": {
|
||||
"0": "0 \uf073", // Example of workspace with a label
|
||||
"grave": "",
|
||||
...
|
||||
```
|
||||
|
||||
[**sway/swayidle.sh**](https://git.john.me.tz/jpm/scripts/src/branch/master/sway/swayidle.sh)
|
||||
|
|
|
@ -21,7 +21,7 @@ my @default_feeds = (
|
|||
# It requires FIFO to stream. For a player that does support STDIN, uncomment
|
||||
# above and delete the following 4 lines
|
||||
unless (-e "/tmp/fifo.mp3") {
|
||||
system("mkfifo /tmp/fifo.mp3");
|
||||
system("mkfifo /tmp/fifo.mp3");
|
||||
}
|
||||
my $player = "> /tmp/fifo.mp3 & omxplayer /tmp/fifo.mp3";
|
||||
|
||||
|
|
4
nvim.sh
4
nvim.sh
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
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
|
||||
nvim $@
|
||||
nvim $@
|
||||
fi
|
||||
|
|
|
@ -16,7 +16,7 @@ local_port=12345
|
|||
|
||||
show_help()
|
||||
{
|
||||
cat<<EOF
|
||||
cat<<EOF
|
||||
Sends a video URL to Kodi
|
||||
Usage: send-to-kodi.sh [URL]
|
||||
|
||||
|
@ -35,24 +35,24 @@ EOF
|
|||
|
||||
error()
|
||||
{
|
||||
if type zenity &>/dev/null; then
|
||||
zenity --error --ellipsize --text "$*"
|
||||
else
|
||||
echo "$*" 1>&2
|
||||
fi
|
||||
if type zenity &>/dev/null; then
|
||||
zenity --error --ellipsize --text "$*"
|
||||
else
|
||||
echo "$*" 1>&2
|
||||
fi
|
||||
|
||||
exit 1
|
||||
exit 1
|
||||
}
|
||||
|
||||
send_json()
|
||||
{
|
||||
curl \
|
||||
${user:+--user "$user:$pass"} \
|
||||
-X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \
|
||||
http://$host:$port/jsonrpc \
|
||||
|| error "Failed to send link - is Kodi running?"
|
||||
curl \
|
||||
${user:+--user "$user:$pass"} \
|
||||
-X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \
|
||||
http://$host:$port/jsonrpc \
|
||||
|| error "Failed to send link - is Kodi running?"
|
||||
}
|
||||
|
||||
ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
|
||||
|
@ -63,35 +63,35 @@ ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
|
|||
# Dialog box?
|
||||
input=$1
|
||||
until [[ $input ]]; do
|
||||
input="$(zenity --entry --title "Send to Kodi" --text \
|
||||
"Paste a video link here")" || exit
|
||||
input="$(zenity --entry --title "Send to Kodi" --text \
|
||||
"Paste a video link here")" || exit
|
||||
done
|
||||
|
||||
if [[ $input =~ ^file:// ]]; then
|
||||
# Remove file:// and carrige return (\r) at the end
|
||||
input="$(sed 's%^file://%%;s/\r$//' <<< "$input")"
|
||||
# Remove file:// and carrige return (\r) at the end
|
||||
input="$(sed 's%^file://%%;s/\r$//' <<< "$input")"
|
||||
fi
|
||||
|
||||
# Get URL for...
|
||||
|
||||
# Local media
|
||||
if [[ -e $input ]]; then
|
||||
type nc &>/dev/null || error "netcat required"
|
||||
[[ $local_hostname && $local_port ]] || \
|
||||
error "Please set local hostname and port in configuration"
|
||||
type nc &>/dev/null || error "netcat required"
|
||||
[[ $local_hostname && $local_port ]] || \
|
||||
error "Please set local hostname and port in configuration"
|
||||
|
||||
# Start netcat in background and kill it when we exit
|
||||
nc -lp $local_port < "$input" &
|
||||
trap "kill $!" EXIT
|
||||
# Start netcat in background and kill it when we exit
|
||||
nc -lp $local_port < "$input" &
|
||||
trap "kill $!" EXIT
|
||||
|
||||
url="tcp://$local_hostname:$local_port"
|
||||
url="tcp://$local_hostname:$local_port"
|
||||
|
||||
# youtube.com / youtu.be
|
||||
elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then
|
||||
url="$ytplugin$(\
|
||||
sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\
|
||||
<<< "$input"\
|
||||
)"
|
||||
url="$ytplugin$(\
|
||||
sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\
|
||||
<<< "$input"\
|
||||
)"
|
||||
|
||||
# Playable formats
|
||||
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
|
||||
else
|
||||
type youtube-dl &>/dev/null || error "youtube-dl required"
|
||||
url="$(youtube-dl -gf best "$input")" || \
|
||||
error "No videos found, or site not supported by youtube-dl"
|
||||
type youtube-dl &>/dev/null || error "youtube-dl required"
|
||||
url="$(youtube-dl -gf best "$input")" || \
|
||||
error "No videos found, or site not supported by youtube-dl"
|
||||
fi
|
||||
|
||||
[[ $url ]] && send_json "$url"
|
||||
|
|
|
@ -53,6 +53,7 @@ elif [ $1 == "fade" ]; then
|
|||
elif [ $1 == "unfade" ]; then
|
||||
if [ -e $HOME/.spool/sway-hidden ]; then
|
||||
kill -USR2 `cat $HOME/.spool/sway-transparency`
|
||||
/home/jpm/scripts/sway/displays.pl -w
|
||||
fi
|
||||
elif [ $1 == "dim" ]; then
|
||||
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE
|
||||
|
|
|
@ -32,10 +32,10 @@ elif [ "$res" == "↹ Restart i3" ]; then
|
|||
i3 restart
|
||||
elif [ "$res" == "↻ Reload Sway" ]; then
|
||||
sway reload
|
||||
/home/jpm/scripts/sway/displays.pl
|
||||
/home/jpm/scripts/distrobox/debian12/displays.sh
|
||||
elif [ "$res" == "↻ Reload Waybar" ]; then
|
||||
# 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
|
||||
rm $SSH_AUTH_SOCK
|
||||
sudo systemctl reboot -i
|
||||
|
|
|
@ -20,7 +20,7 @@ export FLATPAK_IDE_LOG_LEVEL="0"
|
|||
export "$( gnome-keyring-daemon --start )"
|
||||
|
||||
#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=gles2 $HOME/build/sway/build/sway/sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
|
||||
export SWAYSOCK=`sway --get-socketpath`
|
||||
|
|
|
@ -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
|
||||
in my sway/displays.pl script. If no outputs are provided, all available that
|
||||
are currently enabled will be set.\n
|
||||
--path=<path> Path to wallpaper directory.
|
||||
-p <path> Default: $ENV{HOME}/wallpapers\n
|
||||
--daemon=N Configures the wallpaper to be periodically rotated for all
|
||||
-d N of the given outputs. N indicates the number of seconds between
|
||||
each rotation, if provided (default: 300).\n
|
||||
--nocrop Don't crop a selection from the image. Instead, pass the whole
|
||||
-n image to swaybg and let it handle the scaling\n
|
||||
--path=<path> Path to wallpaper directory.
|
||||
-p <path> Default: $ENV{HOME}/wallpapers\n
|
||||
--daemon=N Configures the wallpaper to be periodically rotated for all
|
||||
-d N of the given outputs. N indicates the number of seconds between
|
||||
each rotation, if provided (default: 300).\n
|
||||
--nocrop Don't crop a selection from the image. Instead, pass the whole
|
||||
-n image to swaybg and let it handle the scaling\n
|
||||
--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
|
||||
Default: 5; If provided without a value for N then all (1).
|
||||
--recursive=N Enumerate images recursively through directories in the path.
|
||||
-r N N indicates the directory depth, unlimited if no N is provided.
|
||||
--help This menu
|
||||
-r N N indicates the directory depth, unlimited if no N is provided.
|
||||
--help This menu
|
||||
-h\n
|
||||
You can send SIGUSR1 to force the daemon to reload immediately. Rotation timer
|
||||
will be reset.\n");
|
||||
|
@ -66,6 +66,64 @@ sub new
|
|||
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
|
||||
sub get_outputs
|
||||
{
|
||||
|
@ -223,12 +281,12 @@ sub do_log
|
|||
# Journald is borked. Just don't bother logging
|
||||
return 0;
|
||||
if ($self->{daemon}) {
|
||||
#use Log::Journald qw(send);
|
||||
#send(
|
||||
#PRIORITY => ERROR->{$level},
|
||||
#MESSAGE => $msg,
|
||||
#PERL_PACKAGE => 'Sway Wallpapers'
|
||||
#) || warn "Could not send log ($level $msg): $!";
|
||||
use Log::Journald qw(send);
|
||||
send(
|
||||
PRIORITY => ERROR->{$level},
|
||||
MESSAGE => $msg,
|
||||
PERL_PACKAGE => 'Sway Wallpapers'
|
||||
) || warn "Could not send log ($level $msg): $!";
|
||||
if ($die) {
|
||||
$msg = '(FATAL) ' . $msg;
|
||||
exit(1);
|
||||
|
@ -250,7 +308,6 @@ sub run
|
|||
$self->do_log("LOG_DEBUG", "Fetching outputs from IPC");
|
||||
$self->{outputs} = $self->get_outputs();
|
||||
# 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}}));
|
||||
$self->do_log("LOG_DEBUG", "Removing inactive ouputs");
|
||||
my $active = $self->get_active();
|
||||
|
@ -261,7 +318,6 @@ sub run
|
|||
}
|
||||
$self->do_log("LOG_DEBUG", "Looping desired ouputs");
|
||||
foreach my $target (@t) {
|
||||
print $target."\n";
|
||||
$self->do_log("LOG_DEBUG", "Ensuring that desired output is active");
|
||||
unless (defined($active->{$target})) {
|
||||
$self->do_log('LOG_DEBUG', "Target $target is not an active output");
|
||||
|
@ -371,47 +427,7 @@ while (my $arg = shift(@ARGV)) {
|
|||
} elsif ($arg =~ m/^-/) {
|
||||
die "Unrecognized argument: $arg\n";
|
||||
} else {
|
||||
print "Adding $arg to targets\n";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,18 +15,18 @@ sub usage()
|
|||
{
|
||||
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
|
||||
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
|
||||
delay between each.\n
|
||||
--attribute=x Attribute of window(s) to fade.
|
||||
-a x Default: [title="*"]\n
|
||||
--plus Increases opacity by increment instead of setting it directly
|
||||
-p to that increment.\n
|
||||
--minus Decreases opacity by increment instead of setting it directly
|
||||
-m to that increment.\n
|
||||
--delay=N Change the delay in ms between each percentage point change in
|
||||
-d N opacity. Default: 20\n
|
||||
--help This menu
|
||||
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
|
||||
delay between each.\n
|
||||
--attribute=x Attribute of window(s) to fade.
|
||||
-a x Default: [title="*"]\n
|
||||
--plus Increases opacity by increment instead of setting it directly
|
||||
-p to that increment.\n
|
||||
--minus Decreases opacity by increment instead of setting it directly
|
||||
-m to that increment.\n
|
||||
--delay=N Change the delay in ms between each percentage point change in
|
||||
-d N opacity. Default: 20\n
|
||||
--help This menu
|
||||
-h\n");
|
||||
exit(0);
|
||||
}
|
||||
|
|
442
thinkpad/blc.pl
442
thinkpad/blc.pl
|
@ -16,26 +16,26 @@
|
|||
# $0 + "+%c" -= 10 +=4 =1 =100 "+%p"
|
||||
# [
|
||||
# {
|
||||
# "action" => "increment",
|
||||
# "value" => 1
|
||||
# "action" => "increment",
|
||||
# "value" => 1
|
||||
# },{
|
||||
# "action" => "print",
|
||||
# "value" => "+%c"
|
||||
# "action" => "print",
|
||||
# "value" => "+%c"
|
||||
# },{
|
||||
# "action" => "decrement",
|
||||
# "value" => 10
|
||||
# "action" => "decrement",
|
||||
# "value" => 10
|
||||
# },{
|
||||
# "action" => "increment",
|
||||
# "value" => 4
|
||||
# "action" => "increment",
|
||||
# "value" => 4
|
||||
# },{
|
||||
# "action" => "set",
|
||||
# "value" => 1
|
||||
# "action" => "set",
|
||||
# "value" => 1
|
||||
# },{
|
||||
# "action" => "set",
|
||||
# "value" => 100
|
||||
# "action" => "set",
|
||||
# "value" => 100
|
||||
# },{
|
||||
# "action" => "print",
|
||||
# "value" => "+%p"
|
||||
# "action" => "print",
|
||||
# "value" => "+%p"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
|
@ -57,7 +57,7 @@
|
|||
# --delay-increment=0 --delay-action=1000
|
||||
#
|
||||
# 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 ...
|
||||
#
|
||||
# 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
|
||||
{
|
||||
my $value = shift;
|
||||
return int($value/get_max()*100);
|
||||
my $value = shift;
|
||||
return int($value/get_max()*100);
|
||||
}
|
||||
|
||||
sub get_offset
|
||||
{
|
||||
return int(get_max()/100);
|
||||
return int(get_max()/100);
|
||||
}
|
||||
|
||||
sub get_current
|
||||
{
|
||||
open(my $c,'<',"$cur_file");
|
||||
my $current = <$c>;
|
||||
close $c;
|
||||
chomp $current;
|
||||
return $current;
|
||||
open(my $c,'<',"$cur_file");
|
||||
my $current = <$c>;
|
||||
close $c;
|
||||
chomp $current;
|
||||
return $current;
|
||||
}
|
||||
|
||||
sub get_max
|
||||
{
|
||||
open(my $m,'<',"$max_file");
|
||||
my $max = <$m>;
|
||||
close $m;
|
||||
chomp $max;
|
||||
return $max;
|
||||
open(my $m,'<',"$max_file");
|
||||
my $max = <$m>;
|
||||
close $m;
|
||||
chomp $max;
|
||||
return $max;
|
||||
}
|
||||
|
||||
sub get_min
|
||||
{
|
||||
return int((get_max()/100)+2);
|
||||
return int((get_max()/100)+2);
|
||||
}
|
||||
|
||||
sub writable
|
||||
{
|
||||
if (! -w $cur_file) {
|
||||
die "You don't have permission to write $cur_file\n";
|
||||
}
|
||||
return 1;
|
||||
if (! -w $cur_file) {
|
||||
die "You don't have permission to write $cur_file\n";
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub logger
|
||||
{
|
||||
my ($current, $target) = @_;
|
||||
open(my $fh,'>',$last_log);
|
||||
print $fh to_percent($current);
|
||||
close($fh);
|
||||
open($fh,'>',$cur_log);
|
||||
print $fh to_percent($target);
|
||||
close($fh);
|
||||
my ($current, $target) = @_;
|
||||
open(my $fh,'>',$last_log);
|
||||
print $fh to_percent($current);
|
||||
close($fh);
|
||||
open($fh,'>',$cur_log);
|
||||
print $fh to_percent($target);
|
||||
close($fh);
|
||||
}
|
||||
|
||||
sub writef
|
||||
{
|
||||
my $target = shift;
|
||||
open(my $fh,'>',$cur_file);
|
||||
print $fh $target;
|
||||
close($fh);
|
||||
my $target = shift;
|
||||
open(my $fh,'>',$cur_file);
|
||||
print $fh $target;
|
||||
close($fh);
|
||||
}
|
||||
|
||||
sub increment
|
||||
{
|
||||
if (writable()) {
|
||||
my $current = get_current();
|
||||
my $max = get_max();
|
||||
my $target = $current+get_offset();
|
||||
if ($target > $max) {
|
||||
$target = $max;
|
||||
}
|
||||
return $target;
|
||||
if (writable()) {
|
||||
my $current = get_current();
|
||||
my $max = get_max();
|
||||
my $target = $current+get_offset();
|
||||
if ($target > $max) {
|
||||
$target = $max;
|
||||
}
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
sub decrement
|
||||
{
|
||||
if (writable()) {
|
||||
my $current = get_current();
|
||||
my $min = get_min();
|
||||
my $target = $current-get_offset();
|
||||
if ($target < $min) {
|
||||
$target = $min;
|
||||
}
|
||||
set($target);
|
||||
return $target;
|
||||
if (writable()) {
|
||||
my $current = get_current();
|
||||
my $min = get_min();
|
||||
my $target = $current-get_offset();
|
||||
if ($target < $min) {
|
||||
$target = $min;
|
||||
}
|
||||
set($target);
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
sub set
|
||||
{
|
||||
my $value = shift;
|
||||
if (writable()) {
|
||||
my $current = get_current();
|
||||
logger($current,$value);
|
||||
if ($value > $current) {
|
||||
for (my $i=$current;$i<=$value;$i++) {
|
||||
writef($i);
|
||||
}
|
||||
} else {
|
||||
for (my $i=$current;$i>=$value;$i--) {
|
||||
writef($i);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
my $value = shift;
|
||||
if (writable()) {
|
||||
my $current = get_current();
|
||||
logger($current,$value);
|
||||
if ($value > $current) {
|
||||
for (my $i=$current;$i<=$value;$i++) {
|
||||
writef($i);
|
||||
}
|
||||
} else {
|
||||
for (my $i=$current;$i>=$value;$i--) {
|
||||
writef($i);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
sub help
|
||||
{
|
||||
print "
|
||||
print "
|
||||
Backlight Control
|
||||
|
||||
Usage: blc.pl [--silent|--notify] [OPTION] [VALUE]
|
||||
|
@ -189,18 +189,18 @@ Output printed to STDOUT unless:
|
|||
|
||||
--silent Do not display output (overrides --notify)
|
||||
--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.
|
||||
|
||||
Actions:
|
||||
|
||||
= VALUE Set backlight to specific value. VALUE greater than
|
||||
100 will be treated as absolute value. VALUE eqaul to
|
||||
or less than 100 will be treated as a percentage
|
||||
+ Increment by 1%
|
||||
100 will be treated as absolute value. VALUE eqaul to
|
||||
or less than 100 will be treated as a percentage
|
||||
+ Increment by 1%
|
||||
+= VALUE Increment by VALUE percent
|
||||
- Decrement by 1%
|
||||
- Decrement by 1%
|
||||
-= VALUE Decrement by VALUE percent
|
||||
|
||||
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 current absolute value
|
||||
^ Print maximum absolute value
|
||||
% Print current percentage (does not include % symbol)
|
||||
== Print current absolute value
|
||||
^ Print maximum absolute value
|
||||
% Print current percentage (does not include % symbol)
|
||||
--help Help (not impacted by --silent or --notify)
|
||||
--HELP Advanced help (same as above)
|
||||
|
||||
|
@ -221,28 +221,28 @@ Any other option will be printed literally";
|
|||
|
||||
sub advanced
|
||||
{
|
||||
$current = get_current();
|
||||
$max = get_max();
|
||||
print ".
|
||||
$current = get_current();
|
||||
$max = get_max();
|
||||
print ".
|
||||
|
||||
Print functions can be strung together but command will exit
|
||||
with the first non-print option. eg.
|
||||
|
||||
\$ blc.pl == / ^
|
||||
21/100
|
||||
\$ blc.pl == ++
|
||||
('==' ignored)
|
||||
(Backlight incremented)
|
||||
\$ blc.pl == / ^
|
||||
21/100
|
||||
\$ blc.pl == ++
|
||||
('==' ignored)
|
||||
(Backlight incremented)
|
||||
|
||||
Escape options with \\ in quotes to display them literally. eg.
|
||||
|
||||
\$ blc.pl == / ^ '\\=' % \'\\%\'
|
||||
" . $current . "/" . $max . "=" . int($current/$max*100) . "%
|
||||
\$ blc.pl == / ^ '\\=' % \'\\%\'
|
||||
" . $current . "/" . $max . "=" . int($current/$max*100) . "%
|
||||
|
||||
Only one \'\\' is removed per block. eg.
|
||||
|
||||
\$ blc.pl '\\% \\'
|
||||
% \\
|
||||
\$ blc.pl '\\% \\'
|
||||
% \\
|
||||
|
||||
";
|
||||
}
|
||||
|
@ -252,140 +252,140 @@ my (@output, $target, $silent, $notify);
|
|||
|
||||
my $operation_found = 0;
|
||||
if (scalar @ARGV) {
|
||||
while ($arg = shift) {
|
||||
if ($arg eq '%') {
|
||||
push @output,to_percent(get_current);
|
||||
} elsif ($arg eq '^') {
|
||||
push @output,get_max();
|
||||
} elsif ($arg eq '==') {
|
||||
push @output,get_current();
|
||||
} elsif ($arg eq '--help') {
|
||||
help();
|
||||
print " (see --HELP).\n\n";
|
||||
exit();
|
||||
} elsif ($arg eq '--HELP') {
|
||||
help();
|
||||
advanced();
|
||||
exit();
|
||||
} elsif ($arg eq '--silent') {
|
||||
$silent = 1;
|
||||
} elsif ($arg =~ /^--notify/) {
|
||||
$notify = 1;
|
||||
if ($arg =~ /=[0-9]+$/) {
|
||||
$duration = $arg;
|
||||
$duration =~ s/.*=([0-9]+)/$1/;
|
||||
} else {
|
||||
$duration = 1000;
|
||||
}
|
||||
} elsif ($arg eq '+') {
|
||||
unshift(@ARGV,1);
|
||||
unshift(@ARGV,'+=');
|
||||
} elsif ($arg =~ /^\+=/) {
|
||||
my $offset;
|
||||
if ($arg =~ m/^\+=(.+)$/) {
|
||||
$offset = $1;
|
||||
} else {
|
||||
$offset = shift || die "+= without accompanying offset value\n";
|
||||
}
|
||||
unless ($offset =~ /^\d+$/) {
|
||||
die "+= <value> is not a number ($offset)\n";
|
||||
}
|
||||
for (my $j=0;$j<$offset;$j++) {
|
||||
$target = increment();
|
||||
@output = to_percent($target);
|
||||
}
|
||||
$operation_found = 1;
|
||||
} elsif ($arg eq '-') {
|
||||
unshift(@ARGV,1);
|
||||
unshift(@ARGV,'-=');
|
||||
} elsif ($arg =~ /^-=/) {
|
||||
my $offset;
|
||||
if ($arg =~ m/^-=(.+)$/) {
|
||||
$offset = $1;
|
||||
} else {
|
||||
$offset = shift || die "-= without accompanying offset value\n";
|
||||
}
|
||||
unless ($offset =~ /^\d+$/) {
|
||||
die "-= <value> is not a number ($offset)\n";
|
||||
}
|
||||
for (my $j=0;$j<$offset;$j++) {
|
||||
$target = decrement();
|
||||
@output = to_percent($target);
|
||||
}
|
||||
$operation_found = 1;
|
||||
} elsif ($arg =~ m/^=/) {
|
||||
my $value;
|
||||
if ($arg =~ m/^=(.+)$/) {
|
||||
$target = $1;
|
||||
} else {
|
||||
$target = shift || die "= without accompanying absolute value\n";
|
||||
}
|
||||
unless ($target =~ /^\d+$/) {
|
||||
die "= <value> is not a number ($target)\n";
|
||||
}
|
||||
if ($target < 1) {
|
||||
$target = set(get_min());
|
||||
} elsif ($target > get_max()) {
|
||||
$target = set(get_max());
|
||||
} elsif ($target > 100) {
|
||||
$target = set($target);
|
||||
} else {
|
||||
$target = set(
|
||||
int((get_max()*$target/100)+1)
|
||||
);
|
||||
}
|
||||
@output = to_percent($target);
|
||||
$operation_found = 1;
|
||||
} else {
|
||||
push(@output,$arg);
|
||||
}
|
||||
while ($arg = shift) {
|
||||
if ($arg eq '%') {
|
||||
push @output,to_percent(get_current);
|
||||
} elsif ($arg eq '^') {
|
||||
push @output,get_max();
|
||||
} elsif ($arg eq '==') {
|
||||
push @output,get_current();
|
||||
} elsif ($arg eq '--help') {
|
||||
help();
|
||||
print " (see --HELP).\n\n";
|
||||
exit();
|
||||
} elsif ($arg eq '--HELP') {
|
||||
help();
|
||||
advanced();
|
||||
exit();
|
||||
} elsif ($arg eq '--silent') {
|
||||
$silent = 1;
|
||||
} elsif ($arg =~ /^--notify/) {
|
||||
$notify = 1;
|
||||
if ($arg =~ /=[0-9]+$/) {
|
||||
$duration = $arg;
|
||||
$duration =~ s/.*=([0-9]+)/$1/;
|
||||
} else {
|
||||
$duration = 1000;
|
||||
}
|
||||
} elsif ($arg eq '+') {
|
||||
unshift(@ARGV,1);
|
||||
unshift(@ARGV,'+=');
|
||||
} elsif ($arg =~ /^\+=/) {
|
||||
my $offset;
|
||||
if ($arg =~ m/^\+=(.+)$/) {
|
||||
$offset = $1;
|
||||
} else {
|
||||
$offset = shift || die "+= without accompanying offset value\n";
|
||||
}
|
||||
unless ($offset =~ /^\d+$/) {
|
||||
die "+= <value> is not a number ($offset)\n";
|
||||
}
|
||||
for (my $j=0;$j<$offset;$j++) {
|
||||
$target = increment();
|
||||
@output = to_percent($target);
|
||||
}
|
||||
$operation_found = 1;
|
||||
} elsif ($arg eq '-') {
|
||||
unshift(@ARGV,1);
|
||||
unshift(@ARGV,'-=');
|
||||
} elsif ($arg =~ /^-=/) {
|
||||
my $offset;
|
||||
if ($arg =~ m/^-=(.+)$/) {
|
||||
$offset = $1;
|
||||
} else {
|
||||
$offset = shift || die "-= without accompanying offset value\n";
|
||||
}
|
||||
unless ($offset =~ /^\d+$/) {
|
||||
die "-= <value> is not a number ($offset)\n";
|
||||
}
|
||||
for (my $j=0;$j<$offset;$j++) {
|
||||
$target = decrement();
|
||||
@output = to_percent($target);
|
||||
}
|
||||
$operation_found = 1;
|
||||
} elsif ($arg =~ m/^=/) {
|
||||
my $value;
|
||||
if ($arg =~ m/^=(.+)$/) {
|
||||
$target = $1;
|
||||
} else {
|
||||
$target = shift || die "= without accompanying absolute value\n";
|
||||
}
|
||||
unless ($target =~ /^\d+$/) {
|
||||
die "= <value> is not a number ($target)\n";
|
||||
}
|
||||
if ($target < 1) {
|
||||
$target = set(get_min());
|
||||
} elsif ($target > get_max()) {
|
||||
$target = set(get_max());
|
||||
} elsif ($target > 100) {
|
||||
$target = set($target);
|
||||
} else {
|
||||
$target = set(
|
||||
int((get_max()*$target/100)+1)
|
||||
);
|
||||
}
|
||||
@output = to_percent($target);
|
||||
$operation_found = 1;
|
||||
} else {
|
||||
push(@output,$arg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@output = (
|
||||
'{"Backlight":{"Max":"'
|
||||
. get_max()
|
||||
. '","Current":"'
|
||||
. get_current()
|
||||
. '","Percentage","'
|
||||
. int(get_current()/get_max()*100)
|
||||
. '%"}}'
|
||||
);
|
||||
@output = (
|
||||
'{"Backlight":{"Max":"'
|
||||
. get_max()
|
||||
. '","Current":"'
|
||||
. get_current()
|
||||
. '","Percentage","'
|
||||
. int(get_current()/get_max()*100)
|
||||
. '%"}}'
|
||||
);
|
||||
}
|
||||
|
||||
if ($silent) {
|
||||
exit();
|
||||
exit();
|
||||
} elsif ($notify) {
|
||||
my $concat = '';
|
||||
foreach (@output) {
|
||||
$concat .= $_;
|
||||
}
|
||||
my $concat = '';
|
||||
foreach (@output) {
|
||||
$concat .= $_;
|
||||
}
|
||||
=pod
|
||||
use Gtk2::Notify -init, "Backlight";
|
||||
my $notification = Gtk2::Notify::new('Backlight', $concat, '', "notification-display-brightness");
|
||||
use Gtk2::Notify -init, "Backlight";
|
||||
my $notification = Gtk2::Notify::new('Backlight', $concat, '', "notification-display-brightness");
|
||||
|
||||
$notification->set_hint_string('x-canonical-private-synchronous','blc');
|
||||
$notification->set_urgency('NOTIFY_URGENCY_LOW');
|
||||
$notification->set_hint_int32('value',(split('%',$concat))[0]);
|
||||
$notification->set_timeout($duration);
|
||||
$notification->show();
|
||||
exit;
|
||||
print "notify-send --urgency=normal"
|
||||
. ' --icon="notification-display-brightness"'
|
||||
. ' --hint=string:x-canonical-private-synchronous:blc'
|
||||
. ' --expire-time=' . $duration
|
||||
. ' "Backlight"'
|
||||
. ' "' . $concat . " '" . join("','", @output) . "'\"";
|
||||
system "notify-send --urgency=normal"
|
||||
. ' --icon="notification-display-brightness"'
|
||||
. ' --hint=string:x-canonical-private-synchronous:blc'
|
||||
. ' --hint=int:value:' . (split('%',$concat))[0]
|
||||
. ' --expire-time=' . $duration
|
||||
. ' "' . $concat . "\"";
|
||||
$notification->set_hint_string('x-canonical-private-synchronous','blc');
|
||||
$notification->set_urgency('NOTIFY_URGENCY_LOW');
|
||||
$notification->set_hint_int32('value',(split('%',$concat))[0]);
|
||||
$notification->set_timeout($duration);
|
||||
$notification->show();
|
||||
exit;
|
||||
print "notify-send --urgency=normal"
|
||||
. ' --icon="notification-display-brightness"'
|
||||
. ' --hint=string:x-canonical-private-synchronous:blc'
|
||||
. ' --expire-time=' . $duration
|
||||
. ' "Backlight"'
|
||||
. ' "' . $concat . " '" . join("','", @output) . "'\"";
|
||||
system "notify-send --urgency=normal"
|
||||
. ' --icon="notification-display-brightness"'
|
||||
. ' --hint=string:x-canonical-private-synchronous:blc'
|
||||
. ' --hint=int:value:' . (split('%',$concat))[0]
|
||||
. ' --expire-time=' . $duration
|
||||
. ' "' . $concat . "\"";
|
||||
=cut
|
||||
|
||||
exit();
|
||||
exit();
|
||||
} else {
|
||||
print foreach @output;
|
||||
print "\n";
|
||||
exit();
|
||||
print foreach @output;
|
||||
print "\n";
|
||||
exit();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ foreach (@devices) {
|
|||
close $t;
|
||||
$output .= '"Type":"' . $type . '"';
|
||||
if ($name =~ /BAT[0-9]+/) {
|
||||
$nobat = 0;
|
||||
open(my $s,'<',"$_/status");
|
||||
my $status = <$s>;
|
||||
chomp $status;
|
||||
|
@ -86,10 +85,6 @@ foreach (@devices) {
|
|||
}
|
||||
$output .= "},";
|
||||
}
|
||||
unless ($nobat) {
|
||||
print('{"AC":{"Type":"AC","Status":"Plugged-In"}}');
|
||||
exit();
|
||||
}
|
||||
|
||||
$battery_total{'percentage'} = sprintf("%0d",
|
||||
$battery_total{'current'} / $battery_total{'max'} * 100
|
||||
|
@ -109,13 +104,13 @@ if ($bar) {
|
|||
my $class = 'discharging';
|
||||
$output = '';
|
||||
if ($powref->{AC}->{Status} eq "Plugged-In") {
|
||||
$class = 'charging';
|
||||
$class = 'charging';
|
||||
$output .= "";
|
||||
} elsif ($powref->{Total}->{Percentage} <= 10) {
|
||||
$class = 'critical';
|
||||
$class = 'critical';
|
||||
$output .= "";
|
||||
} elsif ($powref->{Total}->{Percentage} <= 35) {
|
||||
$class = 'low';
|
||||
$class = 'low';
|
||||
$output .= "";
|
||||
} elsif ($powref->{Total}->{Percentage} <= 60) {
|
||||
$output .= "";
|
||||
|
@ -138,11 +133,11 @@ if ($bar) {
|
|||
my $total = '';
|
||||
$output = "Device Status Percentage\n";
|
||||
foreach my $device (keys %{$powref}) {
|
||||
my $status;
|
||||
my $status;
|
||||
if ($powref->{$device}->{Status} eq "Plugged-In") {
|
||||
$status = "";
|
||||
} elsif (!defined($powref->{$device}->{Percentage}) || $powref->{$device}->{Percentage} == 0) {
|
||||
$status = " ";
|
||||
$status = "";
|
||||
} elsif (!defined($powref->{$device}->{Percentage}) || $powref->{$device}->{Percentage} == 0) {
|
||||
$status = " ";
|
||||
} elsif ($powref->{$device}->{Percentage} <= 10) {
|
||||
$status = " " . $powref->{$device}->{'Percentage'} . "%";
|
||||
} elsif ($powref->{$device}->{Percentage} <= 35) {
|
||||
|
@ -153,19 +148,19 @@ if ($bar) {
|
|||
$status = " " . $powref->{$device}->{'Percentage'} . "%";
|
||||
} else {
|
||||
$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;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ elif [ "$1" == 'upgrade' ]; then
|
|||
COUNT=`apt list --upgradable 2> /dev/null | wc -l`
|
||||
let COUNT--
|
||||
echo $COUNT > /home/jpm/.spool/apt-upgradeable
|
||||
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"
|
||||
fi
|
||||
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"
|
||||
fi
|
||||
elif [ "$1" == 'update' ]; then
|
||||
sudo apt update >/dev/null 2>/dev/null
|
||||
COUNT=`apt list --upgradable 2> /dev/null | wc -l`
|
||||
|
|
|
@ -6,7 +6,7 @@ swaymsg -t get_tree |
|
|||
sed -e 's/^\(.*\) [—-] .*$/\1/'|
|
||||
sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' |
|
||||
wofi -s $HOME/.dotfiles/wofi/style.css -c \
|
||||
$HOME/.dotfiles/wofi/sidebar -d | {
|
||||
$HOME/.dotfiles/wofi/sidebar -d | {
|
||||
read -r
|
||||
id=`echo $REPLY | rev | cut -d' ' -f1 | rev`
|
||||
swaymsg "[con_id=$id]" focus
|
||||
|
|
|
@ -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)
|
||||
if [[ $CHENTRY == "" ]]; then
|
||||
exit
|
||||
exit
|
||||
fi
|
||||
#echo "$CHENTRY"
|
||||
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}')
|
||||
|
|
Loading…
Reference in New Issue