Introduction
This is a collection of command-line utilities designed to make your daily Linux workflow a bit less... tedious. It's not like I built these because I enjoy helping, but someone had to do it. You'll find tools for quick AI assistance, automatic command fixing, and even a way to block those pesky distracting websites.
Installation
Getting these tools set up is quite simple. Just follow these steps. Don't mess it up.
- Clone the Repository:
git clone https://github.com/anas1412/scripts.git cd scripts
- Run the Installer:
The installer handles dependencies, copies scripts to
~/scripts/
, and configures your shell.chmod +x install ./install
Note: The script will prompt you for your Google Gemini API key. Ensure you have Python3 and pip3 installed; the installer will attempt to install the necessary Python library (`google-generativeai`) for your user.
- Activate Changes:
After installation, refresh your shell to load the new commands and configurations.
source ~/.zshrc # If you use Zsh # OR source ~/.bashrc # If you use Bash # OR simply close and reopen your terminal window.
ai
Command
Purpose
The ai
command allows you to quickly query an AI assistant for Linux-related questions. It provides a brief explanation and the most relevant command.
Usage
Simply type ai
followed by your question in quotes.
ai "how do I recursively copy files and keep their permissions"
# Expected output example:
# To recursively copy files and preserve permissions, use 'cp -a'.
# cp -a source_directory/ destination_directory/
Details
- This command is an alias that calls the
gemini_ai_helper.py
script located in~/scripts/
. - It relies on your
GEMINI_API_KEY
being set in your environment. - The AI attempts to provide a concise, one-to-two-sentence explanation followed immediately by the raw command without markdown formatting.
fix
Command
Purpose
Did your last command fail? Instead of re-typing, just use fix
. This command analyzes the error output of your previous command and uses AI to suggest a corrected version, giving you an option to execute it immediately.
Usage
Run a command that you expect to fail (or one that just did), then type fix
.
# Example: A typo in a common command
sudo apt updatee
# Output from apt:
# E: Invalid operation updatee
# E: Failed to fetch some archives, maybe run apt-get update or try with --fix-missing?
# Now, type 'fix':
fix
# Expected interaction:
# Attempting to re-run: sudo apt updatee
# The previous command failed (exit code 100).
# Sending details to AI for a suggested fix...
#
# AI suggests:
# sudo apt update
# Execute suggested command? (y/N): y
# # If you type 'y', 'sudo apt update' will then be executed.
Details
- The
fix
command is a shell function (not a simple alias) that captures the exact previous command and its full standard output/error. - It passes this information to the
gemini_try_helper.py
script. - The AI is instructed to return *only* the raw, corrected command.
- It will not attempt to fix itself or empty commands.
blocker
Script
Purpose
The blocker
script helps you easily manage entries in your /etc/hosts
file to block specific websites. Useful for focus, or just... being picky about what you access.
Usage
The script uses actions (add
, remove
, edit
, list
) followed by domain names.
Add Domains
blocker add facebook.com twitter.com
# Adds 127.0.0.1 entries for facebook.com, www.facebook.com, twitter.com, www.twitter.com
List Blocked Domains
blocker list
# Displays the domains currently managed by the blocker script in /etc/hosts
Remove Domains
blocker remove facebook.com
Edit a Domain
blocker edit oldsite.com newsite.com
# Replaces oldsite.com (and its www. version) with newsite.com (and its www. version)
Get Help
blocker help
# Displays usage instructions
Details
- The script modifies
/etc/hosts
, which requires root privileges. It handles thesudo
calls internally, so you don't need to prefixblocker
withsudo
yourself. - It adds a special marker (
# --blocker-managed--
) to lines it manages, preventing it from interfering with other entries in your hosts file. - When adding or removing a domain, it automatically includes the
www.
subdomain version for comprehensive blocking.
install
Script
Purpose
This script orchestrates the entire setup of Anas's CLI Toolkit. It's the first thing you run to get everything working.
Usage
Run from the root of the cloned repository:
chmod +x install
./install
Details
- Checks for
pip3
and installs thegoogle-generativeai
Python package to your user's site-packages. - Creates the
~/scripts/
directory if it doesn't exist. - Copies
gemini_ai_helper.py
,gemini_try_helper.py
, andblocker
from the cloned repository into~/scripts/
. - **Generates and populates**
~/scripts/shell_config.sh
with the definitions for theai
alias andfix
function. This file is *not* part of the GitHub repository itself. - Makes all necessary scripts executable.
- Adds/updates specific blocks in your
~/.bashrc
and~/.zshrc
to:- Export your
GEMINI_API_KEY
. - Add
~/scripts/
to yourPATH
. - Source the newly created
~/scripts/shell_config.sh
.
- Export your
- Uses unique markers (e.g.,
# --- START ... ---
,# --- END ... ---
) to manage its configuration blocks, allowing safe re-runs without clashing with your existing shell configuration.
shell_config.sh
Purpose
This file acts as a centralized location for the custom shell aliases and functions provided by this toolkit (specifically ai
and fix
). It keeps your main .bashrc
or .zshrc
files cleaner.
Usage
This file is not meant to be run directly by the user. It is automatically:
- Created and populated by the
install
script during setup. - Sourced (loaded) by your
.bashrc
or.zshrc
every time you open a new terminal session. This makes theai
alias andfix
function available.
Details
- It defines the
ai
alias, pointing togemini_ai_helper.py
. - It defines the
fix
shell function, which orchestrates the logic for fixing failed commands usinggemini_try_helper.py
. - Its primary role is to modularize your shell configuration.