aboutsummaryrefslogtreecommitdiff
path: root/mling/tmpl
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-07 02:25:27 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-07 02:25:27 +0800
commit81528b273c18693ebd3f05c6f8057ff8e632f4a0 (patch)
tree85026c27535337c0123d4650c844ae364bc9780a /mling/tmpl
parente41e8bda221b44d09d7e93ffc43675147ab60a6d (diff)
Refactor mling to use new program architecture and install scripts
Diffstat (limited to 'mling/tmpl')
-rw-r--r--mling/tmpl/load.fish75
-rw-r--r--mling/tmpl/load.ps190
-rw-r--r--mling/tmpl/load.sh100
3 files changed, 0 insertions, 265 deletions
diff --git a/mling/tmpl/load.fish b/mling/tmpl/load.fish
deleted file mode 100644
index 19e1ef7..0000000
--- a/mling/tmpl/load.fish
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env fish
-
-# Save original directory
-set -l _load_original_dir $PWD
-
-# Switch to script directory
-set -l _load_dir (dirname (status filename))
-cd $_load_dir
-
-# Load mling.fish from path
-source .comp/mling_comp.fish
-
-# Add all namespace bin directories to PATH
-for _dir in */bin/
- if test -d $_dir
- set -gx PATH $PWD/$_dir $PATH
- end
-end
-
-function _load_comp_script
- if string match -q '*.fish' -- $argv[1]
- source $argv[1] 2>/dev/null
- end
-end
-
-# Iterate through all namespaces
-for _namespace in */
- set _namespace (string trim -r -c / $_namespace)
-
- # Skip if UNTRUSTED marked or no comp directory
- test -f $_namespace/UNTRUSTED && continue
- test -d $_namespace/comp || continue
-
- # Find all loadable scripts in comp
- set _scripts (find $_namespace/comp -maxdepth 1 -type f \( -name '*.sh' -o -name '*.zsh' -o -name '*.fish' \) 2>/dev/null)
- test -z "$_scripts" && continue
-
- # Count scripts
- set _count (count $_scripts)
-
- # If TRUSTED marked, load directly
- if test -f $_namespace/TRUSTED
- for _script in $_scripts
- _load_comp_script $_script
- end
- continue
- end
-
- # Ask user
- read -l -p 'printf "%s has %d completion script(s) to load, do you trust it? [Y/n] " $_namespace $_count' _answer
- switch $_answer
- case '' Y y
- for _script in $_scripts
- chmod +x $_script
- end
- touch $_namespace/TRUSTED
-
- # Ask whether to load immediately
- read -l -p 'printf "Load it immediately? [Y/n] "' _load_answer
- switch $_load_answer
- case '' Y y
- for _script in $_scripts
- _load_comp_script $_script
- end
- end
- case '*'
- touch $_namespace/UNTRUSTED
- end
-end
-
-# Restore original directory
-cd $_load_original_dir
-
-# Clean up
-functions -e _load_comp_script
diff --git a/mling/tmpl/load.ps1 b/mling/tmpl/load.ps1
deleted file mode 100644
index fb616f4..0000000
--- a/mling/tmpl/load.ps1
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env pwsh
-
-# Save original directory, restore after execution
-$_load_original_dir = Get-Location
-
-# Resolve script directory (works with dot-source: . ./load.ps1)
-$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
-if (-not $scriptPath) {
- Write-Error "load.ps1: failed to resolve script directory"
- return
-}
-
-# Load completion script mling_comp.ps1 from the .comp subdirectory
-$compScript = Join-Path -Path $scriptPath -ChildPath ".comp" | Join-Path -ChildPath "mling_comp.ps1"
-if (Test-Path $compScript) {
- . $compScript
-}
-
-# Change to script directory
-try {
- Set-Location $scriptPath -ErrorAction Stop
-} catch {
- Write-Error "load.ps1: failed to cd to script directory"
- return
-}
-
-# Add bin directories from all namespaces to PATH
-$allDirs = Get-ChildItem -Directory
-Get-ChildItem -Directory | Where-Object { Test-Path (Join-Path -Path $_.FullName -ChildPath "bin") } | ForEach-Object {
- $binPath = Join-Path -Path $_.FullName -ChildPath "bin"
- $env:PATH = "$binPath;$env:PATH"
-}
-
-# Helper function: execute script with appropriate shell
-function _load_script {
- param([string]$script)
- if ($script -like "*.ps1") {
- & $script 2>$null
- }
-}
-
-# Iterate over all namespaces (top-level directories except .comp)
-$nsDirs = Get-ChildItem -Directory -Exclude ".comp"
-foreach ($_dir in $nsDirs) {
- $ns = $_dir.Name
-
- # Skip if UNTRUSTED marker exists
- $untrustedMarker = Join-Path -Path $ns -ChildPath "UNTRUSTED"
- if (Test-Path $untrustedMarker) { continue }
-
- $compDir = Join-Path -Path $ns -ChildPath "comp"
- if (-not (Test-Path $compDir -PathType Container)) { continue }
-
- # Find all loadable scripts under comp
- $scripts = Get-ChildItem -Path $compDir -Filter "*.ps1" -File -ErrorAction SilentlyContinue
- if (-not $scripts) { continue }
-
- $count = ($scripts | Measure-Object).Count
-
- # If TRUSTED marker exists, load directly
- $trustedMarker = Join-Path -Path $ns -ChildPath "TRUSTED"
- if (Test-Path $trustedMarker) {
- foreach ($_script in $scripts) { _load_script $_script.FullName }
- continue
- }
-
- # No marker, ask user
- $answer = Read-Host "'$ns' has $count completion script(s) to load, do you trust it? [Y/n] "
- if ($answer -eq "" -or $answer -match "^(y|yes)$") {
- # Mark as TRUSTED
- New-Item -ItemType File -Path $trustedMarker -Force | Out-Null
-
- # Ask whether to load immediately
- $load_answer = Read-Host "Load it immediately? [Y/n] "
- if ($load_answer -eq "" -or $load_answer -match "^(y|yes)$") {
- foreach ($_script in $scripts) { _load_script $_script.FullName }
- }
- } else {
- New-Item -ItemType File -Path $untrustedMarker -Force | Out-Null
- }
-}
-
-# Restore original working directory
-try {
- Set-Location $_load_original_dir -ErrorAction Stop
-} catch {}
-
-# Cleanup
-Remove-Variable -Name _load_original_dir -ErrorAction SilentlyContinue
-Remove-Item Function:_load_script -ErrorAction SilentlyContinue
diff --git a/mling/tmpl/load.sh b/mling/tmpl/load.sh
deleted file mode 100644
index 0d48e95..0000000
--- a/mling/tmpl/load.sh
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/env bash
-
-# Save original directory, restore after execution
-_load_original_dir="$PWD"
-
-cd "$(dirname "$0")" 2>/dev/null || {
- echo "load.sh: failed to cd to script directory" >&2
- return 1
-}
-
-# If in zsh, source mling.zsh, otherwise source mling.sh
-if [ -n "$ZSH_VERSION" ]; then
- [ -f "./.comp/mling_comp.zsh" ] && source "./.comp/mling_comp.zsh"
-else
- [ -f "./.comp/mling_comp.sh" ] && source "./.comp/mling_comp.sh"
-fi
-
-# Add bin directories from all namespaces to PATH
-for _dir in */bin/; do
- [ -d "$_dir" ] && export PATH="$PWD/${_dir%/}:$PATH"
-done
-
-# Helper function: execute script with appropriate shell
-_load_script() {
- local script="$1"
- if [ -n "$ZSH_VERSION" ]; then
- case "$script" in
- *.zsh|*.sh)
- source "$script" 2>/dev/null
- ;;
- esac
- else
- case "$script" in
- *.sh)
- bash "$script" 2>/dev/null
- ;;
- esac
- fi
-}
-
-# Iterate over all namespaces
-for _namespace in */; do
- _namespace="${_namespace%/}"
- [ "$_namespace" = "*" ] && continue
-
- # Skip if UNTRUSTED marker exists
- [ -f "$_namespace/UNTRUSTED" ] && continue
-
- _comp_dir="$_namespace/comp"
- [ ! -d "$_comp_dir" ] && continue
-
- # Find all loadable scripts under comp
- _scripts=$(find "$_comp_dir" -maxdepth 1 -type f \( -name '*.sh' -o -name '*.zsh' -o -name '*.fish' \) 2>/dev/null)
- [ -z "$_scripts" ] && continue
-
- # Count scripts
- _count=$(echo "$_scripts" | wc -l)
-
- # If TRUSTED marker exists, load directly
- if [ -f "$_namespace/TRUSTED" ]; then
- echo "$_scripts" | while IFS= read -r _script; do
- _load_script "$_script"
- done
- continue
- fi
-
- # No marker, ask user
- printf "'%s' has %d completion script(s) to load, do you trust it? [Y/n] " "$_namespace" "$_count"
- read _answer
- case "$_answer" in
- [Yy]*|"")
- # Mark as TRUSTED and set executable permissions
- echo "$_scripts" | while IFS= read -r _script; do
- chmod +x "$_script"
- done
- touch "$_namespace/TRUSTED"
-
- # Ask whether to load immediately
- printf "Load it immediately? [Y/n] "
- read _load_answer
- case "$_load_answer" in
- [Yy]*|"")
- echo "$_scripts" | while IFS= read -r _script; do
- _load_script "$_script"
- done
- ;;
- esac
- ;;
- *)
- touch "$_namespace/UNTRUSTED"
- ;;
- esac
-done
-
-# Restore original working directory
-cd "$_load_original_dir" 2>/dev/null || true
-
-# Cleanup
-unset -f _load_script
-unset _load_original_dir _dir _namespace _comp_dir _scripts _count _answer _load_answer _script