This commit is contained in:
abs3nt 2025-03-05 10:46:35 -08:00
parent e180b13f74
commit 7ff0cd043a
Signed by: abs3nt
GPG Key ID: A7BD96A8BAB04C09
9 changed files with 60 additions and 16 deletions

@ -18,4 +18,25 @@ function __repo_needs_command
return 1
end
function __repo_using_command
set -l cmd (commandline -opc)
if test (count $cmd) -gt 1
if test $argv[1] = $cmd[2]
return 0
end
end
return 1
end
function __repo_list_repos
find "$REPO_BASE_DIR" -type d -name ".git" | path dirname | sort | path basename
end
# Main command completions
complete -f -c repo -n __repo_needs_command -a '(__repo_commands)'
# Repository completions
complete -f -c repo -n '__repo_using_command go; or __repo_using_command goto' -a '(__repo_list_repos)'
# Help option
complete -f -c repo -s h -l help -d 'Show help message'

@ -7,7 +7,7 @@ function _repo_clean_path
end
end
set stripped (echo $stripped | sed -e "s/:/\//1")
set stripped (string replace --max=1 ":" "/" $stripped)
if not string match -q "*/*" $stripped
set stripped "github.com/$stripped"

@ -1,5 +1,5 @@
function _repo_clone
if test -z "$argv[2]"
if not set -q argv[2]; or test -z "$argv[2]"
echo "Error: Repository path is required"
return 1
end
@ -13,7 +13,7 @@ function _repo_clone
mkdir -p "$trimmed"
if not test -d "$trimmed/.git"
set repourl (echo "$repo_prefix@$cleaned" | sed -e "s/\//:/1")
set repourl (string replace --max=1 "/" ":" "$repo_prefix@$cleaned")
echo "Cloning $repourl to $trimmed..."
git clone "$repourl" "$trimmed"
else
@ -21,4 +21,4 @@ function _repo_clone
end
_repo_post_clone "$trimmed"
end
end

@ -1,5 +1,5 @@
function _repo_goto
if test -z "$argv[1]"
if not set -q argv[1]; or test -z "$argv[1]"
echo "Error: Repository path is required"
return 1
end
@ -9,4 +9,4 @@ function _repo_goto
# Remove .git suffix if present
set trimmed (string replace -r '(\.git)$' '' "$output_path")
_repo_post_goto $trimmed
end
end

@ -1,6 +1,6 @@
function _repo_list
for git_dir in (find "$REPO_BASE_DIR" -type d -name ".git")
set parent_dir (dirname "$git_dir")
echo (basename "$parent_dir" | sed 's/\./_/g')
set parent_dir (path dirname "$git_dir")
echo (path basename "$parent_dir" | string replace -a "." "_")
end
end

@ -1,5 +1,5 @@
function _repo_new
if test -z "$argv[1]"
if not set -q argv[1]; or test -z "$argv[1]"
echo "Error: Repository path is required"
return 1
end
@ -17,4 +17,4 @@ function _repo_new
end
_repo_post_new "$trimmed"
end
end

@ -2,5 +2,14 @@ function _repo_open
set remote (git remote get-url origin)
set remote (string replace -r "git@" "https://" $remote)
set remote (string replace --max=1 ":" "/" $remote)
xdg-open "$remote"
if not command -q xdg-open
echo "Error: xdg-open command not found"
return 1
end
if not xdg-open "$remote" 2>/dev/null
echo "Error: Failed to open $remote"
return 1
end
end

@ -1,4 +1,4 @@
function repo_post_goto
function _repo_post_goto
if functions -q repo_post_goto
repo_post_goto $argv[1]
else

@ -1,6 +1,22 @@
function repo
set cmd $argv[1]
set arg $argv[2]
argparse h/help -- $argv
or begin
_repo_help
return 1
end
if set -q _flag_help
_repo_help
return 0
end
if not set -q argv[1]
_repo_help
return 1
end
set -l cmd $argv[1]
set -l arg $argv[2]
switch $cmd
case get
@ -15,8 +31,6 @@ function repo
_repo_goto $arg
case new create
_repo_new $arg
case help -h -help --help
_repo_help
case '*'
echo "Unknown command: $cmd"
_repo_help