From 7ff0cd043ac7f950d5178eaa445f7e4a8c3928d5 Mon Sep 17 00:00:00 2001
From: abs3nt <abs3nt@asdf.cafe>
Date: Wed, 5 Mar 2025 10:46:35 -0800
Subject: [PATCH] stuff

---
 completions/repo.fish           | 21 +++++++++++++++++++++
 functions/_repo_clean_path.fish |  2 +-
 functions/_repo_clone.fish      |  6 +++---
 functions/_repo_goto.fish       |  4 ++--
 functions/_repo_list.fish       |  4 ++--
 functions/_repo_new.fish        |  4 ++--
 functions/_repo_open.fish       | 11 ++++++++++-
 functions/_repo_post_goto.fish  |  2 +-
 functions/repo.fish             | 22 ++++++++++++++++++----
 9 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/completions/repo.fish b/completions/repo.fish
index ab12a31..8473aac 100644
--- a/completions/repo.fish
+++ b/completions/repo.fish
@@ -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'
diff --git a/functions/_repo_clean_path.fish b/functions/_repo_clean_path.fish
index 8dde086..dc804e4 100644
--- a/functions/_repo_clean_path.fish
+++ b/functions/_repo_clean_path.fish
@@ -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"
diff --git a/functions/_repo_clone.fish b/functions/_repo_clone.fish
index 770fd8d..6870929 100644
--- a/functions/_repo_clone.fish
+++ b/functions/_repo_clone.fish
@@ -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
\ No newline at end of file
diff --git a/functions/_repo_goto.fish b/functions/_repo_goto.fish
index 3751277..81013ce 100644
--- a/functions/_repo_goto.fish
+++ b/functions/_repo_goto.fish
@@ -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
\ No newline at end of file
diff --git a/functions/_repo_list.fish b/functions/_repo_list.fish
index e919328..4514f6e 100644
--- a/functions/_repo_list.fish
+++ b/functions/_repo_list.fish
@@ -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
diff --git a/functions/_repo_new.fish b/functions/_repo_new.fish
index 30948ab..70f46ea 100644
--- a/functions/_repo_new.fish
+++ b/functions/_repo_new.fish
@@ -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
\ No newline at end of file
diff --git a/functions/_repo_open.fish b/functions/_repo_open.fish
index c4cc7fa..fd11909 100644
--- a/functions/_repo_open.fish
+++ b/functions/_repo_open.fish
@@ -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
diff --git a/functions/_repo_post_goto.fish b/functions/_repo_post_goto.fish
index b77992e..225e39c 100644
--- a/functions/_repo_post_goto.fish
+++ b/functions/_repo_post_goto.fish
@@ -1,4 +1,4 @@
-function repo_post_goto
+function _repo_post_goto
     if functions -q repo_post_goto
         repo_post_goto $argv[1]
     else
diff --git a/functions/repo.fish b/functions/repo.fish
index 4ad076d..9ec73e9 100644
--- a/functions/repo.fish
+++ b/functions/repo.fish
@@ -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