From ddd1935d05eb01d3a5f1e04d84a8d57d354174b6 Mon Sep 17 00:00:00 2001 From: cyc4188 <1065768794@qq.com> Date: Wed, 23 Aug 2023 00:30:47 +0800 Subject: [PATCH 1/4] fix: incorrect icons --- icons.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/icons.go b/icons.go index 6bd60e4..65d5d0d 100644 --- a/icons.go +++ b/icons.go @@ -70,8 +70,6 @@ func (im iconMap) getIcon(f os.FileInfo) string { key = "su" case f.Mode()&os.ModeSetgid != 0: key = "sg" - case f.Mode()&0111 != 0: - key = "ex" } if val, ok := im[key]; ok { return val @@ -89,6 +87,11 @@ func (im iconMap) getIcon(f os.FileInfo) string { if val, ok := im["*"+strings.ToLower(ext)]; ok { return val } + if f.Mode()&0111 != 0 { + if val, ok := im["ex"]; ok { + return val + } + } if val, ok := im["fi"]; ok { return val } From 52e434779cc499e86e046e81ebb4ce6b9468927b Mon Sep 17 00:00:00 2001 From: cyc4188 <1065768794@qq.com> Date: Sun, 27 Aug 2023 19:27:06 +0800 Subject: [PATCH 2/4] feat: yank path to clipboard with y --- go.mod | 1 + go.sum | 1 + main.go | 22 +++++++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 467b7d0..7d72cd1 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( ) require ( + github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect diff --git a/go.sum b/go.sum index 65be8f0..89fbb7a 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= 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= diff --git a/main.go b/main.go index 34a1d43..39c59ab 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "time" "unicode/utf8" + "github.com/atotto/clipboard" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -63,6 +64,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() { @@ -126,6 +128,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 { @@ -356,9 +359,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() m.preview() @@ -472,12 +481,12 @@ 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 len(m.files) == 0 { - main = bar + "\n" + warning.Render("No files") + main = barStr + "\n" + warning.Render("No files") } // Delete bar. @@ -488,6 +497,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, @@ -825,6 +840,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() From e4dbf363cca5e9022f14a576f74af27a851205c9 Mon Sep 17 00:00:00 2001 From: cyc4188 <1065768794@qq.com> Date: Sun, 27 Aug 2023 19:31:36 +0800 Subject: [PATCH 3/4] update: readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 54a847b..c010e2d 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. From d7db2ec6be2a0a4e6e391d37de0cf48e251061b6 Mon Sep 17 00:00:00 2001 From: cyc4188 <1065768794@qq.com> Date: Sat, 2 Sep 2023 16:23:03 +0800 Subject: [PATCH 4/4] update: clipboard lib --- go.mod | 2 +- go.sum | 4 ++-- main.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index e756054..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 @@ -12,7 +13,6 @@ require ( ) require ( - github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect diff --git a/go.sum b/go.sum index 30e4138..5a960ae 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= -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 409e238..c0a9c42 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "time" "unicode/utf8" - "github.com/atotto/clipboard" + "github.com/antonmedv/clipboard" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss"