From 5ff197b53f10a9acdaee47ff564e39cbdce57c74 Mon Sep 17 00:00:00 2001 From: abs3nt <abs3nt@asdf.cafe> Date: Wed, 5 Mar 2025 11:05:35 -0800 Subject: [PATCH] stuff --- README.md | 107 ++++++++++++++++++++++++++++++++++++++ completions/repo.fish | 21 -------- functions/_repo_open.fish | 6 +-- 3 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..99db382 --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ +# repo.fish + +A Fish shell plugin to simplify git repository management. + +## Features + +- Clone repositories with a consistent directory structure +- Navigate to repositories quickly +- Create new git repositories +- Open repositories in your browser +- List all your repositories +- Customizable hooks for post-clone, post-goto, and post-new actions + +## Installation + +Install with [Fisher](https://github.com/jorgebucaran/fisher): + +```fish +fisher install abs3ntdev/repo.fish +``` + +## Usage + +### Basic Commands + +```fish +# Clone a repository +repo get github.com/user/repo + +# Navigate to a repository +repo go github.com/user/repo + +# Create a new repository +repo new github.com/user/myrepo + +# Open current repository in browser +repo open + +# Clone an AUR repository +repo aur package-name + +# List all repositories +repo list + +# Show help +repo help +``` + +### Configuration + +By default, all repositories are stored in `~/repos`. You can change this by setting the `$REPO_BASE_DIR` variable in your `config.fish`: + +```fish +set -gx REPO_BASE_DIR ~/path/to/repos +``` + +### Custom Hooks + +repo.fish provides three hooks that you can customize: + +1. **Post-clone hook**: Runs after cloning a repository +2. **Post-goto hook**: Runs after navigating to a repository +3. **Post-new hook**: Runs after creating a new repository + +To use hooks, define the following functions: + +```fish +# Define a custom post-clone hook +function repo_post_clone + echo "Repository cloned to: $argv[1]" + # Your custom actions here + cd $argv[1] + # You can run additional commands like: + # npm install + # bundle install + # etc. +end + +# Define a custom post-goto hook +function repo_post_goto + echo "Navigated to: $argv[1]" + # Your custom actions here + cd $argv[1] + # You can run additional commands like: + # git status + # ls -la + # etc. +end + +# Define a custom post-new hook +function repo_post_new + echo "Created new repository at: $argv[1]" + # Your custom actions here + cd $argv[1] + # You can run additional commands like: + # touch README.md + # git add README.md + # git commit -m "Initial commit" + # etc. +end +``` + +If you don't define these functions, the default behavior is to change to the repository directory. + +## License + +MIT diff --git a/completions/repo.fish b/completions/repo.fish index 5b7b909..ab12a31 100644 --- a/completions/repo.fish +++ b/completions/repo.fish @@ -18,25 +18,4 @@ 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" -printf "%h\n" 2>/dev/null | sed 's|.*/||; s/\./_/g' -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_open.fish b/functions/_repo_open.fish index fd11909..612418a 100644 --- a/functions/_repo_open.fish +++ b/functions/_repo_open.fish @@ -1,13 +1,13 @@ 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) - + set remote (string replace -r "^https://([^/]+):" "https://\$1/" $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