Extension init, syntax highlighting, autocompletion, install script
This commit is contained in:
171
install-extension.sh
Executable file
171
install-extension.sh
Executable file
@@ -0,0 +1,171 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ASHES Language Support Extension Installer
|
||||
# This script installs the ASHES language support extension for VSCode/VSCodium
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to detect VSCode/VSCodium extensions directory
|
||||
detect_extensions_dir() {
|
||||
local extensions_dir=""
|
||||
|
||||
# Check for VSCodium first (more common on Linux)
|
||||
if command -v codium &> /dev/null; then
|
||||
extensions_dir="$HOME/.vscode-oss/extensions"
|
||||
elif command -v code &> /dev/null; then
|
||||
extensions_dir="$HOME/.vscode/extensions"
|
||||
else
|
||||
print_warning "Neither VSCode nor VSCodium found in PATH"
|
||||
extensions_dir="$HOME/.vscode/extensions"
|
||||
fi
|
||||
|
||||
echo "$extensions_dir"
|
||||
}
|
||||
|
||||
# Function to check if directory exists and is writable
|
||||
check_directory() {
|
||||
local dir="$1"
|
||||
|
||||
if [ ! -d "$dir" ]; then
|
||||
print_info "Creating directory: $dir"
|
||||
mkdir -p "$dir" || {
|
||||
print_error "Failed to create directory: $dir"
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
|
||||
if [ ! -w "$dir" ]; then
|
||||
print_error "Directory is not writable: $dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Main installation function
|
||||
main() {
|
||||
print_info "ASHES Language Support Extension Installer"
|
||||
print_info "=========================================="
|
||||
echo
|
||||
|
||||
# Get the script directory (where the vscode-extension folder is located)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
EXTENSION_SOURCE="$SCRIPT_DIR/vscode-extension-ashes"
|
||||
|
||||
# Check if source extension directory exists
|
||||
if [ ! -d "$EXTENSION_SOURCE" ]; then
|
||||
print_error "Extension source directory not found: $EXTENSION_SOURCE"
|
||||
print_error "Please run this script from the project root directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Detect default extensions directory
|
||||
DEFAULT_EXTENSIONS_DIR=$(detect_extensions_dir)
|
||||
|
||||
print_info "Default VSCode/VSCodium extensions directory:"
|
||||
print_info " $DEFAULT_EXTENSIONS_DIR"
|
||||
echo
|
||||
|
||||
# Ask for confirmation or custom path
|
||||
read -p "Use default path? (y/n) [y]: " use_default
|
||||
use_default=${use_default:-y}
|
||||
|
||||
if [[ $use_default =~ ^[Yy]$ ]]; then
|
||||
EXTENSIONS_DIR="$DEFAULT_EXTENSIONS_DIR"
|
||||
else
|
||||
echo
|
||||
read -p "Enter custom extensions directory path: " custom_path
|
||||
EXTENSIONS_DIR="$custom_path"
|
||||
fi
|
||||
|
||||
# Validate the extensions directory
|
||||
if ! check_directory "$EXTENSIONS_DIR"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the destination path for the symlink
|
||||
EXTENSION_DEST="$EXTENSIONS_DIR/vscode-extension-ashes"
|
||||
|
||||
echo
|
||||
print_info "Installation Summary:"
|
||||
print_info "===================="
|
||||
print_info "Source: $EXTENSION_SOURCE"
|
||||
print_info "Destination: $EXTENSION_DEST"
|
||||
print_info "Link name: vscode-extension-ashes"
|
||||
echo
|
||||
|
||||
# Final confirmation
|
||||
read -p "Proceed with installation? (y/n) [y]: " confirm
|
||||
confirm=${confirm:-y}
|
||||
|
||||
if [[ ! $confirm =~ ^[Yy]$ ]]; then
|
||||
print_info "Installation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo
|
||||
print_info "Installing extension..."
|
||||
|
||||
# Check if destination already exists
|
||||
if [ -e "$EXTENSION_DEST" ]; then
|
||||
print_warning "Destination already exists: $EXTENSION_DEST"
|
||||
read -p "Remove existing installation? (y/n) [y]: " remove_existing
|
||||
remove_existing=${remove_existing:-y}
|
||||
|
||||
if [[ $remove_existing =~ ^[Yy]$ ]]; then
|
||||
print_info "Removing existing installation..."
|
||||
rm -rf "$EXTENSION_DEST" || {
|
||||
print_error "Failed to remove existing installation"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
print_info "Installation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create the symlink
|
||||
print_info "Creating symlink..."
|
||||
if ln -s "$EXTENSION_SOURCE" "$EXTENSION_DEST"; then
|
||||
print_success "Extension installed successfully!"
|
||||
echo
|
||||
print_info "Next steps:"
|
||||
print_info "1. Restart VSCode/VSCodium"
|
||||
print_info "2. Open any .esc file to test the extension"
|
||||
print_info "3. The language should be automatically detected as 'ASHES'"
|
||||
echo
|
||||
print_info "To uninstall, simply remove the symlink:"
|
||||
print_info " rm '$EXTENSION_DEST'"
|
||||
else
|
||||
print_error "Failed to create symlink"
|
||||
print_error "Make sure you have write permissions to: $EXTENSIONS_DIR"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user