mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 21:19:09 -07:00
Compare commits
3 Commits
ecc39344ca
...
3f9c41d266
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f9c41d266 | ||
|
|
69e4b83652 | ||
|
|
74c2472dd2 |
@@ -48,6 +48,7 @@ def parse_brewfile(content):
|
|||||||
"""
|
"""
|
||||||
Parses Brewfile content.
|
Parses Brewfile content.
|
||||||
Returns:
|
Returns:
|
||||||
|
- unconditional_lines: list of strings
|
||||||
- conditional_pkgs: set of (type, name)
|
- conditional_pkgs: set of (type, name)
|
||||||
- preserved_footer: string (everything from first conditional onwards)
|
- preserved_footer: string (everything from first conditional onwards)
|
||||||
"""
|
"""
|
||||||
@@ -60,7 +61,7 @@ def parse_brewfile(content):
|
|||||||
|
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
stripped = line.strip()
|
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:
|
if first_conditional_idx == -1:
|
||||||
# Look back for comments that might belong to this block
|
# Look back for comments that might belong to this block
|
||||||
j = i - 1
|
j = i - 1
|
||||||
@@ -78,10 +79,11 @@ def parse_brewfile(content):
|
|||||||
in_conditional -= 1
|
in_conditional -= 1
|
||||||
|
|
||||||
if first_conditional_idx == -1:
|
if first_conditional_idx == -1:
|
||||||
return set(), ""
|
return lines, set(), ""
|
||||||
|
|
||||||
|
unconditional_lines = lines[:first_conditional_idx]
|
||||||
footer = "\n".join(lines[first_conditional_idx:])
|
footer = "\n".join(lines[first_conditional_idx:])
|
||||||
return conditional_pkgs, footer
|
return unconditional_lines, conditional_pkgs, footer
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
repo_root = get_repo_root()
|
repo_root = get_repo_root()
|
||||||
@@ -94,13 +96,37 @@ def main(args):
|
|||||||
with open(brewfile_path) as f:
|
with open(brewfile_path) as f:
|
||||||
old_content = f.read()
|
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)
|
ignore_list = get_ignore_list(repo_root)
|
||||||
|
|
||||||
dumped_lines = get_current_packages()
|
dumped_lines = get_current_packages()
|
||||||
|
|
||||||
new_unconditional_lines = []
|
new_unconditional_lines = []
|
||||||
|
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)
|
||||||
|
|
||||||
|
# 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:
|
for line in dumped_lines:
|
||||||
match = PKG_RE.match(line)
|
match = PKG_RE.match(line)
|
||||||
if match:
|
if match:
|
||||||
@@ -109,6 +135,9 @@ def main(args):
|
|||||||
continue
|
continue
|
||||||
if (pkg_type, pkg_name) in conditional_pkgs:
|
if (pkg_type, pkg_name) in conditional_pkgs:
|
||||||
continue
|
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 it's not a package line (e.g. comment from dump), we can skip or keep
|
||||||
if line.strip():
|
if line.strip():
|
||||||
@@ -152,5 +181,6 @@ def main(args):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Update Brewfile while preserving conditionals.")
|
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("--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()
|
args = parser.parse_args()
|
||||||
main(args)
|
main(args)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# For interactive shells
|
# For interactive shells
|
||||||
[[ -n "$ZSH_PROFILE" ]] && {
|
[[ -n "$ZSH_PROFILE" ]] && {
|
||||||
zshrc_start_time=$(date +%s.%N)
|
zmodload zsh/datetime
|
||||||
|
zshrc_start_time=$EPOCHREALTIME
|
||||||
zmodload zsh/zprof
|
zmodload zsh/zprof
|
||||||
}
|
}
|
||||||
HISTFILE=~/.zhistory
|
HISTFILE=~/.zhistory
|
||||||
@@ -208,16 +209,19 @@ if [[ $- == *i* ]] ; then
|
|||||||
|
|
||||||
# Regenerate zcompdump if it's older than any file in fpath
|
# Regenerate zcompdump if it's older than any file in fpath
|
||||||
DUMPFILE="${ZDOTDIR:-$HOME}/.zcompdump"
|
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
|
# If any completion file was modified, or dump doesn't exist, we might need to update.
|
||||||
compinit -i -D "$DUMPFILE"
|
if [[ ! -f "$DUMPFILE" || ( -n "$newest_comp" && "$newest_comp" -nt "$DUMPFILE" ) ]]; then
|
||||||
# Asynchronously compile the dump file
|
compinit -i -d "$DUMPFILE"
|
||||||
{ zcompile "$DUMPFILE" } &!
|
# Asynchronously compile the dump file with an atomic rename
|
||||||
|
{ zcompile "$DUMPFILE.zwc.tmp" "$DUMPFILE" && mv -f "$DUMPFILE.zwc.tmp" "$DUMPFILE.zwc" } &!
|
||||||
else
|
else
|
||||||
compinit -C -i -D "$DUMPFILE"
|
compinit -C -i -d "$DUMPFILE"
|
||||||
fi
|
fi
|
||||||
unset DUMPFILE updated_files
|
unset DUMPFILE newest_comp
|
||||||
autoload -Uz promptinit && promptinit
|
autoload -Uz promptinit && promptinit
|
||||||
# Virtualenvwrapper
|
# Virtualenvwrapper
|
||||||
source_first_existing \
|
source_first_existing \
|
||||||
@@ -292,9 +296,9 @@ fi
|
|||||||
typeset -U PATH
|
typeset -U PATH
|
||||||
|
|
||||||
if [[ -n "$ZSH_PROFILE" ]]; then
|
if [[ -n "$ZSH_PROFILE" ]]; then
|
||||||
zshrc_end_time=$(date +%s.%N)
|
zshrc_end_time=$EPOCHREALTIME
|
||||||
elapsed_seconds=$(echo "$zshrc_end_time - $zshrc_start_time" | bc -l)
|
# Calculation in ms using zsh floating point math
|
||||||
elapsed_ms=$(printf "%.0f" "$(echo "$elapsed_seconds * 1000" | bc -l)")
|
elapsed_ms=$(( (zshrc_end_time - zshrc_start_time) * 1000 ))
|
||||||
echo "zshrc done: ${elapsed_ms}ms"
|
printf "zshrc done: %.0fms\n" "$elapsed_ms"
|
||||||
zprof
|
zprof
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user