From 3883292bd69d510e3659b79950dab12653ebb1be Mon Sep 17 00:00:00 2001 From: a Date: Mon, 30 Jun 2025 21:05:12 -0500 Subject: [PATCH] noot --- README.md | 9 ++++++ lib/git.sh | 82 ------------------------------------------------------ 2 files changed, 9 insertions(+), 82 deletions(-) create mode 100644 README.md delete mode 100644 lib/git.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..a20374a --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# repotool + +this is a rediculous tool. + +it returns json which is to be used by another wrapper for your shell that does directory movement. + +i have no really other idea on how to implement this. + +i did it in bashly originally, but i switched to lua. diff --git a/lib/git.sh b/lib/git.sh deleted file mode 100644 index 905fd9d..0000000 --- a/lib/git.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bash - -# Parse a git URL into domain and path components -# Usage: parse_git_url -# Returns: JSON with domain and path fields -parse_git_url() { - local url="$1" - local regex="$2" - local jq="$3" - - local domain="" - local path="" - local output - - # Check if it's an HTTP(S) URL - if [[ "$url" =~ ^https?:// ]]; then - output=($(echo "$url" | $regex '/^https?:\/\/(?:.*?:)?(.*\..*?)\/(.*?)(\.git)?$/ && print "$1 $2" ' -)) - if [[ ${#output[@]} -eq 2 ]]; then - domain=${output[0]} - path=${output[1]} - fi - # Check if it's an SSH URL - elif [[ "$url" =~ ^[^:]+@[^:]+: ]] || [[ "$url" =~ ^ssh:// ]]; then - output=($(echo "$url" | $regex '/^(?:.*?@)?(.*\..*?)(?::|\/)(.*?)(\.git)?$/ && print "$1 $2" ' -)) - if [[ ${#output[@]} -eq 2 ]]; then - domain=${output[0]} - path=${output[1]} - fi - # Check if it's a bare domain path (e.g., gfx.cafe/oku/trade) - else - output=($(echo "$url" | $regex '/^(.*\..*?)\/(.*?)(\.git)?$/ && print "$1 $2" ' -)) - if [[ ${#output[@]} -eq 2 ]]; then - domain=${output[0]} - path=${output[1]} - fi - fi - - # Return JSON - $jq -n --arg domain "$domain" --arg path "$path" '{domain: $domain, path: $path}' -} - -# Get domain and path from current git repository's origin -# Usage: parse_git_origin -# Returns: JSON with domain and path fields -parse_git_origin() { - local regex="$1" - local jq="$2" - - # Get origin URL - local origin_url - origin_url=$(git config --get remote.origin.url) - - if [[ -z "$origin_url" ]]; then - $jq -n '{domain: "", path: ""}' - return 1 - fi - - # Parse the URL - parse_git_url "$origin_url" "$regex" "$jq" -} - -# Validate if a URL is a valid git repository URL -# Usage: valid_url -# Returns: 1 for HTTP(S), 2 for SSH, 3 for bare domain paths, -1 for invalid -valid_url() { - local url="$1" - - if [[ "$url" =~ ^https?:// ]]; then - echo "1" - return 0 - elif [[ "$url" =~ ^[^:]+@[^:]+: ]] || [[ "$url" =~ ^ssh:// ]]; then - echo "2" - return 0 - elif [[ "$url" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]+/[^/]+ ]]; then - # Bare domain path like gfx.cafe/oku/trade - echo "3" - return 0 - else - echo "-1" - return 1 - fi -} \ No newline at end of file