Skip to content

Harshith073/command-log-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Log Tracker

A comprehensive CLI-based monitoring tool that records every command you run in your terminal, along with timestamps and execution duration. Perfect for developers and system administrators who want to analyze their workflows, track repetitive tasks, and generate productivity reports.

Features

  • Automatic Command Tracking: Seamlessly logs every command executed in your terminal
  • Detailed Metrics: Captures timestamps, execution duration, exit codes, and working directories
  • Smart Categorization: Automatically categorizes commands (git, file operations, network, etc.)
  • Productivity Reports: Generate insightful reports about your command usage patterns
  • Data Visualization: Create beautiful charts and graphs using matplotlib
  • Data Persistence: SQLite database ensures your data is safely stored
  • Privacy-First: All data stored locally - no online services required
  • Export Capabilities: Export your command history to CSV for further analysis
  • Search & Filter: Powerful search and filtering capabilities

Installation

Prerequisites

  • Python 3.7 or higher
  • pip (Python package installer)

Setup

  1. Clone or download this repository:
git clone <repository-url>
cd command-log-tracker
  1. Install required Python packages:
pip install matplotlib
  1. Make the CLI executable:
chmod +x cmdtrack
  1. (Optional) Add to your PATH:
export PATH="/path/to/command-log-tracker:$PATH"

Shell Integration

To automatically track all your commands, integrate with your shell:

For Bash

Add this line to your ~/.bashrc:

source /path/to/command-log-tracker/command_tracker/shell_integration/bashrc_integration.sh

Then reload your shell:

source ~/.bashrc

For Zsh

Add this line to your ~/.zshrc:

source /path/to/command-log-tracker/command_tracker/shell_integration/zshrc_integration.sh

Then reload your shell:

source ~/.zshrc

Disable/Enable Tracking

Once integrated, you can temporarily disable or enable tracking:

cmdtrack_disable  # Disable tracking
cmdtrack_enable   # Enable tracking

Usage

Command Line Interface

The cmdtrack command provides various subcommands for managing and analyzing your command history:

View Command History

# Show recent commands (default: 20)
cmdtrack history

# Show more commands
cmdtrack history -l 50

# Search for specific commands
cmdtrack history -s "git"

Generate Statistics

# Basic statistics
cmdtrack stats

# Detailed report
cmdtrack stats --detailed

Productivity Reports

# Generate 7-day productivity report
cmdtrack report

# Custom time period
cmdtrack report --days 30

# Include repetitive tasks analysis
cmdtrack report --repetitive

Data Visualization

# Generate all charts
cmdtrack visualize --all

# Specific chart types
cmdtrack visualize --daily          # Daily activity chart
cmdtrack visualize --categories     # Category distribution pie chart
cmdtrack visualize --heatmap        # Hourly activity heatmap
cmdtrack visualize --top            # Top commands bar chart
cmdtrack visualize --trends         # Category trends over time
cmdtrack visualize --duration       # Execution time distribution

# Custom time period
cmdtrack visualize --all --days 60

Charts are saved to ~/.command_tracker/charts/

Export Data

# Export all commands to CSV
cmdtrack export commands.csv

# Export last 30 days only
cmdtrack export recent.csv --days 30

Manual Command Logging

# Log a command manually
cmdtrack log "make build"

# With duration and exit code
cmdtrack log "npm test" -d 12.5 -e 0

List Categories

# View all available command categories
cmdtrack categories

Data Cleanup

# Delete commands older than 90 days
cmdtrack cleanup --days 90

# Force delete without confirmation
cmdtrack cleanup --days 180 --force

Command Categories

Commands are automatically categorized into the following types:

  • git: Git version control commands
  • file_ops: File operations (ls, cp, mv, etc.)
  • text_processing: Text manipulation (grep, sed, awk, etc.)
  • network: Network-related commands (ping, curl, ssh, etc.)
  • development: Programming and compilation commands
  • docker: Docker and container commands
  • package_management: Package managers (apt, npm, pip, etc.)
  • process_management: Process control (ps, top, kill, etc.)
  • database: Database clients and tools
  • editors: Text editors (vim, nano, code, etc.)
  • And many more...

Data Storage

All data is stored locally in an SQLite database:

  • Default location: ~/.command_tracker/commands.db
  • Charts: ~/.command_tracker/charts/

You can specify a custom database location:

cmdtrack --db /custom/path/commands.db history

Example Workflows

Daily Review

# See what you worked on today
cmdtrack report --days 1

# Generate visual summary
cmdtrack visualize --daily --days 7

Find Repetitive Tasks

# Identify tasks you run frequently
cmdtrack report --repetitive

# Consider creating aliases or scripts for these

Project Analysis

# Export commands for a specific project
cmdtrack export project_analysis.csv --days 30

# Search for project-specific commands
cmdtrack history -s "my-project" -l 100

Performance Analysis

# See which commands take the longest
cmdtrack stats --detailed

# Visualize execution time distribution
cmdtrack visualize --duration

Privacy & Security

  • 100% Local: All data is stored on your local machine
  • No Network Calls: The tool never sends data anywhere
  • Open Source: Full transparency - review the code yourself
  • User Control: Easy to disable, export, or delete your data

Architecture

command-log-tracker/
├── cmdtrack                    # Main CLI executable
├── command_tracker/
│   ├── core/
│   │   ├── database.py        # SQLite database management
│   │   └── tracker.py         # Command tracking logic
│   ├── utils/
│   │   ├── analytics.py       # Analytics and reporting
│   │   └── categorizer.py     # Command categorization
│   ├── visualizations/
│   │   └── charts.py          # Matplotlib visualizations
│   └── shell_integration/
│       ├── track_command.py   # Shell hook script
│       ├── bashrc_integration.sh
│       └── zshrc_integration.sh
├── docs/                      # Documentation
├── tests/                     # Test files
└── examples/                  # Example scripts

Development

Running Tests

python -m pytest tests/

Adding Custom Categories

You can extend the categorizer with custom categories:

from command_tracker.utils.categorizer import CommandCategorizer

categorizer = CommandCategorizer()
categorizer.add_custom_category('my_tools', ['mytool', 'mycommand'])

Troubleshooting

Shell Integration Not Working

  1. Verify the integration script is sourced correctly
  2. Check file permissions are correct (executable)
  3. Ensure Python 3 is available in your PATH

Commands Not Being Logged

  1. Check if tracking is enabled: cmdtrack_enable
  2. Verify database permissions
  3. Check for errors in shell output

Performance Issues

  1. The tracking happens asynchronously and shouldn't slow down your shell
  2. If you notice issues, you can temporarily disable: cmdtrack_disable
  3. Consider cleaning up old data: cmdtrack cleanup --days 90

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is open source and available under the MIT License.

Future Enhancements

Potential features for future versions:

  • Web dashboard for visualizations
  • Machine learning for command suggestions
  • Team collaboration features
  • Plugin system for custom analyzers
  • Integration with CI/CD pipelines
  • Command completion predictions

Acknowledgments

Built with:

  • Python 3
  • SQLite
  • Matplotlib
  • Love for the command line

Happy tracking! May your commands be plentiful and your workflows efficient.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published