Skip to content

Commit 6283eb2

Browse files
Merge pull request #14 from nathan-fiscaletti/dev
Added support for interactive pinning/unpinning
2 parents f6a2c68 + b2297a9 commit 6283eb2

File tree

5 files changed

+327
-37
lines changed

5 files changed

+327
-37
lines changed

README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
https://github.com/user-attachments/assets/d22fadbd-bf6e-412e-80be-f2218536642c
2-
31
# git-switch
42

53
A fast, interactive terminal UI for switching between git branches. Built with [tcell](https://github.com/gdamore/tcell) for a smooth, cross-platform experience.
@@ -46,6 +44,8 @@ sw
4644
- Use **Up/Down** arrows to select.
4745
- Press **Enter** to checkout the selected branch.
4846
- Press **Esc** or **Ctrl+C** to exit.
47+
- Press **CTRL+D** to pin the currently selected branch.
48+
- Press **CTRL+U** to unpin the currently selected branch.
4949

5050
### Git Checkout Override
5151

@@ -128,31 +128,67 @@ The interactive branch selector is exposed in the [`pkg`](./pkg) package.
128128
package main
129129

130130
import (
131+
"fmt"
131132
sw "github.com/nathan-fiscaletti/git-switch/pkg"
132133
)
133134

134135
func main() {
136+
// Your branch data
137+
currentBranch := "main"
138+
branches := []string{"main", "develop", "feature/new-api", "bugfix/issue-123"}
139+
pinnedBranches := []string{"main", "develop"}
140+
135141
branchSelector, err := sw.NewBranchSelector(sw.BranchSelectorArguments{
136142
CurrentBranch: currentBranch,
137143
Branches: branches,
138-
PinnedBranches: pinnedBranches,
144+
PinnedBranches: &pinnedBranches, // Pass as pointer for shared state
139145
PinnedBranchPrefix: "",
140146
WindowSize: 10,
141147
SearchLabel: "search branch",
148+
149+
// Optional: Handle pin/unpin operations
150+
OnPinBranch: func(branch string) error {
151+
// Implement your own storage logic
152+
fmt.Printf("Pinning branch: %s\n", branch)
153+
// Save to database, file, etc.
154+
return nil
155+
},
156+
OnUnpinBranch: func(branch string) error {
157+
// Implement your own storage logic
158+
fmt.Printf("Unpinning branch: %s\n", branch)
159+
// Remove from database, file, etc.
160+
return nil
161+
},
142162
})
143163
if err != nil {
144164
panic(err)
145165
}
146166

147-
b, err := branchSelector.PickBranch()
167+
// Show the interactive selector
168+
selectedBranch, err := branchSelector.PickBranch()
148169
if err != nil {
149170
panic(err)
150171
}
151172

152-
// ... use b ...
173+
if selectedBranch != "" {
174+
fmt.Printf("Selected branch: %s\n", selectedBranch)
175+
// Process the selected branch...
176+
}
153177
}
154178
```
155179

180+
#### Interactive Features
181+
182+
The branch selector includes interactive hotkeys:
183+
184+
- **CTRL+D**: Pin the currently selected branch
185+
- **CTRL+U**: Unpin the currently selected branch
186+
- **Up/Down**: Navigate branches
187+
- **Enter**: Select branch
188+
- **Esc/Ctrl+C**: Exit
189+
190+
Pin/unpin operations automatically call your `OnPinBranch` and `OnUnpinBranch` callbacks, allowing you to integrate with any storage backend (database, files, APIs, etc.).
191+
156192
## Configuration
157193

158194
Config File Location:

0 commit comments

Comments
 (0)