summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2023-11-07 17:37:37 +0100
committerLinnnus <[email protected]>2023-11-07 17:37:37 +0100
commit3824d4d797d39bd6f2dee3655027a79713ef400c (patch)
tree617a3e9294573604aaedc04c72973639cc919954
parentf538d7e75a4caba9d4bff0a3273c8cd5efa616ff (diff)
home/zsh+pkgs: Add watch-while for long commands lol
-rw-r--r--home/zsh/default.nix1
-rw-r--r--home/zsh/watch-while.nix20
-rw-r--r--pkgs/default.nix2
-rw-r--r--pkgs/watch-while/default.nix23
-rw-r--r--pkgs/watch-while/watch-while.zsh19
5 files changed, 65 insertions, 0 deletions
diff --git a/home/zsh/default.nix b/home/zsh/default.nix
index b759b0e..e45f731 100644
--- a/home/zsh/default.nix
+++ b/home/zsh/default.nix
@@ -2,6 +2,7 @@
imports = [
./plugins.nix
./editing.nix
+ ./watch-while.nix
];
programs.zsh = {
diff --git a/home/zsh/watch-while.nix b/home/zsh/watch-while.nix
new file mode 100644
index 0000000..d3d6422
--- /dev/null
+++ b/home/zsh/watch-while.nix
@@ -0,0 +1,20 @@
+# This module configures some ZSH aliases such that 'watch-while' is invoked
+{
+ pkgs,
+ lib,
+ ...
+}: let
+ # Program to invoke for long-running commands.
+ pkg = pkgs.watch-while;
+ exec = "${pkg}/bin/watch-while";
+in {
+ # Alias long-running commands to their prefixed versions. These aliases are
+ # only loaded for interactive use, so they won't mess with scripts.
+ programs.zsh.shellAliases =
+ lib.genAttrs ["nixos-rebuild" "darwin-rebuild"] (p: "${exec} ${p}")
+ # Enable alias expansion after sudo with this trick.
+ // {"sudo" = "sudo ";};
+
+ # Also add the program to the environment for manual invocation.
+ home.packages = [pkg];
+}
diff --git a/pkgs/default.nix b/pkgs/default.nix
index 2953063..5ab245a 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -9,6 +9,8 @@ pkgs: {
mcping = pkgs.callPackage ./mcping {};
+ watch-while = pkgs.callPackage ./watch-while {};
+
# TODO: These should be contained in the 'vimPlugins' attrset. This turns out
# to be non-trivial because this module is both consumed in a flake output
# context and an overlay context.
diff --git a/pkgs/watch-while/default.nix b/pkgs/watch-while/default.nix
new file mode 100644
index 0000000..fb29441
--- /dev/null
+++ b/pkgs/watch-while/default.nix
@@ -0,0 +1,23 @@
+{
+ zsh,
+ mpv,
+ stdenvNoCC,
+}:
+stdenvNoCC.mkDerivation rec {
+ pname = "watch-while";
+ version = "0.1.0";
+
+ src = ./watch-while.zsh;
+ unpackPhase = ":";
+
+ buildPhase = ''
+ substituteAll $src ${pname}
+ chmod +x ${pname}
+ '';
+ inherit zsh mpv;
+
+ installPhase = ''
+ mkdir -p $out/bin
+ mv ${pname} $out/bin/
+ '';
+}
diff --git a/pkgs/watch-while/watch-while.zsh b/pkgs/watch-while/watch-while.zsh
new file mode 100644
index 0000000..d38d393
--- /dev/null
+++ b/pkgs/watch-while/watch-while.zsh
@@ -0,0 +1,19 @@
+#!@zsh@/bin/zsh
+
+set -ue
+
+# This file should be a (symbolik link to a) file which we want to watch. Once
+# we're finished with that movie, we just read the next.
+movie=${XDG_CONFIG_HOME:-$HOME/.config}/watch-while/movie
+
+if [ -f $movie ]; then
+ @mpv@/bin/mpv --save-position-on-quit --autofit='90%x90%' -- $movie >/dev/null 2>&1 &
+ mpv_pid=$?
+ trap 'kill -s QUIT $mpv_pid' EXIT
+
+ # We don't exec because we want our exec handler to fire.
+ "$@" || exit $?
+else
+ # In this case where we don't have any movie we just transparently run the command.
+ exec "$@"
+fi