diff options
| -rw-r--r-- | functions/ugit.fish | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/functions/ugit.fish b/functions/ugit.fish index 8d59dad..9dd6d8d 100644 --- a/functions/ugit.fish +++ b/functions/ugit.fish @@ -1 +1,35 @@ -alias ugit='git clone --depth 1' +function __get_last_directory + set -l url $argv[1] + + # Check if URL is empty + if test -z "$url" + echo "" + return + end + + # Remove protocol and domain + set -l path (string replace -r '^https?://[^/]+' '' "$url") + + # Remove query parameters and fragments + set -l clean_path (string replace -r '[?#].*$' '' "$path") + + # Split by slashes and get the last non-empty part + set -l parts (string split / "$clean_path") + set -l last_part (echo $parts | string trim -c ' ' | string replace -a ' ' '\n' | grep -v '^$' | tail -n 1) + + # Check if there's a path (not just domain) + if test -z "$last_part" -o "$last_part" = "$clean_path" + echo "" + else + echo -e "$last_part" | tail -n 1 + end +end + +function ugit --wraps git --description "Shallow clone a git repository and enter in it" + set -l url $argv[1] + set -l path (__get_last_directory $url) + git clone --depth 1 "$url" + if test $status = 0 -a -n "$path" + cd "$path" + end +end |