Shell RC File Integration
Relevant source files
The following files were used as context for generating this wiki page:
The Shell RC File Integration system in ollacc is responsible for ensuring the utility is globally accessible to the user via a persistent shell alias. By automating the modification of standard shell configuration files (RC files), the project eliminates the need for users to manually manage path variables or remember the specific installation directory. This integration is designed to be idempotent during installation and reversible during uninstallation.
Sources: install.sh:8-11, README.md:52-57
RC File Selection Logic
During the installation process, the system performs a sequential search for the user's primary shell configuration file. This ensures that the ollacc alias is placed where the user's current shell environment is most likely to load it.
Candidate Search Order
The installer iterates through a prioritized list of hidden files in the user's home directory. The first file found becomes the target for the alias injection.
| Order | File Name | Context |
|---|---|---|
| 1 | .zshrc | Default for modern macOS and many Zsh users |
| 2 | .bashrc | Primary configuration for interactive Bash shells |
| 3 | .bash_profile | Login shell configuration for Bash |
| 4 | .profile | Generic fallback for sh-compatible shells |
If none of the above files exist, the installer creates a new ~/.profile file and sets the appropriate ownership.
Sources: install.sh:75-87, README.md:52-57
Installation and Alias Injection
The installation script uses a marker-based approach to ensure the alias injection is idempotent. This prevents duplicate entries if the installer is run multiple times.
Injection Workflow
The script defines a specific MARKER comment and an ALIAS_LINE that points to the launcher executable within the ~/.ollacc directory.
The flow ensures that if the ALIAS_LINE already exists in the file, no changes are made.
Sources: install.sh:89-102, README.md:58-59
Uninstallation and Cleanup
The uninstall.sh script provides a mechanism to revert changes made to shell RC files. Unlike the installer, which stops at the first file found, the uninstaller scans all potential candidate files to ensure total removal of the alias.
Removal Logic
The uninstaller uses awk to process files. It searches for the specific # ollacc: alias marker and removes it along with the subsequent alias line. It also attempts to clean up the preceding blank line typically added during installation to maintain file cleanliness.
| Component | Target String | Action |
|---|---|---|
| Marker | # ollacc: alias | Identified as the deletion trigger |
| Alias | alias ollacc="..." | Removed if following the marker |
| Whitespace | \n | Preceding blank line is stripped |
Sources: uninstall.sh:22-48
Sequence of Uninstallation
Sources: uninstall.sh:22-63, README.md:121-125
Security and Permission Handling
The integration logic includes specific checks to handle environments where the scripts might be executed via sudo.
- User Detection: The scripts determine the
REAL_USERandREAL_HOMEby checkingSUDO_USERor queryinggetent passwd. This ensures that even if run as root, the alias is added to the human user's home directory. - Ownership Correction: If executed under
sudo, the scripts explicitly runchownon the modified RC files and the~/.ollaccdirectory to return ownership to theREAL_USER. - File Permissions: Config files are created with
chmod 600to protect sensitive API tokens, while the launcher is set to755for execution.
Sources: install.sh:17-26, install.sh:105-109, lib/config.sh:45-48, lib/auth.sh:44
Summary
The Shell RC File Integration provides a seamless "install and use" experience by managing shell aliases across various Unix-like shell environments. Through idempotent injection and precise uninstallation logic, it maintains system cleanliness while ensuring the ollacc command remains persistent across terminal sessions.