diff options
| -rwxr-xr-x[-rw-r--r--] | .run/src/bin/shell-script.sh | 0 | ||||
| -rw-r--r-- | run.ps1 | 148 | ||||
| -rwxr-xr-x | run.sh | 148 |
3 files changed, 156 insertions, 140 deletions
diff --git a/.run/src/bin/shell-script.sh b/.run/src/bin/shell-script.sh index 306afb5..306afb5 100644..100755 --- a/.run/src/bin/shell-script.sh +++ b/.run/src/bin/shell-script.sh @@ -2,33 +2,33 @@ $tools = @{} -if (Test-Path ".run/src/bin/*.cs") { - Get-ChildItem -Path ".run/src/bin/*.cs" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "cs"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.ps1") { + Get-ChildItem -Path ".run/src/bin/*.ps1" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "ps1"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.rs") { - Get-ChildItem -Path ".run/src/bin/*.rs" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "rs"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.cs") { + Get-ChildItem -Path ".run/src/bin/*.cs" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "cs"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.py") { - Get-ChildItem -Path ".run/src/bin/*.py" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "py"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.exe") { + Get-ChildItem -Path ".run/src/bin/*.exe" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "exe"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.ps1") { - Get-ChildItem -Path ".run/src/bin/*.ps1" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "ps1"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.go") { + Get-ChildItem -Path ".run/src/bin/*.go" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "go"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.rb") { - Get-ChildItem -Path ".run/src/bin/*.rb" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "rb"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.nim") { + Get-ChildItem -Path ".run/src/bin/*.nim" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "nim"; Path = $_.FullName } } } @@ -38,32 +38,32 @@ if (Test-Path ".run/src/bin/*.pl") { } } -if (Test-Path ".run/src/bin/*.go") { - Get-ChildItem -Path ".run/src/bin/*.go" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "go"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.py") { + Get-ChildItem -Path ".run/src/bin/*.py" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "py"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.zig") { - Get-ChildItem -Path ".run/src/bin/*.zig" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "zig"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.rb") { + Get-ChildItem -Path ".run/src/bin/*.rb" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "rb"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.nim") { - Get-ChildItem -Path ".run/src/bin/*.nim" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "nim"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.rs") { + Get-ChildItem -Path ".run/src/bin/*.rs" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "rs"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.exe") { - Get-ChildItem -Path ".run/src/bin/*.exe" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "exe"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.zig") { + Get-ChildItem -Path ".run/src/bin/*.zig" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "zig"; Path = $_.FullName } } } if ($args.Count -eq 0) { - $sorted = $tools.Keys | Sort-Object + $sorted = $tools.Keys | Sort-Object @{Expression={if ($tools[$_].Type -eq 'ps1') {0} else {1}}}, {$_} $total = $sorted.Count $num_w = $total.ToString().Length @@ -85,16 +85,16 @@ if ($args.Count -eq 0) { foreach ($name in $sorted) { $type = $tools[$name].Type $lang = switch ($type) { + "ps1" { "PowerShell" } "cs" { "C#" } + "exe" { "Binary" } + "go" { "Go" } + "nim" { "Nim" } + "pl" { "Perl" } "py" { "Python" } - "rs" { "Rust" } - "ps1" { "PowerShell" } "rb" { "Ruby" } - "pl" { "Perl" } - "go" { "Go" } + "rs" { "Rust" } "zig" { "Zig" } - "nim" { "Nim" } - "exe" { "Binary" } } $displayName = $name -replace '[_\-]', ' ' $entry = " " + $i.ToString().PadRight($num_w) + ") " + $displayName.PadRight($max_name) + " [$lang]" @@ -110,7 +110,7 @@ if ($args.Count -eq 0) { $target_name = $args[0] if ($target_name -match '^\d+$') { - $sorted = $tools.Keys | Sort-Object + $sorted = $tools.Keys | Sort-Object @{Expression={if ($tools[$_].Type -eq 'ps1') {0} else {1}}}, {$_} $idx = [int]$target_name - 1 if ($idx -ge 0 -and $idx -lt $sorted.Count) { $target_name = $sorted[$idx] @@ -145,27 +145,55 @@ switch ($info.Type) { "ps1" { & $info.Path @script_args } - "rb" { - ruby $info.Path $script_args + "cs" { + $temp_dir = ".run/target/csproj/$target_name" + $null = New-Item -ItemType Directory -Path $temp_dir -Force + + $props_content = @' +<Project> + <PropertyGroup> + <BaseOutputPath>$(MSBuildThisFileDirectory)../../csharp/bin</BaseOutputPath> + <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)../../csharp/obj</BaseIntermediateOutputPath> + </PropertyGroup> +</Project> +'@ + Set-Content -Path "$temp_dir/Directory.Build.props" -Value $props_content + + $csproj_content = @" +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> +"@ + Set-Content -Path "$temp_dir/$target_name.csproj" -Value $csproj_content + Copy-Item -Path $info.Path -Destination "$temp_dir/Program.cs" -Force + + dotnet run --project "$temp_dir/$target_name.csproj" -- $script_args } - "pl" { - perl $info.Path $script_args + "exe" { + & $info.Path $script_args } "go" { go run $info.Path $script_args } - "zig" { - zig run $info.Path $script_args - } "nim" { nim r --hints:off $info.Path $script_args } - "exe" { - & $info.Path $script_args + "pl" { + perl $info.Path $script_args } "py" { python $info.Path $script_args } + "rb" { + ruby $info.Path $script_args + } "rs" { if (-not (Test-Path ".run/Cargo.toml")) { @" @@ -186,36 +214,8 @@ edition = "2024" } & $binary $script_args } - "cs" { - $temp_dir = ".run/target/csproj/$target_name" - $null = New-Item -ItemType Directory -Path $temp_dir -Force - - $props_content = @' -<Project> - <PropertyGroup> - <BaseOutputPath>$(MSBuildThisFileDirectory)../../csharp/bin</BaseOutputPath> - <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)../../csharp/obj</BaseIntermediateOutputPath> - </PropertyGroup> -</Project> -'@ - Set-Content -Path "$temp_dir/Directory.Build.props" -Value $props_content - - $csproj_content = @" -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <OutputType>Exe</OutputType> - <TargetFramework>net8.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - </PropertyGroup> - -</Project> -"@ - Set-Content -Path "$temp_dir/$target_name.csproj" -Value $csproj_content - Copy-Item -Path $info.Path -Destination "$temp_dir/Program.cs" -Force - - dotnet run --project "$temp_dir/$target_name.csproj" -- $script_args + "zig" { + zig run $info.Path $script_args } } @@ -4,38 +4,40 @@ cd "$(dirname "$0")" || exit 1 declare -A tools -for file in .run/src/bin/*.cs; do +for file in .run/src/bin/*.sh; do if [ -f "$file" ]; then - name=$(basename "$file" .cs) - tools["$name"]="cs" + name=$(basename "$file" .sh) + tools["$name"]="sh" fi done -for file in .run/src/bin/*.rs; do +for file in .run/src/bin/*; do if [ -f "$file" ]; then - name=$(basename "$file" .rs) - tools["$name"]="rs" + name=$(basename "$file") + if [[ ! "$name" == *.* ]]; then + tools["$name"]="binary" + fi fi done -for file in .run/src/bin/*.py; do +for file in .run/src/bin/*.cs; do if [ -f "$file" ]; then - name=$(basename "$file" .py) - tools["$name"]="py" + name=$(basename "$file" .cs) + tools["$name"]="cs" fi done -for file in .run/src/bin/*.sh; do +for file in .run/src/bin/*.go; do if [ -f "$file" ]; then - name=$(basename "$file" .sh) - tools["$name"]="sh" + name=$(basename "$file" .go) + tools["$name"]="go" fi done -for file in .run/src/bin/*.rb; do +for file in .run/src/bin/*.nim; do if [ -f "$file" ]; then - name=$(basename "$file" .rb) - tools["$name"]="rb" + name=$(basename "$file" .nim) + tools["$name"]="nim" fi done @@ -46,38 +48,44 @@ for file in .run/src/bin/*.pl; do fi done -for file in .run/src/bin/*.go; do +for file in .run/src/bin/*.py; do if [ -f "$file" ]; then - name=$(basename "$file" .go) - tools["$name"]="go" + name=$(basename "$file" .py) + tools["$name"]="py" fi done -for file in .run/src/bin/*.zig; do +for file in .run/src/bin/*.rb; do if [ -f "$file" ]; then - name=$(basename "$file" .zig) - tools["$name"]="zig" + name=$(basename "$file" .rb) + tools["$name"]="rb" fi done -for file in .run/src/bin/*.nim; do +for file in .run/src/bin/*.rs; do if [ -f "$file" ]; then - name=$(basename "$file" .nim) - tools["$name"]="nim" + name=$(basename "$file" .rs) + tools["$name"]="rs" fi done -for file in .run/src/bin/*; do +for file in .run/src/bin/*.zig; do if [ -f "$file" ]; then - name=$(basename "$file") - if [[ ! "$name" == *.* ]]; then - tools["$name"]="binary" - fi + name=$(basename "$file" .zig) + tools["$name"]="zig" fi done if [ $# -eq 0 ]; then - sorted_names=($(echo "${!tools[@]}" | tr ' ' '\n' | sort)) + sorted_names=($( + for name in "${!tools[@]}"; do + if [ "${tools[$name]}" = "sh" ]; then + echo "0 $name" + else + echo "1 $name" + fi + done | sort | while read -r _ n; do echo "$n"; done + )) total=${#sorted_names[@]} num_w=${#total} @@ -103,16 +111,16 @@ if [ $# -eq 0 ]; then for name in "${sorted_names[@]}"; do type="${tools[$name]}" case "$type" in + sh) lang="Shell";; + binary) lang="Binary";; cs) lang="C#";; + go) lang="Go";; + nim) lang="Nim";; + pl) lang="Perl";; py) lang="Python";; - rs) lang="Rust";; - sh) lang="Shell";; rb) lang="Ruby";; - pl) lang="Perl";; - go) lang="Go";; + rs) lang="Rust";; zig) lang="Zig";; - nim) lang="Nim";; - binary) lang="Binary";; esac display_name=$(echo "$name" | tr '_-' ' ') entry=$(printf " %-*d) %-*s [%s]" $num_w $i $max_name "$display_name" $lang) @@ -129,7 +137,15 @@ target_name="$1" shift if [[ "$target_name" =~ ^[0-9]+$ ]]; then - sorted=($(echo "${!tools[@]}" | tr ' ' '\n' | sort)) + sorted=($( + for name in "${!tools[@]}"; do + if [ "${tools[$name]}" = "sh" ]; then + echo "0 $name" + else + echo "1 $name" + fi + done | sort | while read -r _ n; do echo "$n"; done + )) idx=$((target_name - 1)) if [ "$idx" -ge 0 ] && [ "$idx" -lt "${#sorted[@]}" ]; then target_name="${sorted[$idx]}" @@ -164,24 +180,9 @@ case "$type" in chmod +x ".run/src/bin/$target_name.sh" ".run/src/bin/$target_name.sh" "$@" ;; - py) - python ".run/src/bin/$target_name.py" "$@" - ;; - rs) - if [ ! -f ".run/Cargo.toml" ]; then - cat > ".run/Cargo.toml" <<'EOF' -[package] -name = "run_rust" -version = "0.1.0" -edition = "2024" - -[workspace] - -[dependencies] -EOF - fi - cargo build --manifest-path ".run/Cargo.toml" --target-dir ".run/target" --bin "$target_name" --quiet - ".run/target/debug/$target_name" "$@" + binary) + chmod +x ".run/src/bin/$target_name" + ".run/src/bin/$target_name" "$@" ;; cs) temp_dir=".run/target/csproj/$target_name" @@ -209,23 +210,38 @@ CSPROJ cp ".run/src/bin/$target_name.cs" "$temp_dir/Program.cs" dotnet run --project "$temp_dir/$target_name.csproj" -- "$@" ;; - rb) - ruby ".run/src/bin/$target_name.rb" "$@" + go) + go run ".run/src/bin/$target_name.go" "$@" + ;; + nim) + nim r --hints:off ".run/src/bin/$target_name.nim" "$@" ;; pl) perl ".run/src/bin/$target_name.pl" "$@" ;; - go) - go run ".run/src/bin/$target_name.go" "$@" + py) + python ".run/src/bin/$target_name.py" "$@" ;; - zig) - zig run ".run/src/bin/$target_name.zig" "$@" + rb) + ruby ".run/src/bin/$target_name.rb" "$@" ;; - nim) - nim r --hints:off ".run/src/bin/$target_name.nim" "$@" + rs) + if [ ! -f ".run/Cargo.toml" ]; then + cat > ".run/Cargo.toml" <<'EOF' +[package] +name = "run_rust" +version = "0.1.0" +edition = "2024" + +[workspace] + +[dependencies] +EOF + fi + cargo build --manifest-path ".run/Cargo.toml" --target-dir ".run/target" --bin "$target_name" --quiet + ".run/target/debug/$target_name" "$@" ;; - binary) - chmod +x ".run/src/bin/$target_name" - ".run/src/bin/$target_name" "$@" + zig) + zig run ".run/src/bin/$target_name.zig" "$@" ;; esac |
