Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions alix/shell_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,28 @@ def preview_aliases(self, target_file: Optional[Path] = None) -> Tuple[str, str]
end_idx = content.find(self.ALIX_MARKER_END)

old_alix = ""
if start_idx != -1 and end_idx != -1:
old_alix = content[start_idx:]
if start_idx != -1 and end_idx != -1 and start_idx < end_idx:
old_alix = content[start_idx:end_idx + len(self.ALIX_MARKER_END)]
content = content[:start_idx] + content[end_idx + len(self.ALIX_MARKER_END) + 1:]
elif start_idx != -1:
# Incomplete start marker, remove content after it
old_alix = ""
content = content[:start_idx]
elif end_idx != -1:
# Incomplete end marker, remove non-comment content before it
old_alix = ""
before = content[:end_idx]
lines = before.split('\n')
kept_lines = [line for line in lines if line.strip().startswith('#') or line.strip() == '']
content = '\n'.join(kept_lines) + '\n' + content[end_idx + len(self.ALIX_MARKER_END) + 1:]

# Add new aliases section
aliases_section = f"\n{self.ALIX_MARKER_START}\n"
aliases_section += f"# Generated by alix on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
aliases_section += self.export_aliases(self.shell_type)
aliases_section += f"\n{self.ALIX_MARKER_END}\n"

return (old_alix, aliases_section)
return (old_alix, content + aliases_section)

def apply_aliases(self, target_file: Optional[Path] = None) -> Tuple[bool, str]:
"""Apply aliases to shell configuration file"""
Expand Down
Loading
Loading