Skip to content

A Zsh plugin to provide enhanced command history logging with directory awareness.

License

Notifications You must be signed in to change notification settings

fuba/histree-zsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

histree-zsh

A Zsh plugin that integrates with histree-core to provide enhanced command history logging with directory awareness.

This project was developed with the assistance of ChatGPT and GitHub Copilot.

Features

  • Automatic command logging with directory context
  • Exit code tracking for each command execution
  • Multiple output formats for viewing history:
    • Simple format: Just the command
    • Verbose format: With timestamp and directory context
    • JSON format: For programmatic access
  • Seamless integration with your Zsh workflow

Prerequisites

  • Zsh shell
  • Go 1.18 or later
    # Check your Go version
    go version
  • Properly configured GOBIN in your PATH
    # Add this to your ~/.zshrc or ~/.bashrc if not already set
    export GOBIN=$HOME/go/bin
    export PATH=$GOBIN:$PATH

Installation

  1. Clone this repository:

    git clone https://github.com/fuba/histree-zsh.git
    cd histree-zsh
  2. Make sure your Go environment is properly set up:

    # Verify your Go environment
    echo $GOBIN
    echo $PATH
  3. Run the installation script:

    chmod +x ./install.sh  # Make sure the script is executable
    ./install.sh

The script will:

  • Create ~/.histree-zsh directory structure
  • Install histree-core using go install
  • Copy the histree-core binary to the correct location
  • Add necessary configurations to your .zshrc

After installation:

~/.histree-zsh/
├── bin/          # Contains the histree-core binary
└── histree.zsh   # The Zsh plugin script

Configuration

The plugin behavior can be customized in your .zshrc:

# Database location (optional)
export HISTREE_DB="$HOME/.histree.db"  # Default location

# History entries limit (optional)
export HISTREE_LIMIT=500  # Default: 100

Usage

Once installed, restart your terminal or run:

source ~/.zshrc

The plugin automatically logs your commands. View history using:

# Simple format (default)
$ histree
git status
npm install
vim README.md

# Verbose format with timestamps and directories
$ histree -v
2024-02-15T15:04:30Z [/home/user/project] [0] git status
2024-02-15T15:05:15Z [/home/user/project] [1] npm install
2024-02-15T15:06:00Z [/home/user/project] [0] vim README.md

# JSON format
$ histree -json
{"command":"git status","directory":"/home/user/project","timestamp":"2024-02-15T15:04:30Z","exit_code":0,"hostname":"host","process_id":1234}
{"command":"npm install","directory":"/home/user/project","timestamp":"2024-02-15T15:05:15Z","exit_code":1,"hostname":"host","process_id":1234}
{"command":"vim README.md","directory":"/home/user/project","timestamp":"2024-02-15T15:06:00Z","exit_code":0,"hostname":"host","process_id":1234}

Command Options

  • -v, --verbose: Show detailed output including timestamp, directory, and exit code
  • -json, --json: Output in JSON format with full command context

Troubleshooting

# Check binary installation
which histree-core        # Should show: ~/.histree-zsh/bin/histree-core

# Check database permissions
ls -l ~/.histree.db

# Verify PATH setting
echo $PATH | grep histree

# Fix binary permissions if needed
chmod +x ~/.histree-zsh/bin/histree-core

# Reset database if corrupted
rm ~/.histree.db    # New one will be created automatically

License

MIT License

About

A Zsh plugin to provide enhanced command history logging with directory awareness.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages