A reusable bash functions and utilities library for development, deployment, and system management.
- 🚀 Quick Start
- 📦 Versioning
- 📁 Project Structure
- 🎯 Core Modules
- 📚 Usage Examples
- 🔧 Installation Methods
- 🎯 Recommendations
- 🔧 Installation and Setup
- 🧪 Testing
- 📖 Documentation
- 🤝 Contributing
- 📄 License
- 🆘 Support
- 🔄 Versions
The easiest way - connect the library directly in your script with one line:
#!/usr/bin/env bash
# Connect the entire library with one line
source <(curl -fsSL https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh)
# Now you can use all functions
logging::info "Script started"
colors::success "Operation completed successfully!"
if validation::is_email "[email protected]"; then
echo "Email is valid"
fi
For more efficient usage, create a loading function:
#!/usr/bin/env bash
# Universal bash-lib loading
load_bash_lib() {
local remote_url="https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh"
local cache_dir="$HOME/.cache/bash-lib"
local cache_file="$cache_dir/bash-lib-standalone.sh"
# Check if library is already loaded
if [[ -n "$__BASH_LIB_IMPORTED" ]]; then
return 0
fi
# Create cache directory
mkdir -p "$cache_dir"
# Use cache if not expired (24 hours)
if [[ -f "$cache_file" ]] && [[ $(($(date +%s) - $(stat -c %Y "$cache_file"))) -lt 86400 ]]; then
source "$cache_file"
else
# Download and cache
if curl -fsSL "$remote_url" -o "$cache_file"; then
source "$cache_file"
else
echo "Error loading library"
exit 1
fi
fi
}
# Load library
load_bash_lib
# Use functions
logging::info "Script started"
colors::success "Ready to work!"
# Clone repository
git clone https://github.com/mrvi0/bash-lib.git
cd bash-lib
# Install library
sudo ./scripts/install.sh
# Activate in current session
source ~/.bashrc
#!/usr/bin/env bash
# Connect library
source /usr/local/lib/bash-lib/bash-lib.sh
# Use functions
logging::info "Starting work"
colors::success "Operation completed successfully"
if validation::is_email "[email protected]"; then
echo "Valid email"
fi
Each stable version of the library is marked with a git tag.
source <(curl -fsSL https://raw.githubusercontent.com/mrvi0/bash-lib/v1.0.0/bash-lib-standalone.sh)
bash_lib::version
if [[ "$__BASH_LIB_VERSION" != "1.0.0" ]]; then
echo "Error: bash-lib version 1.0.0 required"
exit 1
fi
See all versions on the Releases tab or by git tags.
bash-lib/
├── src/ # Main library code
│ ├── core/ # Basic functions
│ │ ├── colors.sh # Colored output
│ │ ├── logging.sh # Logging
│ │ └── validation.sh # Data validation
│ ├── io/ # File and I/O operations
│ ├── system/ # System functions
│ ├── development/ # Development functions
│ └── database/ # Database operations
├── examples/ # Usage examples
│ ├── basic_usage.sh # Basic example
│ ├── simple_usage.sh # Simple connection
│ ├── cached_usage.sh # With caching
│ ├── local_usage.sh # Local file
│ └── universal_usage.sh # Universal method
├── tests/ # Tests
├── docs/ # Documentation
├── scripts/ # Installation scripts
├── bash-lib.sh # Main import file
├── bash-lib-standalone.sh # Single file for simple connection
└── README.md
Colored terminal output with support for various colors and styles.
colors::success "Successful operation"
colors::error "Error"
colors::warning "Warning"
colors::info "Information"
colors::debug "Debug information"
colors::highlight "Highlighted text"
Logging system with various levels and formats.
# Set logging level
logging::set_level debug
# Logging
logging::info "Information message"
logging::debug "Debug information"
logging::warn "Warning"
logging::error "Error"
logging::fatal "Critical error (with exit)"
# Logging to file
logging::set_file "/var/log/myapp.log"
Validation of various data types.
# Email validation
validation::is_email "[email protected]"
# Integer validation
validation::is_integer "123"
validation::is_positive_integer "456"
# Range validation
validation::is_in_range "50" "1" "100"
# Port validation
validation::is_port "8080"
# File existence check
validation::file_exists "/path/to/file"
# Combined validation
validation::all "[email protected]" validation::is_email validation::is_not_empty
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh)
# Setup logging
logging::set_level info
logging::set_file "/tmp/myapp.log"
# Main logic
logging::info "Starting application"
# Input validation
if ! validation::is_email "$1"; then
colors::error "Invalid email: $1"
logging::error "Email validation failed"
exit 1
fi
colors::success "Email is valid: $1"
logging::info "Application completed successfully"
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh)
echo "Processing files..."
for i in {1..100}; do
colors::progress_bar "$i" "100" "30" "Processing"
sleep 0.01
done
echo "Done!"
source <(curl -fsSL https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh)
Pros: Very simple, always up-to-date version Cons: Requires internet on each run, slower
load_bash_lib() {
local cache_dir="$HOME/.cache/bash-lib"
local cache_file="$cache_dir/bash-lib-standalone.sh"
local remote_url="https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh"
mkdir -p "$cache_dir"
if [[ -f "$cache_file" ]] && [[ $(($(date +%s) - $(stat -c %Y "$cache_file"))) -lt 86400 ]]; then
source "$cache_file"
else
curl -fsSL "$remote_url" -o "$cache_file" && source "$cache_file"
fi
}
load_bash_lib
Pros: Fast, 24-hour caching, works without internet Cons: Slightly more complex
# Download file once
curl -fsSL https://raw.githubusercontent.com/mrvi0/bash-lib/main/bash-lib-standalone.sh -o bash-lib-standalone.sh
# Use in scripts
source "./bash-lib-standalone.sh"
Pros: Maximum speed, works without internet Cons: Need to update manually
See examples/universal_usage.sh
- combines all methods with priority.
Scenario | Recommended Method | Reason |
---|---|---|
Quick Scripts | Direct Download | Maximum simplicity |
Serious Projects | Caching | Balance of speed and relevance |
Production | Local File | Reliability and speed |
Development | Universal | Flexibility |
# Install in standard directories
sudo ./scripts/install.sh
# Install in user directories
./scripts/install.sh -d ~/.local/lib/bash-lib -b ~/.local/bin
# Copy files
sudo cp -r src /usr/local/lib/bash-lib/
sudo cp bash-lib.sh /usr/local/lib/bash-lib/
# Add to .bashrc
echo 'source /usr/local/lib/bash-lib/bash-lib.sh' >> ~/.bashrc
source ~/.bashrc
# Run examples
./examples/basic_usage.sh
./examples/simple_usage.sh
./examples/cached_usage.sh
./examples/local_usage.sh
./examples/universal_usage.sh
# Check function availability
bash-lib --help
- API Reference - Complete API documentation
- Getting Started - Getting started guide
- Best Practices - Best practices
- Fork the repository
- Create a branch for your feature (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you have questions or issues:
- Check the documentation
- Look at the examples
- Create an Issue
- v1.0.0 - First stable release with full functionality
- Colored output and formatting
- Logging system with levels
- Data validation (email, numbers, files, ports)
- System utilities (internet check, system information)
- Universal functions (confirmations, headers, progress bars)
- Compatibility with old functions
- v1.1.0 - Planned: IO modules, extended system functions
- v1.2.0 - Planned: Development modules, database modules