0.0.1.r
This commit is contained in:
152
install.sh
152
install.sh
@@ -1,7 +1,10 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ZDTT Terminal Installer
|
||||
# Installs ZDTT Terminal and sets up the zdtt command
|
||||
# Downloads and installs ZDTT Terminal from zdtt-sources.zane.org
|
||||
#
|
||||
# Quick Install:
|
||||
# curl -O https://zdtt-sources.zane.org/install.sh && chmod +x install.sh && ./install.sh
|
||||
#
|
||||
|
||||
set -e # Exit on error
|
||||
@@ -141,18 +144,100 @@ echo ""
|
||||
# Create directories if they don't exist
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
mkdir -p "$BIN_DIR"
|
||||
mkdir -p "$HOME/.zdtt/plugins"
|
||||
|
||||
echo "Installing ZDTT Terminal..."
|
||||
echo "Downloading files from zdtt-sources.zane.org..."
|
||||
echo ""
|
||||
|
||||
# Copy the terminal.py, install.sh, and version.txt to the installation directory
|
||||
# Base URL for ZDTT sources
|
||||
BASE_URL="https://zdtt-sources.zane.org"
|
||||
|
||||
# Files to download
|
||||
declare -a FILES=("terminal.py" "version.txt")
|
||||
|
||||
# Download files
|
||||
DOWNLOAD_SUCCESS=true
|
||||
|
||||
for file in "${FILES[@]}"; do
|
||||
echo "Downloading $file..."
|
||||
|
||||
if command -v wget &> /dev/null; then
|
||||
if wget -q "$BASE_URL/$file" -O "$INSTALL_DIR/$file" 2>/dev/null; then
|
||||
echo -e "${GREEN}✓${NC} $file downloaded"
|
||||
else
|
||||
echo -e "${RED}✗${NC} Failed to download $file"
|
||||
DOWNLOAD_SUCCESS=false
|
||||
break
|
||||
fi
|
||||
elif command -v curl &> /dev/null; then
|
||||
if curl -sSL "$BASE_URL/$file" -o "$INSTALL_DIR/$file" 2>/dev/null; then
|
||||
echo -e "${GREEN}✓${NC} $file downloaded"
|
||||
else
|
||||
echo -e "${RED}✗${NC} Failed to download $file"
|
||||
DOWNLOAD_SUCCESS=false
|
||||
break
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}✗${NC} Neither wget nor curl found"
|
||||
echo "Please install wget or curl to proceed"
|
||||
echo ""
|
||||
echo "Press any key to exit..."
|
||||
read -n 1 -s -r
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$DOWNLOAD_SUCCESS" = false ]; then
|
||||
echo ""
|
||||
echo -e "${RED}Installation failed - unable to download required files${NC}"
|
||||
echo "Please check your internet connection and try again."
|
||||
echo ""
|
||||
echo "Press any key to exit..."
|
||||
read -n 1 -s -r
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy this installer to the installation directory for future use
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cp "$SCRIPT_DIR/terminal.py" "$INSTALL_DIR/terminal.py"
|
||||
cp "$SCRIPT_DIR/install.sh" "$INSTALL_DIR/install.sh"
|
||||
cp "$SCRIPT_DIR/version.txt" "$INSTALL_DIR/version.txt"
|
||||
cp "$0" "$INSTALL_DIR/install.sh"
|
||||
|
||||
# Set executable permissions
|
||||
chmod +x "$INSTALL_DIR/terminal.py"
|
||||
chmod +x "$INSTALL_DIR/install.sh"
|
||||
|
||||
echo -e "${GREEN}✓${NC} ZDTT Terminal files copied to $INSTALL_DIR"
|
||||
echo ""
|
||||
echo -e "${GREEN}✓${NC} ZDTT Terminal files installed to $INSTALL_DIR"
|
||||
|
||||
# Download and install example plugin
|
||||
echo ""
|
||||
echo "Installing example plugin..."
|
||||
EXAMPLE_PLUGIN_URL="https://plugins.zane.org/example_plugin.py"
|
||||
PLUGIN_DEST="$HOME/.zdtt/plugins/example_plugin.py"
|
||||
|
||||
# Try wget first (more reliable), then curl
|
||||
PLUGIN_DOWNLOADED=false
|
||||
|
||||
if command -v wget &> /dev/null; then
|
||||
if wget -q "$EXAMPLE_PLUGIN_URL" -O "$PLUGIN_DEST" 2>/dev/null; then
|
||||
echo -e "${GREEN}✓${NC} Example plugin installed from plugins.zane.org"
|
||||
PLUGIN_DOWNLOADED=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$PLUGIN_DOWNLOADED" = false ] && command -v curl &> /dev/null; then
|
||||
# Suppress curl snap warnings and try download
|
||||
if curl -sSL "$EXAMPLE_PLUGIN_URL" -o "$PLUGIN_DEST" 2>/dev/null; then
|
||||
echo -e "${GREEN}✓${NC} Example plugin installed from plugins.zane.org"
|
||||
PLUGIN_DOWNLOADED=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$PLUGIN_DOWNLOADED" = false ]; then
|
||||
echo -e "${YELLOW}⚠${NC} Could not download example plugin"
|
||||
echo " You can install it later with: zps install $EXAMPLE_PLUGIN_URL"
|
||||
# Don't exit - continue with installation
|
||||
fi
|
||||
|
||||
# Create the zdtt wrapper script
|
||||
cat > "$BIN_DIR/zdtt" << 'EOF'
|
||||
@@ -169,6 +254,60 @@ case "$1" in
|
||||
clear
|
||||
python3 "$ZDTT_DIR/terminal.py"
|
||||
;;
|
||||
update)
|
||||
echo "Checking for updates..."
|
||||
|
||||
# Get current version
|
||||
if [ -f "$ZDTT_DIR/version.txt" ]; then
|
||||
CURRENT_VERSION=$(cat "$ZDTT_DIR/version.txt")
|
||||
else
|
||||
CURRENT_VERSION="unknown"
|
||||
fi
|
||||
|
||||
# Get remote version
|
||||
if command -v curl &> /dev/null; then
|
||||
REMOTE_VERSION=$(curl -sSL https://zdtt-sources.zane.org/version.txt 2>/dev/null)
|
||||
elif command -v wget &> /dev/null; then
|
||||
REMOTE_VERSION=$(wget -qO- https://zdtt-sources.zane.org/version.txt 2>/dev/null)
|
||||
else
|
||||
echo "Error: Neither curl nor wget found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$REMOTE_VERSION" ]; then
|
||||
echo "Error: Could not fetch remote version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Current version: $CURRENT_VERSION"
|
||||
echo "Latest version: $REMOTE_VERSION"
|
||||
echo ""
|
||||
|
||||
if [ "$CURRENT_VERSION" = "$REMOTE_VERSION" ]; then
|
||||
echo "✓ You're already running the latest version!"
|
||||
else
|
||||
echo "Update available!"
|
||||
read -p "Do you want to update now? (yes/no): " -r
|
||||
if [[ $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
|
||||
# Run the installer
|
||||
if [ -f "$ZDTT_DIR/install.sh" ]; then
|
||||
bash "$ZDTT_DIR/install.sh"
|
||||
else
|
||||
echo "Downloading installer..."
|
||||
TEMP_INSTALLER="/tmp/zdtt_install.sh"
|
||||
if command -v curl &> /dev/null; then
|
||||
curl -sSL https://zdtt-sources.zane.org/install.sh -o "$TEMP_INSTALLER"
|
||||
else
|
||||
wget -qO "$TEMP_INSTALLER" https://zdtt-sources.zane.org/install.sh
|
||||
fi
|
||||
bash "$TEMP_INSTALLER"
|
||||
rm -f "$TEMP_INSTALLER"
|
||||
fi
|
||||
else
|
||||
echo "Update cancelled."
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
installer|install|reinstall)
|
||||
# Run the installer for reinstalling/updating
|
||||
if [ -f "$ZDTT_DIR/install.sh" ]; then
|
||||
@@ -205,6 +344,7 @@ case "$1" in
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " zdtt start - Start the ZDTT Terminal"
|
||||
echo " zdtt update - Check for and install updates"
|
||||
echo " zdtt installer - Run installer (for updates/reinstall)"
|
||||
echo " zdtt version - Display version information"
|
||||
echo " zdtt uninstall - Uninstall ZDTT Terminal"
|
||||
|
||||
115
terminal.py
115
terminal.py
@@ -16,6 +16,7 @@ import logging
|
||||
from datetime import datetime
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
import time as time_module
|
||||
|
||||
|
||||
def check_system_compatibility():
|
||||
@@ -101,6 +102,7 @@ class ZDTTTerminal:
|
||||
'alias': self.cmd_alias,
|
||||
'unalias': self.cmd_unalias,
|
||||
'zps': self.cmd_zps,
|
||||
'time': self.cmd_time,
|
||||
# System commands
|
||||
'ls': self.cmd_ls,
|
||||
'pwd': self.cmd_pwd,
|
||||
@@ -124,6 +126,9 @@ class ZDTTTerminal:
|
||||
|
||||
# Load plugins
|
||||
self.load_plugins()
|
||||
|
||||
# Check for updates (non-blocking)
|
||||
self.check_for_updates()
|
||||
|
||||
def setup_logging(self):
|
||||
"""Setup logging for plugin errors"""
|
||||
@@ -156,6 +161,24 @@ class ZDTTTerminal:
|
||||
# Fallback version if file not found
|
||||
return "0.0.1.a"
|
||||
|
||||
def check_for_updates(self):
|
||||
"""Check if a new version is available"""
|
||||
try:
|
||||
# Get remote version
|
||||
url = "https://zdtt-sources.zane.org/version.txt"
|
||||
with urllib.request.urlopen(url, timeout=2) as response:
|
||||
remote_version = response.read().decode('utf-8').strip()
|
||||
|
||||
# Compare versions
|
||||
if remote_version != self.version:
|
||||
print()
|
||||
print(f"🔔 Update available! Current: {self.version} → Latest: {remote_version}")
|
||||
print(" Run 'zdtt update' to update")
|
||||
print()
|
||||
except Exception:
|
||||
# Silently fail if we can't check for updates
|
||||
pass
|
||||
|
||||
def display_banner(self):
|
||||
"""Display the ZDTT ASCII art banner (or custom banner if available)"""
|
||||
# Check for custom banner
|
||||
@@ -367,11 +390,18 @@ ZDTT Terminal v{self.version}
|
||||
else:
|
||||
display_path = cwd
|
||||
|
||||
# Create colorized prompt
|
||||
# Wrap ANSI codes in \001 and \002 so readline knows they're non-printable
|
||||
# This fixes line wrapping issues with long commands
|
||||
RL_PROMPT_START = '\001'
|
||||
RL_PROMPT_END = '\002'
|
||||
|
||||
# Create colorized prompt with readline-safe escape codes
|
||||
# [username in green @ ZDTT path in blue]=>
|
||||
prompt = (f"[{self.COLOR_GREEN}{self.username}{self.COLOR_RESET}"
|
||||
f"@{self.COLOR_CYAN}ZDTT{self.COLOR_RESET} "
|
||||
f"{self.COLOR_BLUE}{display_path}{self.COLOR_RESET}]=> ")
|
||||
prompt = (f"[{RL_PROMPT_START}{self.COLOR_GREEN}{RL_PROMPT_END}{self.username}"
|
||||
f"{RL_PROMPT_START}{self.COLOR_RESET}{RL_PROMPT_END}"
|
||||
f"@{RL_PROMPT_START}{self.COLOR_CYAN}{RL_PROMPT_END}ZDTT{RL_PROMPT_START}{self.COLOR_RESET}{RL_PROMPT_END} "
|
||||
f"{RL_PROMPT_START}{self.COLOR_BLUE}{RL_PROMPT_END}{display_path}"
|
||||
f"{RL_PROMPT_START}{self.COLOR_RESET}{RL_PROMPT_END}]=> ")
|
||||
return prompt
|
||||
|
||||
def cmd_help(self, args):
|
||||
@@ -386,6 +416,7 @@ ZDTT Terminal v{self.version}
|
||||
print(" alias [name=cmd] - Create or display command aliases")
|
||||
print(" unalias <name> - Remove an alias")
|
||||
print(" zps install <url> - Install plugin from URL")
|
||||
print(" time [options] - Display date/time (MM/DD/YY 12h default)")
|
||||
print(" exit - Exit ZDTT (return to shell)")
|
||||
print(" quit - Quit and close terminal window")
|
||||
print()
|
||||
@@ -445,9 +476,11 @@ ZDTT Terminal v{self.version}
|
||||
|
||||
print()
|
||||
print("Features:")
|
||||
print(" • Automatic update checking on startup")
|
||||
print(" • Command history with ↑/↓ navigation (1000 commands)")
|
||||
print(" • Tab completion for commands and files")
|
||||
print(" • Command aliases (alias g=git)")
|
||||
print(" • Flexible time/date display with multiple formats")
|
||||
print(" • Colorized prompt")
|
||||
print(" • Plugin system with ZPS package manager")
|
||||
print(" • Plugin hot-reload (plugins reload)")
|
||||
@@ -677,6 +710,80 @@ ZDTT Terminal v{self.version}
|
||||
print(f"zps: unknown subcommand '{subcommand}'")
|
||||
print("Try: zps install <url>")
|
||||
|
||||
def cmd_time(self, args):
|
||||
"""Display current date and time with various formats"""
|
||||
now = datetime.now()
|
||||
|
||||
# Parse arguments
|
||||
use_24h = False
|
||||
custom_format = None
|
||||
|
||||
for arg in args:
|
||||
if arg in ['--24h', '-24', '24h']:
|
||||
use_24h = True
|
||||
elif arg in ['--12h', '-12', '12h']:
|
||||
use_24h = False
|
||||
elif arg.startswith('--format='):
|
||||
custom_format = arg.split('=', 1)[1]
|
||||
elif arg in ['--help', '-h']:
|
||||
print("\nTime Command - Display current date and time")
|
||||
print("\nUsage:")
|
||||
print(" time - Default format (MM/DD/YY 12h)")
|
||||
print(" time --24h - Use 24-hour format")
|
||||
print(" time --12h - Use 12-hour format (default)")
|
||||
print(" time --format=... - Custom format string")
|
||||
print("\nPre-defined formats:")
|
||||
print(" time iso - ISO 8601 format")
|
||||
print(" time full - Full date and time")
|
||||
print(" time date - Date only")
|
||||
print(" time clock - Time only")
|
||||
print(" time unix - Unix timestamp")
|
||||
print("\nCustom format codes:")
|
||||
print(" %Y - Year (4 digit) %m - Month (01-12)")
|
||||
print(" %d - Day (01-31) %H - Hour (00-23)")
|
||||
print(" %I - Hour (01-12) %M - Minute (00-59)")
|
||||
print(" %S - Second (00-59) %p - AM/PM")
|
||||
print(" %A - Weekday name %B - Month name")
|
||||
print("\nExample:")
|
||||
print(" time --format='%Y-%m-%d %H:%M:%S'")
|
||||
print()
|
||||
return
|
||||
elif arg == 'iso':
|
||||
custom_format = '%Y-%m-%d %H:%M:%S'
|
||||
use_24h = True
|
||||
elif arg == 'full':
|
||||
custom_format = '%A, %B %d, %Y at %I:%M:%S %p'
|
||||
elif arg == 'date':
|
||||
print(now.strftime('%m/%d/%y'))
|
||||
return
|
||||
elif arg == 'clock':
|
||||
if use_24h:
|
||||
print(now.strftime('%H:%M:%S'))
|
||||
else:
|
||||
print(now.strftime('%I:%M:%S %p'))
|
||||
return
|
||||
elif arg == 'unix':
|
||||
print(int(time_module.time()))
|
||||
return
|
||||
|
||||
# Apply custom format if specified
|
||||
if custom_format:
|
||||
try:
|
||||
print(now.strftime(custom_format))
|
||||
except Exception as e:
|
||||
print(f"Error: Invalid format string - {e}")
|
||||
return
|
||||
|
||||
# Default format: MM/DD/YY with time
|
||||
date_str = now.strftime('%m/%d/%y')
|
||||
|
||||
if use_24h:
|
||||
time_str = now.strftime('%H:%M:%S')
|
||||
else:
|
||||
time_str = now.strftime('%I:%M:%S %p')
|
||||
|
||||
print(f"{date_str} {time_str}")
|
||||
|
||||
def cmd_echo(self, args):
|
||||
"""Echo the provided arguments"""
|
||||
if args:
|
||||
|
||||
@@ -1 +1 @@
|
||||
v0.0.1.b
|
||||
0.0.1.b
|
||||
|
||||
Reference in New Issue
Block a user