3 Commits

Author SHA1 Message Date
David Tomaschik
3f9c41d266 Merge branch 'main' of https://github.com/Matir/skel 2026-04-06 18:34:17 -07:00
David Tomaschik
69e4b83652 Fix brew manager 2026-04-06 18:34:06 -07:00
David Tomaschik
74c2472dd2 Fix zsh completion 2026-04-06 15:30:14 -07:00
2 changed files with 62 additions and 28 deletions

View File

@@ -48,6 +48,7 @@ def parse_brewfile(content):
"""
Parses Brewfile content.
Returns:
- unconditional_lines: list of strings
- conditional_pkgs: set of (type, name)
- preserved_footer: string (everything from first conditional onwards)
"""
@@ -60,7 +61,7 @@ def parse_brewfile(content):
for i, line in enumerate(lines):
stripped = line.strip()
if stripped.startswith(('if ', 'unless ', 'case ')) and not stripped.endswith('; end'):
if stripped.startswith(('if ', 'unless ', 'case ', 'def ', 'begin ')) and not stripped.endswith('; end'):
if first_conditional_idx == -1:
# Look back for comments that might belong to this block
j = i - 1
@@ -78,10 +79,11 @@ def parse_brewfile(content):
in_conditional -= 1
if first_conditional_idx == -1:
return set(), ""
return lines, set(), ""
unconditional_lines = lines[:first_conditional_idx]
footer = "\n".join(lines[first_conditional_idx:])
return conditional_pkgs, footer
return unconditional_lines, conditional_pkgs, footer
def main(args):
repo_root = get_repo_root()
@@ -94,25 +96,52 @@ def main(args):
with open(brewfile_path) as f:
old_content = f.read()
conditional_pkgs, footer = parse_brewfile(old_content)
unconditional_lines, conditional_pkgs, footer = parse_brewfile(old_content)
ignore_list = get_ignore_list(repo_root)
dumped_lines = get_current_packages()
new_unconditional_lines = []
for line in dumped_lines:
match = PKG_RE.match(line)
if match:
pkg_type, pkg_name = match.group(1), match.group(2)
if pkg_name in ignore_list:
continue
if (pkg_type, pkg_name) in conditional_pkgs:
continue
seen_pkgs = set()
if args.add_only:
# First, keep existing unconditional packages
for line in unconditional_lines:
match = PKG_RE.match(line)
if match:
pkg_type, pkg_name = match.group(1), match.group(2)
if pkg_name in ignore_list or (pkg_type, pkg_name) in conditional_pkgs:
continue
new_unconditional_lines.append(line)
seen_pkgs.add((pkg_type, pkg_name))
elif line.strip() and not line.strip().startswith('#'):
# Keep other non-comment lines
new_unconditional_lines.append(line)
# If it's not a package line (e.g. comment from dump), we can skip or keep
if line.strip():
new_unconditional_lines.append(line)
# Then, add new packages from dump
for line in dumped_lines:
match = PKG_RE.match(line)
if match:
pkg_type, pkg_name = match.group(1), match.group(2)
if (pkg_type, pkg_name) not in seen_pkgs and pkg_name not in ignore_list and (pkg_type, pkg_name) not in conditional_pkgs:
new_unconditional_lines.append(line)
seen_pkgs.add((pkg_type, pkg_name))
else:
for line in dumped_lines:
match = PKG_RE.match(line)
if match:
pkg_type, pkg_name = match.group(1), match.group(2)
if pkg_name in ignore_list:
continue
if (pkg_type, pkg_name) in conditional_pkgs:
continue
if (pkg_type, pkg_name) in seen_pkgs:
continue
seen_pkgs.add((pkg_type, pkg_name))
# If it's not a package line (e.g. comment from dump), we can skip or keep
if line.strip():
new_unconditional_lines.append(line)
# Sort lines by type (tap, brew, cask, mas) then name
def sort_key(line):
@@ -152,5 +181,6 @@ def main(args):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Update Brewfile while preserving conditionals.")
parser.add_argument("--dry-run", action="store_true", help="Show changes without applying them.")
parser.add_argument("--add-only", action="store_true", help="Only add missing entries, do not remove existing ones.")
args = parser.parse_args()
main(args)

View File

@@ -1,6 +1,7 @@
# For interactive shells
[[ -n "$ZSH_PROFILE" ]] && {
zshrc_start_time=$(date +%s.%N)
zmodload zsh/datetime
zshrc_start_time=$EPOCHREALTIME
zmodload zsh/zprof
}
HISTFILE=~/.zhistory
@@ -208,16 +209,19 @@ if [[ $- == *i* ]] ; then
# Regenerate zcompdump if it's older than any file in fpath
DUMPFILE="${ZDOTDIR:-$HOME}/.zcompdump"
updated_files=(${^fpath}(N.om[1]))
# Find the newest file across all fpath directories to detect edits/additions
# (N.om[1]) = Null-glob, plain files only, sort by mtime, pick the first (newest)
local newest_comp=(${^fpath}/*(N.om[1]))
if [[ ! -f "$DUMPFILE" || ( ${#updated_files} -gt 0 && "$updated_files[1]" -nt "$DUMPFILE" ) ]]; then
compinit -i -D "$DUMPFILE"
# Asynchronously compile the dump file
{ zcompile "$DUMPFILE" } &!
# If any completion file was modified, or dump doesn't exist, we might need to update.
if [[ ! -f "$DUMPFILE" || ( -n "$newest_comp" && "$newest_comp" -nt "$DUMPFILE" ) ]]; then
compinit -i -d "$DUMPFILE"
# Asynchronously compile the dump file with an atomic rename
{ zcompile "$DUMPFILE.zwc.tmp" "$DUMPFILE" && mv -f "$DUMPFILE.zwc.tmp" "$DUMPFILE.zwc" } &!
else
compinit -C -i -D "$DUMPFILE"
compinit -C -i -d "$DUMPFILE"
fi
unset DUMPFILE updated_files
unset DUMPFILE newest_comp
autoload -Uz promptinit && promptinit
# Virtualenvwrapper
source_first_existing \
@@ -292,9 +296,9 @@ fi
typeset -U PATH
if [[ -n "$ZSH_PROFILE" ]]; then
zshrc_end_time=$(date +%s.%N)
elapsed_seconds=$(echo "$zshrc_end_time - $zshrc_start_time" | bc -l)
elapsed_ms=$(printf "%.0f" "$(echo "$elapsed_seconds * 1000" | bc -l)")
echo "zshrc done: ${elapsed_ms}ms"
zshrc_end_time=$EPOCHREALTIME
# Calculation in ms using zsh floating point math
elapsed_ms=$(( (zshrc_end_time - zshrc_start_time) * 1000 ))
printf "zshrc done: %.0fms\n" "$elapsed_ms"
zprof
fi