From f691a2745610eb6570e08263d29e83473cfd126b Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 24 Jan 2025 23:50:51 +0300 Subject: [PATCH] Shadow popup triggering Darwin binaries and set zshrc in rebuild.nu --- rebuild.nu | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/rebuild.nu b/rebuild.nu index 2799699..233dd8b 100755 --- a/rebuild.nu +++ b/rebuild.nu @@ -41,8 +41,86 @@ def main --wrapped [ if (uname | get kernel-name) == "Darwin" { darwin-rebuild switch --flake (".#" + $host) ...$nix_flags + + darwin-shadow-xcode-popup + + darwin-set-zshrc } else { nh os switch . ...$nh_flags -- ...$nix_flags } } +# Replace with the command that has been triggering +# the "install developer tools" popup. +# +# Set by default to "SplitForks" because who even uses that? +const original_trigger = "SplitForks" + +# Where the symbolic links to `false` will be created in +# to shadow all popup-triggering binaries. +# +# Place this in your $env.PATH right before /usr/bin +# to never get the "install developer tools" popup ever again: +# +# ```nu +# let usr_bin_index = $env.PATH +# | enumerate +# | where item == /usr/bin +# | get 0.index +# +# $env.PATH = $env.PATH | insert $usr_bin_index $shadow_path +# ``` +# +# Do NOT set this to a path that you use for other things, +# it will get deleted if it exists to only have the shadowers. +const shadow_path = "~/.local/shadow" # Did you read the comment? + +def darwin-shadow-xcode-popup [] { + print "shadowing xcode popup binaries..." + + let original_size = ls (which $original_trigger | get 0.path) + | get 0.size + + let shadoweds = ls /usr/bin + | flatten + | filter { + # All xcode-select binaries are the same size, so we can narrow down and not run weird stuff. + $in.size == $original_size + } + | filter { + ^$in.name e>| str contains "xcode-select: note: No developer tools were found, requesting install." + } + | get name + | each { path basename } + + let false_path = which "false" | get 0.path + + rm -rf $shadow_path + mkdir $shadow_path + for shadowed in $shadoweds { + let shadow_path = $shadow_path | path join $shadowed + + ln --symbolic $false_path $"($shadow_path)" + } +} + +def darwin-set-zshrc [] { + print "setting zshrc..." + + let nu_command = $" + let usr_bin_index = $env.PATH + | enumerate + | where item == /usr/bin + | get 0.index + + $env.PATH = $env.PATH | insert $usr_bin_index ($shadow_path | path expand) + " + + let zshrc = $" + exec nu --execute ' + ($nu_command) + ' + " + + $zshrc | save --force ~/.zshrc +}