forked from a/repotool
noot
This commit is contained in:
parent
fddc3fbceb
commit
3883292bd6
9
README.md
Normal file
9
README.md
Normal file
@ -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.
|
||||||
82
lib/git.sh
82
lib/git.sh
@ -1,82 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Parse a git URL into domain and path components
|
|
||||||
# Usage: parse_git_url <url> <perl_regex_command> <jq_command>
|
|
||||||
# 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 <perl_regex_command> <jq_command>
|
|
||||||
# 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 <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
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user