save-go

command module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 14 Imported by: 0

README ΒΆ

save - Command History Manager

Go Report Card Version

save is a powerful command-line tool that helps developers track, manage, and reuse their shell commands with additional context and organization features. It's designed to be a more intelligent alternative to basic shell history, offering tagging, searching, and analytics capabilities.

πŸš€ Quick Install

Prerequisites
  • Go 1.21 or higher
  • Git
  • Make (for Unix/Linux/macOS)
One-Line Installation
Linux/macOS
curl -sSL https://raw.githubusercontent.com/t-rhex/save-go/main/install.sh | bash
Windows (PowerShell)
# Run as administrator
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/t-rhex/save-go/main/install.ps1')
Manual Installation
  1. Clone and Build:
git clone https://github.com/t-rhex/save-go.git
cd save-go
  1. Choose Installation Method:
Unix/Linux/macOS:

User Installation (Recommended, no sudo required):

make user-install

System-wide Installation (Requires sudo):

make install
Windows:
# Build
go build -o save.exe

# Copy to a directory in your PATH (e.g., %USERPROFILE%\AppData\Local\save)
$installPath = "$env:USERPROFILE\AppData\Local\save"
New-Item -ItemType Directory -Force -Path $installPath
Copy-Item save.exe -Destination "$installPath\save.exe"

# Add to PATH if not already there
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$installPath*") {
    [Environment]::SetEnvironmentVariable("Path", "$userPath;$installPath", "User")
}
  1. Add to Shell (if using user installation):
Unix/Linux/macOS:
# For Bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo '[[ -f ~/.bash_completion.d/save ]] && . ~/.bash_completion.d/save' >> ~/.bashrc

# For Zsh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
echo 'fpath=(~/.zsh/completion $fpath)' >> ~/.zshrc
Windows (PowerShell):
# Add to PowerShell profile
if (!(Test-Path $PROFILE)) { New-Item -Type File -Force $PROFILE }
Add-Content $PROFILE "`$env:Path = [Environment]::GetEnvironmentVariable('Path', 'User')"

# Setup completion
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Completions"
save --generate-completion powershell > "$env:USERPROFILE\Documents\WindowsPowerShell\Completions\save.ps1"
  1. Reload Shell:
Unix/Linux/macOS:
source ~/.bashrc  # or source ~/.zshrc for Zsh
Windows:
# Reload PATH
$env:Path = [Environment]::GetEnvironmentVariable("Path", "User")

πŸš€ Quick Start

# Save and run a command
save 'echo "Hello World"'

# Save with tags and description
save --tag docker,prod --desc 'Start services' 'docker-compose up'

# List recent commands
save --list

# Search commands
save --search "docker"

πŸ“š Features

Core Features
  • ✨ Command execution and storage with metadata
  • πŸ“ Only successful commands are saved
  • πŸ“ Directory context tracking
  • 🏷️ Tagging system
  • πŸ“ Interactive command mode
  • πŸ“ Command descriptions
  • ⭐ Favorite commands
  • πŸ”„ Command rerunning
  • πŸ“Š Usage statistics
  • πŸ’Ύ Backup and restore functionality
  • πŸ› οΈ Data integrity verification
  • πŸ”„ Command duplication prevention
Advanced Features
  • πŸ”— Command chains with dependencies
  • ⚑ Parallel execution support
  • 🎯 Conditional execution
  • ⏰ Time-based execution
  • πŸ”„ Undo support
  • πŸ“ˆ Analytics and insights
  • πŸ” Similar command detection
Interactive Mode
# Enter interactive mode
save --interactive
# or
save -i

# Available commands in interactive mode:
help              # Show help message
exit              # Exit interactive mode
clear             # Clear the screen
list              # List recent commands
tags              # Show available tags

πŸ’» Usage Examples

Basic Command Management
# Save with current directory
save --dir 'npm start'

# Add tags to existing command
save --add-tags 42 git,prod

# Mark as favorite
save --favorite 42

# Edit command interactively
save --interactive-edit 42

# List favorite commands
save --list-favorites
Backup and Restore
# Create backup
save --backup

# List available backups
save --list-backups

# Restore from backup
save --restore backup-20240321-123456.json

# Verify data integrity
save --verify
Command Chains
# Create deployment chain
save --create-chain 'deploy' 'Deploy to prod' steps.json deps.json

# Run chain
save --run-chain 1

# Run chain ignoring errors
save --run-chain 1 --continue-on-error
Search and Analytics
# Search by tag
save --filter-tag docker

# View statistics
save --stats

# Export history
save --export history.json

βš™οΈ Configuration

Default Paths
  • Config: ~/.config/save/config.json
  • History: ~/.save_history.json
  • Backups: ~/.config/save/backups/
  • Completions:
    • Bash: ~/.bash_completion.d/save
    • Zsh: ~/.zsh/completion/_save
Environment Variables
SAVE_CONFIG_PATH   # Custom config file location
SAVE_HISTORY_PATH  # Custom history file location
SAVE_NO_COLOR      # Disable color output
SAVE_BACKUP_PATH   # Custom backup directory location
Unix/Linux:
  • Config: ~/.config/save/config.json
  • History: ~/.save_history.json
  • Backups: ~/.config/save/backups/
  • Completions:
    • Bash: ~/.bash_completion.d/save
    • Zsh: ~/.zsh/completion/_save
Windows:
User Installation (Default):
  • Binary: %USERPROFILE%\bin\save.exe
  • Config: %USERPROFILE%\AppData\Local\save\config.json
  • History: %USERPROFILE%\AppData\Local\save\history.json
  • Completions: %USERPROFILE%\Documents\WindowsPowerShell\Completions\save.ps1
System Installation:
  • Binary: C:\Program Files\save\save.exe
  • Config: C:\ProgramData\save\config.json
  • History: C:\ProgramData\save\history.json

πŸ”„ Updates

Unix/Linux/macOS:
# Update to latest version
curl -sSL https://raw.githubusercontent.com/t-rhex/save-go/main/install.sh | bash
Windows:
# Update to latest version
# Run as administrator for system-wide installation
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/t-rhex/save-go/main/install.ps1')

# Or for user installation
$InstallType = "user"
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/t-rhex/save-go/main/install.ps1')

πŸ› Troubleshooting

Common Issues
  1. Command not found
# Add to PATH
export PATH="$HOME/.local/bin:$PATH"
  1. No shell completion
# Reload shell completion
source ~/.bashrc  # or source ~/.zshrc for Zsh
  1. Permission denied
# Fix permissions
chmod +x $HOME/.local/bin/save
  1. Duplicate commands
# Use --dir flag to save same command in different directory context
save --dir 'npm start'

# Or use --rerun to execute existing command
save --rerun <command_id>
  1. Command not found on Windows
# Add to PATH for current session
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'User')

# Or permanently add to PATH
[Environment]::SetEnvironmentVariable(
    "Path",
    [Environment]::GetEnvironmentVariable("Path", "User") + ";$env:USERPROFILE\bin",
    "User"
)

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by shell history management tools
  • Built with Go's robust standard library
  • Community feedback and contributions

πŸ“¬ Support

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL