This commit is contained in:
abs3nt 2025-03-03 18:04:52 -08:00
parent cb936d00f0
commit 31659e91b0
Signed by: abs3nt
GPG Key ID: A7BD96A8BAB04C09
12 changed files with 228 additions and 7 deletions

21
completions/repo.fish Normal file

@ -0,0 +1,21 @@
function __repo_commands
echo "get\tClone a repository"
echo "open\tOpen the repository in a browser"
echo "aur\tClone an AUR repository"
echo "list\tList all repositories"
echo "go\tNavigate to a repository"
echo "goto\tNavigate to a repository"
echo "new\tCreate a new repository"
echo "create\tCreate a new repository"
echo "help\tShow help message"
end
function __repo_needs_command
set -l cmd (commandline -opc)
if [ (count $cmd) -eq 1 ]
return 0
end
return 1
end
complete -f -c repo -n '__repo_needs_command' -a '(__repo_commands)'

23
functions/clone.fish Normal file

@ -0,0 +1,23 @@
function repo_clone
if test -z "$argv[2]"
echo "Error: Repository path is required"
return 1
end
set repo_prefix $argv[1]
set cleaned (clean_repo_path "$argv[2]")
set output_path "$REPO_BASE_DIR/$cleaned"
set suffix ".git"
set clean_path (string replace -r "$suffix\$" "" "$output_path")
mkdir -p "$clean_path"
if test ! -d "$clean_path/.git"
set repourl (string replace "/" ":" "$repo_prefix@$cleaned" -r)
echo "Cloning $repourl to $clean_path..."
git clone "$repourl" "$clean_path"
else
echo "Repository already exists: $clean_path"
end
post_repo_clone "$clean_path"
end

14
functions/core.fish Normal file

@ -0,0 +1,14 @@
function clean_repo_path
set stripped $argv[1]
set stripped (string replace -r "^http://" "" $stripped)
set stripped (string replace -r "^https://" "" $stripped)
set stripped (string replace -r "^git@" "" $stripped)
set stripped (string replace -r "^ssh://" "" $stripped)
set stripped (string replace -r "^aur@" "" $stripped)
set stripped (string replace -r ":" "/" $stripped)
if not string match -q "*/*" $stripped
set stripped "github.com/$stripped"
end
echo "$stripped"
end

11
functions/goto.fish Normal file

@ -0,0 +1,11 @@
function repo_goto
if test -z "$argv[1]"
echo "Error: Repository path is required"
return 1
end
set cleaned (clean_repo_path "$argv[1]")
set output_path "$REPO_BASE_DIR/$cleaned"
set suffix ".git"
post_repo_goto (string replace -r "$suffix\$" "" "$output_path")
end

16
functions/help.fish Normal file

@ -0,0 +1,16 @@
function repo_help
echo "Usage: repo <command> <repository>"
echo ""
echo "Commands:"
echo " get Clone a repository to the repos directory"
echo " open Open the current repository in the browser"
echo " aur Clone an AUR repository"
echo " list List all repositories"
echo " go|goto Navigate to a repository"
echo " new|create Create a new repository"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " repo get github.com/user/repo"
echo " repo open"
end

11
functions/hooks.fish Normal file

@ -0,0 +1,11 @@
function post_repo_clone
cd "$argv[1]"
end
function post_repo_goto
cd "$argv[1]"
end
function post_repo_new
cd "$argv[1]"
end

6
functions/list.fish Normal file

@ -0,0 +1,6 @@
function list_repos
find "$REPO_BASE_DIR" -type d -name ".git" | while read -l git_dir
set parent_dir (dirname "$git_dir")
string replace -r '.*/' '' "$parent_dir" | string replace -a '.' '_'
end
end

19
functions/new.fish Normal file

@ -0,0 +1,19 @@
function repo_new
if test -z "$argv[1]"
echo "Error: Repository path is required"
return 1
end
set cleaned (clean_repo_path "$argv[1]")
set output_path "$REPO_BASE_DIR/$cleaned"
set clean_path (string replace -r "\.git\$" "" "$output_path")
mkdir -p "$clean_path"
if test ! -d "$clean_path/.git"
git init "$clean_path"
else
echo "Repository already exists: $clean_path"
end
post_repo_new "$clean_path"
end

6
functions/open.fish Normal file

@ -0,0 +1,6 @@
function repo_open
set remote (git remote get-url origin)
set remote (string replace "git@" "https://" $remote)
set remote (string replace ":" "/" $remote)
xdg-open "$remote"
end

25
functions/repo.fish Normal file

@ -0,0 +1,25 @@
function repo
set cmd $argv[1]
set arg $argv[2]
switch "$cmd"
case 'get'
repo_clone "git" "$arg"
case 'aur'
repo_clone "aur" "$arg"
case 'open'
repo_open
case 'list'
list_repos
case 'go' 'goto'
repo_goto "$arg"
case 'new' 'create'
repo_new "$arg"
case 'help' '-h' '-help' '--help'
repo_help
case '*'
echo "Unknown command: $cmd"
repo_help
return 1
end
end

@ -2,6 +2,8 @@
## installation
### ZSH
- Sheldon
```
@ -14,6 +16,20 @@ sheldon add repo-manager --github abs3ntdev/repo-manager
zinit light abs3ntdev/repo-manager
```
### Fish
- Fisher
```
fisher install abs3ntdev/repo-manager
```
- Oh My Fish
```
omf install abs3ntdev/repo-manager
```
## usage
```
@ -37,10 +53,12 @@ Examples:
### hooks
hooks are configured by overriding the functions provided in the plugin in hooks.zsh
the default hooks are:
#### ZSH
```
Hooks are configured by overriding the functions provided in the plugin in hooks.zsh
The default hooks are:
```zsh
post_repo_clone() {
cd "$1"
}
@ -54,9 +72,9 @@ post_repo_new() {
}
```
you can override these in your .zshrc or in a file sourced by your .zshrc to do whatever you want. example:
You can override these in your .zshrc or in a file sourced by your .zshrc to do whatever you want. Example:
```
```zsh
post_repo_clone() {
code "$1"
}
@ -70,10 +88,55 @@ post_repo_new() {
}
```
#### Fish
Hooks are configured by overriding the functions provided in the plugin in hooks.fish
The default hooks are:
```fish
function post_repo_clone
cd "$argv[1]"
end
function post_repo_goto
cd "$argv[1]"
end
function post_repo_new
cd "$argv[1]"
end
```
You can override these in your config.fish or in a file sourced by your config.fish to do whatever you want. Example:
```fish
function post_repo_clone
code "$argv[1]"
end
function post_repo_goto
nvim "$argv[1]"
end
function post_repo_new
some_script "$argv[1]"
end
```
### base directory
the base directory is set via ENV. the default is $HOME/repos you can change this by adding the following to your .zshrc
#### ZSH
```
The base directory is set via ENV. The default is $HOME/repos. You can change this by adding the following to your .zshrc:
```zsh
export REPO_BASE_DIR="whatever/you/want"
```
#### Fish
The base directory is set via ENV. The default is $HOME/repos. You can change this by adding the following to your config.fish:
```fish
set -g REPO_BASE_DIR "whatever/you/want"
```

6
repo.plugin.fish Normal file

@ -0,0 +1,6 @@
set -q REPO_BASE_DIR; or set -g REPO_BASE_DIR "$HOME/repos"
set functions_dir (status dirname)/functions
for script in $functions_dir/*.fish
source $script
end