diff --git a/README.md b/README.md index 2e23380..fa95388 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Now use `lk` command to start walking. | `Ctrl+c` | Exit without cd | | `/` | Fuzzy search | | `dd` | Delete file or dir | +| `y` | yank current dir | The `EDITOR` or `WALK_EDITOR` environment variable used for opening files from the walk. diff --git a/go.mod b/go.mod index 4f1a82d..42471b0 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/antonmedv/walk go 1.17 require ( + github.com/antonmedv/clipboard v1.0.1 github.com/charmbracelet/bubbles v0.16.1 github.com/charmbracelet/bubbletea v0.24.2 github.com/charmbracelet/lipgloss v0.8.0 diff --git a/go.sum b/go.sum index 6c21213..5a960ae 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ -github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/antonmedv/clipboard v1.0.1 h1:z9rRBhSKt4lDb6uNcMykUmNbspk/6v07JeiTaOfYYOY= +github.com/antonmedv/clipboard v1.0.1/go.mod h1:3jcOUCdraVHehZaOsMaJZoE92MxURt5fovC1gDAiZ2s= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= diff --git a/main.go b/main.go index 6494228..c0a9c42 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "time" "unicode/utf8" + "github.com/antonmedv/clipboard" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -64,6 +65,7 @@ var ( keyPreview = key.NewBinding(key.WithKeys(" ")) keyDelete = key.NewBinding(key.WithKeys("d")) keyUndo = key.NewBinding(key.WithKeys("u")) + keyYank = key.NewBinding(key.WithKeys("y")) ) func main() { @@ -128,6 +130,7 @@ type model struct { previewContent string // Content of preview. deleteCurrentFile bool // Whether to delete current file. toBeDeleted []toDelete // Map of files to be deleted. + yankSuccess bool // Show yank info } type position struct { @@ -355,9 +358,15 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } + case key.Matches(msg, keyYank): + // copy path to clipboard + clipboard.WriteAll(m.path) + m.yankSuccess = true + return m, nil } // End of switch statement for key presses. m.deleteCurrentFile = false + m.yankSuccess = false m.updateOffset() m.saveCursorPosition() @@ -474,14 +483,14 @@ func (m *model) View() string { if barLen > outputWidth { location = location[min(barLen-outputWidth, len(location)):] } - bar := bar.Render(location) + search.Render(filter) + barStr := bar.Render(location) + search.Render(filter) - main := bar + "\n" + Join(output, "\n") + main := barStr + "\n" + Join(output, "\n") if m.err != nil { - main = bar + "\n" + warning.Render(m.err.Error()) + main = barStr + "\n" + warning.Render(m.err.Error()) } else if len(m.files) == 0 { - main = bar + "\n" + warning.Render("No files") + main = barStr + "\n" + warning.Render("No files") } // Delete bar. @@ -492,6 +501,12 @@ func (m *model) View() string { main += "\n" + danger.Render(deleteBar) } + // Yank success. + if m.yankSuccess { + yankBar := fmt.Sprintf("yanked path to clipboard: %v", m.path) + main += "\n" + bar.Render(yankBar) + } + if m.previewMode { return lipgloss.JoinHorizontal( lipgloss.Top, @@ -884,6 +899,7 @@ func usage() { put(" Ctrl+c\tExit without cd") put(" /\tFuzzy search") put(" dd\tDelete file or dir") + put(" y\tYank current directory path to clipboard") put("\n Flags:\n") put(" --icons\tdisplay icons") _ = w.Flush()