aboutsummaryrefslogtreecommitdiff
path: root/run.sh
diff options
context:
space:
mode:
Diffstat (limited to 'run.sh')
-rwxr-xr-xrun.sh148
1 files changed, 82 insertions, 66 deletions
diff --git a/run.sh b/run.sh
index 4375c32..9f045ce 100755
--- a/run.sh
+++ b/run.sh
@@ -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