1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-29 19:17:45 +00:00

Shadow popup triggering Darwin binaries and set zshrc in rebuild.nu

This commit is contained in:
RGBCube 2025-01-24 23:50:51 +03:00
parent ce4be21e2e
commit f691a27456

View file

@ -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
}