forked from a/repotool
Merge pull request 'fish' (#1) from abs3nt/repotool:fishy into master
Reviewed-on: a/repotool#1
This commit is contained in:
commit
abe56ca25a
59
fish-repotool/README.md
Normal file
59
fish-repotool/README.md
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# Fish Repotool Plugin
|
||||||
|
|
||||||
|
A Fish shell plugin for the repotool repository management system.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### Using Fisher
|
||||||
|
|
||||||
|
```fish
|
||||||
|
fisher install path/to/fish-repotool
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual Installation
|
||||||
|
|
||||||
|
1. Copy the `conf.d/repotool.fish` file to your fish config directory:
|
||||||
|
```fish
|
||||||
|
cp conf.d/repotool.fish ~/.config/fish/conf.d/
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Copy the `functions/repotool.fish` file to your fish functions directory:
|
||||||
|
```fish
|
||||||
|
cp functions/repotool.fish ~/.config/fish/functions/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Set the `REPOTOOL_PATH` environment variable to specify where your repositories are stored:
|
||||||
|
|
||||||
|
```fish
|
||||||
|
set -gx REPOTOOL_PATH "$HOME/my-repos"
|
||||||
|
```
|
||||||
|
|
||||||
|
If not set, it defaults to `$HOME/repo`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
The plugin provides a `repo` alias that sources the repotool function with the following commands:
|
||||||
|
|
||||||
|
- `repo get <url>` - Clone a repository if not found
|
||||||
|
- `repo worktree list` - List existing worktrees
|
||||||
|
- `repo worktree get <name>` - Create or go to a worktree
|
||||||
|
- `repo worktree root` - Return to the root directory
|
||||||
|
- `repo worktree remove <name>` - Remove a worktree
|
||||||
|
- `repo open` - Open the current repository in web browser
|
||||||
|
|
||||||
|
## Hooks
|
||||||
|
|
||||||
|
The plugin supports hooks that can be placed in `$REPOTOOL_PATH/.hooks/`:
|
||||||
|
|
||||||
|
- `before_<hook_name>_cd.fish` - Executed before changing directory
|
||||||
|
- `after_<hook_name>_cd.fish` - Executed after changing directory
|
||||||
|
|
||||||
|
Hooks can also have `.sh` extension or no extension at all.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Fish shell 4.0 or later
|
||||||
|
- `jq` for JSON parsing
|
||||||
|
- The repotool binary installed at `$REPOTOOL_PATH/.bin/repotool`
|
||||||
9
fish-repotool/conf.d/repotool.fish
Normal file
9
fish-repotool/conf.d/repotool.fish
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
# Set default REPOTOOL_PATH if not already set
|
||||||
|
if not set -q REPOTOOL_PATH
|
||||||
|
set -gx REPOTOOL_PATH "$HOME/repo"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create alias that sources the main repotool function
|
||||||
|
alias repo="source $REPOTOOL_PATH/.shell/repotool.fish"
|
||||||
79
fish-repotool/functions/repotool.fish
Normal file
79
fish-repotool/functions/repotool.fish
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
# Set default REPOTOOL_PATH if not already set
|
||||||
|
if not set -q REPOTOOL_PATH
|
||||||
|
set -gx REPOTOOL_PATH "$HOME/repo"
|
||||||
|
end
|
||||||
|
|
||||||
|
function _activate_hook
|
||||||
|
set -l hook_name $argv[1]
|
||||||
|
set -l response $argv[2]
|
||||||
|
|
||||||
|
if test -f "$REPOTOOL_PATH/.hooks/$hook_name.fish"
|
||||||
|
source "$REPOTOOL_PATH/.hooks/$hook_name.fish" $response
|
||||||
|
return 0
|
||||||
|
else if test -f "$REPOTOOL_PATH/.hooks/$hook_name.sh"
|
||||||
|
source "$REPOTOOL_PATH/.hooks/$hook_name.sh" $response
|
||||||
|
return 0
|
||||||
|
else if test -f "$REPOTOOL_PATH/.hooks/$hook_name"
|
||||||
|
source "$REPOTOOL_PATH/.hooks/$hook_name" $response
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function _parse_json
|
||||||
|
set -l response $argv[1]
|
||||||
|
set -l key $argv[2]
|
||||||
|
echo "$response" | jq -r ".$key"
|
||||||
|
end
|
||||||
|
|
||||||
|
function _handle_response
|
||||||
|
set -l response $argv[1]
|
||||||
|
|
||||||
|
# Validate JSON
|
||||||
|
if not echo "$response" | jq . >/dev/null 2>&1
|
||||||
|
# Not valid JSON, write to stderr
|
||||||
|
echo "$response" >&2
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if response has an echo field
|
||||||
|
set -l echo_msg (echo "$response" | jq -r '.echo // empty')
|
||||||
|
if test -n "$echo_msg"
|
||||||
|
echo "$echo_msg"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get hook name from response
|
||||||
|
set -l hook_name (echo "$response" | jq -r '.hook // empty')
|
||||||
|
|
||||||
|
# Handle before hook if hook name is provided
|
||||||
|
if test -n "$hook_name"
|
||||||
|
_activate_hook "before_{$hook_name}_cd" "$response"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if response has a cd field
|
||||||
|
set -l cd_path (echo "$response" | jq -r '.cd // empty')
|
||||||
|
if test -n "$cd_path"
|
||||||
|
cd "$cd_path"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Handle after hook if hook name is provided
|
||||||
|
if test -n "$hook_name"
|
||||||
|
_activate_hook "after_{$hook_name}_cd" "$response"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
set TOOL_BIN "$REPOTOOL_PATH/.bin/repotool"
|
||||||
|
|
||||||
|
# Pass all arguments to repotool and handle response
|
||||||
|
set -l response ($TOOL_BIN $argv)
|
||||||
|
set -l exit_code $status
|
||||||
|
|
||||||
|
if test $exit_code -ne 0
|
||||||
|
echo "Command failed with exit code $exit_code" >&2
|
||||||
|
return $exit_code
|
||||||
|
end
|
||||||
|
|
||||||
|
_handle_response "$response"
|
||||||
Loading…
Reference in New Issue
Block a user