mirror of
https://github.com/Gerg-L/nixos.git
synced 2025-12-10 00:43:56 -05:00
refactor: move zellij to shared module
This commit is contained in:
parent
362b9dda0f
commit
5b9d021b59
3 changed files with 39 additions and 18 deletions
39
nixosModules/zellij/default.nix
Normal file
39
nixosModules/zellij/default.nix
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
}:
|
||||
{
|
||||
options.local.zellij = lib.mkEnableOption "zellij" // {
|
||||
default = true;
|
||||
};
|
||||
|
||||
config = lib.mkIf config.local.zellij {
|
||||
local.packages = {
|
||||
inherit (pkgs) zellij;
|
||||
};
|
||||
|
||||
programs.zsh.interactiveShellInit =
|
||||
let
|
||||
monitorScript = pkgs.replaceVarsWith {
|
||||
src = ./monitor.ps;
|
||||
replacements = builtins.mapAttrs (_: lib.getExe) {
|
||||
inherit (pkgs) perl xdotool;
|
||||
};
|
||||
isExecutable = true;
|
||||
};
|
||||
in
|
||||
''
|
||||
if [[ -z "$ZELLIJ" ]]; then
|
||||
if [[ -n "$SSH_TTY" ]]; then
|
||||
zellij attach -c "SSH@$USER"
|
||||
else
|
||||
MONITOR="$(${monitorScript} || true)"
|
||||
zellij attach -c "''${MONITOR:+"$MONITOR@"}$USER"
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
'';
|
||||
|
||||
};
|
||||
}
|
||||
45
nixosModules/zellij/monitor.ps
Normal file
45
nixosModules/zellij/monitor.ps
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#!@perl@
|
||||
|
||||
use strict;
|
||||
|
||||
my %M; # hash to hold keys from 'xdotool getmouselocation --shell'
|
||||
my $pipe; # file handle for the pipes we're going to open
|
||||
|
||||
# get the current cursor location into $M{X} and $M{Y}
|
||||
open($pipe, "-|", qw(@xdotool@ getmouselocation --shell)) ||
|
||||
die "couldn't open pipe from xdotool: $!\n";
|
||||
|
||||
while(<$pipe>) {
|
||||
chomp;
|
||||
my($key, $val) = split /=/;
|
||||
$M{$key} = $val;
|
||||
};
|
||||
close($pipe);
|
||||
|
||||
# compare mouse location to monitor co-ordinates
|
||||
open($pipe, "-|", "xrandr") ||
|
||||
die "couldn't open pipe from xrandr: $!\n";
|
||||
|
||||
while(<$pipe>) {
|
||||
my ($display, $width, $height, $x_offset, $y_offset);
|
||||
|
||||
next unless m/ connected /;
|
||||
my @F = split;
|
||||
$display = $F[0];
|
||||
|
||||
# co-ordinates are on fourth field (F[3]) on the primary display
|
||||
# or on third field (F[2]) on non-primary displays. Perl arrays
|
||||
# start from zero, not one (same as in bash).
|
||||
if ($F[2] eq "primary") {
|
||||
($width, $height, $x_offset, $y_offset) = split /[x+]/, $F[3];
|
||||
} else {
|
||||
($width, $height, $x_offset, $y_offset) = split /[x+]/, $F[2];
|
||||
};
|
||||
|
||||
if ($M{X} >= $x_offset && $M{X} <= $width + $x_offset &&
|
||||
$M{Y} >= $y_offset && $M{Y} <= $height + $y_offset) {
|
||||
print "$display\n";
|
||||
last;
|
||||
};
|
||||
};
|
||||
close($pipe);
|
||||
Loading…
Add table
Add a link
Reference in a new issue