UNPKG

@jalasem/dss

Version:

Dev Spaces Switcher (DSS) - Seamlessly manage isolated development environments with separate SSH keys and Git configurations. Enhanced UI with beautiful tables and improved documentation.

266 lines (246 loc) 10.4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateCompletionScript = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); const prompts_1 = require("@inquirer/prompts"); const ui_1 = require("./ui"); // import { IConfig } from './types'; // const configPath = path.join(os.homedir(), '.dss', 'spaces', 'config.json'); function generateCompletionScript(shell) { return __awaiter(this, void 0, void 0, function* () { ui_1.UIHelper.printHeader('Shell Completion Setup'); let selectedShell = shell; if (!selectedShell) { selectedShell = yield (0, prompts_1.select)({ message: 'Select your shell:', choices: [ { name: 'Bash', value: 'bash' }, { name: 'Zsh', value: 'zsh' }, { name: 'Fish', value: 'fish' } ] }); } const completionScript = generateScript(selectedShell); if (!completionScript) { ui_1.UIHelper.error(`Completion script for ${selectedShell} is not supported yet.`); return; } ui_1.UIHelper.printInfoBox('Completion Script Generated', [ `Generated completion script for ${selectedShell}`, 'Copy the script below to enable auto-completion', '', 'Installation instructions will be shown after the script' ]); console.log('\n' + ui_1.UIHelper.dim('--- Completion Script ---')); console.log(completionScript); console.log(ui_1.UIHelper.dim('--- End of Script ---\n')); // Show installation instructions showInstallationInstructions(selectedShell); const saveScript = yield (0, prompts_1.confirm)({ message: 'Would you like to save this script to a file?', default: true }); if (saveScript) { const scriptPath = path_1.default.join(os_1.default.homedir(), `dss-completion.${selectedShell}`); yield fs_extra_1.default.writeFile(scriptPath, completionScript); ui_1.UIHelper.success(`Completion script saved to: ${ui_1.UIHelper.filename(scriptPath)}`); ui_1.UIHelper.printInfoBox('Next Steps', [ `1. Source the script in your ${selectedShell} configuration:`, ` source ${scriptPath}`, '', '2. Or follow the installation instructions above', '3. Restart your terminal or run the source command', '4. Try: dss <TAB> to see available commands' ]); } }); } exports.generateCompletionScript = generateCompletionScript; function generateScript(shell) { switch (shell) { case 'bash': return generateBashScript(); case 'zsh': return generateZshScript(); case 'fish': return generateFishScript(); default: return null; } } function generateBashScript() { /* eslint-disable no-useless-escape */ return `#!/bin/bash # DSS (Dev Spaces Switcher) Bash Completion Script _dss_completion() { local cur prev opts COMPREPLY=() cur="\${COMP_WORDS[COMP_CWORD]}" prev="\${COMP_WORDS[COMP_CWORD-1]}" # Main commands opts="add list switch remove edit test inspect onboard batch export import bulk completion --help --version -h -v" # Get space names for relevant commands if [[ \$prev == "switch" || \$prev == "remove" || \$prev == "edit" || \$prev == "test" || \$prev == "inspect" ]]; then local spaces if [ -f ~/.dss/spaces/config.json ]; then spaces=$(cat ~/.dss/spaces/config.json | grep -o '"name":"[^"]*"' | cut -d'"' -f4 | tr '\n' ' ') COMPREPLY=( $(compgen -W "\$spaces" -- \$cur) ) return 0 fi fi # Options for specific commands case \$prev in switch|remove|bulk) opts="$opts --dry-run" ;; completion) opts="bash zsh fish" ;; esac COMPREPLY=( $(compgen -W "\$opts" -- \$cur) ) return 0 } complete -F _dss_completion dss `; /* eslint-enable no-useless-escape */ } function generateZshScript() { return `#!/bin/zsh # DSS (Dev Spaces Switcher) Zsh Completion Script _dss() { local context state state_descr line local -a commands spaces commands=( 'add:Create a new development space' 'list:List all development spaces' 'switch:Switch to a specified space' 'remove:Remove a specified space' 'edit:Modify an existing space' 'test:Test GitHub access for current space' 'inspect:Show detailed information about a space' 'onboard:Interactive onboarding for new users' 'batch:Switch between multiple spaces' 'export:Export space configuration' 'import:Import space configuration' 'bulk:Bulk update operations' 'completion:Generate shell completion script' '--help:Show help information' '--version:Show version information' ) # Get space names if [[ -f ~/.dss/spaces/config.json ]]; then spaces=(\\$(echo "dummy")) fi _arguments -C \\ '1: :->command' \ '*: :->args' && return 0 case $state in command) _describe 'commands' commands ;; args) case $words[2] in switch|remove|edit|test|inspect) _describe 'spaces' spaces ;; completion) _values 'shell' 'bash' 'zsh' 'fish' ;; esac ;; esac } compdef _dss dss `; } function generateFishScript() { return `#!/usr/bin/env fish # DSS (Dev Spaces Switcher) Fish Completion Script # Function to get space names function __dss_get_spaces if test -f ~/.dss/spaces/config.json cat ~/.dss/spaces/config.json | grep -o '"name":"[^"]*"' | cut -d'"' -f4 end end # Main completion function complete -c dss -f # Commands complete -c dss -n '__fish_use_subcommand' -a 'add' -d 'Create a new development space' complete -c dss -n '__fish_use_subcommand' -a 'list' -d 'List all development spaces' complete -c dss -n '__fish_use_subcommand' -a 'switch' -d 'Switch to a specified space' complete -c dss -n '__fish_use_subcommand' -a 'remove' -d 'Remove a specified space' complete -c dss -n '__fish_use_subcommand' -a 'edit' -d 'Modify an existing space' complete -c dss -n '__fish_use_subcommand' -a 'test' -d 'Test GitHub access for current space' complete -c dss -n '__fish_use_subcommand' -a 'inspect' -d 'Show detailed information about a space' complete -c dss -n '__fish_use_subcommand' -a 'onboard' -d 'Interactive onboarding for new users' complete -c dss -n '__fish_use_subcommand' -a 'batch' -d 'Switch between multiple spaces' complete -c dss -n '__fish_use_subcommand' -a 'export' -d 'Export space configuration' complete -c dss -n '__fish_use_subcommand' -a 'import' -d 'Import space configuration' complete -c dss -n '__fish_use_subcommand' -a 'bulk' -d 'Bulk update operations' complete -c dss -n '__fish_use_subcommand' -a 'completion' -d 'Generate shell completion script' # Global options complete -c dss -n '__fish_use_subcommand' -l help -s h -d 'Show help information' complete -c dss -n '__fish_use_subcommand' -l version -s v -d 'Show version information' # Space name completions for relevant commands complete -c dss -n '__fish_seen_subcommand_from switch remove edit test inspect' -a '(__dss_get_spaces)' # Options for specific commands complete -c dss -n '__fish_seen_subcommand_from switch remove bulk' -l dry-run -d 'Preview changes without applying them' # Shell completions for completion command complete -c dss -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish' -d 'Shell type' `; } function showInstallationInstructions(shell) { ui_1.UIHelper.printHeader('Installation Instructions'); switch (shell) { case 'bash': ui_1.UIHelper.printInfoBox('Bash Installation', [ '1. Add to ~/.bashrc or ~/.bash_profile:', ' source /path/to/dss-completion.bash', '', '2. Or copy to system completion directory:', ' sudo cp dss-completion.bash /etc/bash_completion.d/', '', '3. Restart your terminal or run:', ' source ~/.bashrc' ]); break; case 'zsh': ui_1.UIHelper.printInfoBox('Zsh Installation', [ '1. Add to ~/.zshrc:', ' source /path/to/dss-completion.zsh', '', '2. Or copy to zsh completion directory:', ' cp dss-completion.zsh ~/.oh-my-zsh/completions/_dss', '', '3. Restart your terminal or run:', ' source ~/.zshrc' ]); break; case 'fish': ui_1.UIHelper.printInfoBox('Fish Installation', [ '1. Copy to fish completion directory:', ' cp dss-completion.fish ~/.config/fish/completions/', '', '2. Or manually load:', ' source dss-completion.fish', '', '3. Restart your terminal or run:', ' fish' ]); break; } }