From 7105c0f31ec5f8aeb14864aae0a27c4c4ae7bce1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:02:23 +0000 Subject: [PATCH 1/8] Initial plan From 4f4fb7024a548d544755a6c18e69932effbc476c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:03:53 +0000 Subject: [PATCH 2/8] Add create-package tool and README from PR branch Co-authored-by: punppis <6446823+punppis@users.noreply.github.com> --- README.md | 51 ++++++++++++++++++++++++++++- create-package | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100755 create-package diff --git a/README.md b/README.md index 4c06dc0..53480c0 100644 --- a/README.md +++ b/README.md @@ -1 +1,50 @@ -My collection of bash scripts. \ No newline at end of file +My collection of bash scripts. + +## Tools + +### create-package + +A tool to create new package directories with bash script templates. + +**Usage:** + +```bash +# Using command-line arguments +./create-package "My Tool" + +# Using stdin (piped input) +echo "My Tool" | ./create-package +``` + +**Behavior:** + +- Creates a directory with the sanitized package name +- Generates an executable bash script inside the directory with the same name +- The generated script includes a shebang, error handling, and a simple hello message + +**Name Sanitization Rules:** + +Package names are automatically sanitized: +- Converted to lowercase +- Spaces and underscores are replaced with dashes +- Only `[a-z0-9-]` characters are retained (letters, numbers, dashes) +- Multiple consecutive dashes are collapsed into one +- Leading and trailing dashes are removed + +**Examples:** + +```bash +# Creates: my-tool/my-tool +./create-package "My Tool" + +# Creates: hello-world/hello-world +echo "Hello_World" | ./create-package + +# Creates: test123/test123 +./create-package "test123" +``` + +**Error Handling:** + +- If the sanitized name is empty (e.g., only special characters), the script exits with an error +- If a directory with that name already exists, the script exits with an error message \ No newline at end of file diff --git a/create-package b/create-package new file mode 100755 index 0000000..7788d98 --- /dev/null +++ b/create-package @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +set -euo pipefail + +# create-package: Create a new package directory with a bash script template +# Usage: ./create-package +# echo "" | ./create-package + +# Color helper functions +red() { + if [[ -t 1 ]]; then + echo -e "\033[31m$*\033[0m" >&2 + else + echo "$*" >&2 + fi +} + +green() { + if [[ -t 1 ]]; then + echo -e "\033[32m$*\033[0m" + else + echo "$*" + fi +} + +# Read package name from stdin or CLI args +if [[ $# -gt 0 ]]; then + package_name="$*" +elif [[ ! -t 0 ]]; then + # Reading from pipe + read -r package_name +else + red "Error: Package name required" + echo "Usage: ./create-package " >&2 + echo " echo \"\" | ./create-package" >&2 + exit 1 +fi + +# Sanitize the package name: +# 1. Convert to lowercase +# 2. Replace spaces and underscores with dashes +# 3. Remove any characters that are not [a-z0-9-] +# 4. Collapse multiple consecutive dashes into one +# 5. Remove leading/trailing dashes +sanitized=$(echo "$package_name" | \ + tr '[:upper:]' '[:lower:]' | \ + tr ' _' '-' | \ + sed 's/[^a-z0-9-]//g' | \ + sed 's/-\+/-/g' | \ + sed 's/^-//;s/-$//') + +# Check if sanitized name is empty +if [[ -z "$sanitized" ]]; then + red "Error: Package name '$package_name' results in empty string after sanitization" + echo "Package names must contain at least one alphanumeric character" >&2 + exit 1 +fi + +# Check if directory already exists +if [[ -d "$sanitized" ]]; then + red "Error: Directory '$sanitized' already exists" + exit 1 +fi + +# Create the package directory (using mkdir without -p to avoid race condition) +if ! mkdir "$sanitized" 2>/dev/null; then + red "Error: Failed to create directory '$sanitized' (may have been created concurrently)" + exit 1 +fi + +# Create the package script +script_path="$sanitized/$sanitized" +cat > "$script_path" < Date: Thu, 29 Jan 2026 22:05:17 +0000 Subject: [PATCH 3/8] Update create-package sanitization to handle all whitespace characters Co-authored-by: punppis <6446823+punppis@users.noreply.github.com> --- README.md | 10 +++++++--- create-package | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 53480c0..87b2ef5 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ echo "My Tool" | ./create-package Package names are automatically sanitized: - Converted to lowercase -- Spaces and underscores are replaced with dashes +- Any run of whitespace characters (spaces, tabs, etc.) is replaced with a single dash +- All special characters are removed - Only `[a-z0-9-]` characters are retained (letters, numbers, dashes) - Multiple consecutive dashes are collapsed into one - Leading and trailing dashes are removed @@ -37,8 +38,11 @@ Package names are automatically sanitized: # Creates: my-tool/my-tool ./create-package "My Tool" -# Creates: hello-world/hello-world -echo "Hello_World" | ./create-package +# Creates: my-repo/my-repo +./create-package "my repo" + +# Creates: my-repo2/my-repo2 +./create-package "my ^ repo2" # Creates: test123/test123 ./create-package "test123" diff --git a/create-package b/create-package index 7788d98..244646b 100755 --- a/create-package +++ b/create-package @@ -37,13 +37,13 @@ fi # Sanitize the package name: # 1. Convert to lowercase -# 2. Replace spaces and underscores with dashes +# 2. Replace any run of whitespace characters with a single dash # 3. Remove any characters that are not [a-z0-9-] # 4. Collapse multiple consecutive dashes into one # 5. Remove leading/trailing dashes sanitized=$(echo "$package_name" | \ tr '[:upper:]' '[:lower:]' | \ - tr ' _' '-' | \ + sed 's/[[:space:]]\+/-/g' | \ sed 's/[^a-z0-9-]//g' | \ sed 's/-\+/-/g' | \ sed 's/^-//;s/-$//') From 21151dcea3ef5d560946b57b8a8e27106e2e42a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:07:00 +0000 Subject: [PATCH 4/8] Clarify README sanitization rules order Co-authored-by: punppis <6446823+punppis@users.noreply.github.com> --- README.md | 3 +-- my-repo2/my-repo2 | 7 +++++++ test-piped-input/test-piped-input | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 my-repo2/my-repo2 create mode 100755 test-piped-input/test-piped-input diff --git a/README.md b/README.md index 87b2ef5..b66e1ce 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,7 @@ echo "My Tool" | ./create-package Package names are automatically sanitized: - Converted to lowercase - Any run of whitespace characters (spaces, tabs, etc.) is replaced with a single dash -- All special characters are removed -- Only `[a-z0-9-]` characters are retained (letters, numbers, dashes) +- All other special characters are removed (only `[a-z0-9-]` are retained) - Multiple consecutive dashes are collapsed into one - Leading and trailing dashes are removed diff --git a/my-repo2/my-repo2 b/my-repo2/my-repo2 new file mode 100755 index 0000000..cb98bca --- /dev/null +++ b/my-repo2/my-repo2 @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +# my-repo2: Package script +# Generated by create-package + +echo "Hello from my-repo2!" diff --git a/test-piped-input/test-piped-input b/test-piped-input/test-piped-input new file mode 100755 index 0000000..aca98ac --- /dev/null +++ b/test-piped-input/test-piped-input @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +# test-piped-input: Package script +# Generated by create-package + +echo "Hello from test-piped-input!" From 0583970deca1252e9e3edb7be593051e7a402b38 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:07:11 +0000 Subject: [PATCH 5/8] Remove accidentally committed test directories and update .gitignore Co-authored-by: punppis <6446823+punppis@users.noreply.github.com> --- .gitignore | 3 ++- my-repo2/my-repo2 | 7 ------- test-piped-input/test-piped-input | 7 ------- 3 files changed, 2 insertions(+), 15 deletions(-) delete mode 100755 my-repo2/my-repo2 delete mode 100755 test-piped-input/test-piped-input diff --git a/.gitignore b/.gitignore index 2518e23..b1fa043 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode/** \ No newline at end of file +.vscode/**my-repo* +test-* diff --git a/my-repo2/my-repo2 b/my-repo2/my-repo2 deleted file mode 100755 index cb98bca..0000000 --- a/my-repo2/my-repo2 +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# my-repo2: Package script -# Generated by create-package - -echo "Hello from my-repo2!" diff --git a/test-piped-input/test-piped-input b/test-piped-input/test-piped-input deleted file mode 100755 index aca98ac..0000000 --- a/test-piped-input/test-piped-input +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# test-piped-input: Package script -# Generated by create-package - -echo "Hello from test-piped-input!" From 621650621fd3216ed9b54d7f0e0d3c245f56751a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:08:17 +0000 Subject: [PATCH 6/8] Fix .gitignore formatting and remove extra trailing newline in create-package Co-authored-by: punppis <6446823+punppis@users.noreply.github.com> --- .gitignore | 3 ++- create-package | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b1fa043..98e8478 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.vscode/**my-repo* +.vscode/** +my-repo* test-* diff --git a/create-package b/create-package index 244646b..1eb8502 100755 --- a/create-package +++ b/create-package @@ -84,4 +84,3 @@ chmod +x "$script_path" green "✓ Created package '$sanitized'" echo " Script: $script_path" - From 7f801a9ea8ffe31a6ec90bbd76ed254a88801dff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:10:05 +0000 Subject: [PATCH 7/8] Final verification complete Co-authored-by: punppis <6446823+punppis@users.noreply.github.com> --- piped-test/piped-test | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 piped-test/piped-test diff --git a/piped-test/piped-test b/piped-test/piped-test new file mode 100755 index 0000000..bee5ff2 --- /dev/null +++ b/piped-test/piped-test @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +# piped-test: Package script +# Generated by create-package + +echo "Hello from piped-test!" From 292b65adbb2f331bf046056ad92c766422b45572 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:10:21 +0000 Subject: [PATCH 8/8] Remove test directory from version control --- piped-test/piped-test | 7 ------- 1 file changed, 7 deletions(-) delete mode 100755 piped-test/piped-test diff --git a/piped-test/piped-test b/piped-test/piped-test deleted file mode 100755 index bee5ff2..0000000 --- a/piped-test/piped-test +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# piped-test: Package script -# Generated by create-package - -echo "Hello from piped-test!"