From 966643fd2e87934c14672c31e169f788adef671f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Wed, 19 Jun 2024 22:21:35 -0700 Subject: [PATCH] replace workdir with . in tables --- internal/dirs/dirs.go | 10 ++++++++-- internal/tables/tables.go | 10 +++++----- main.go | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/internal/dirs/dirs.go b/internal/dirs/dirs.go index 1ec4103..64e1854 100644 --- a/internal/dirs/dirs.go +++ b/internal/dirs/dirs.go @@ -9,7 +9,9 @@ import ( // UnExpand unexpands some directory shortcuts // // $HOME -> ~ -func UnExpand(dir string) (outdir string) { +// $PWD -> . +// workdir -> . +func UnExpand(dir, workdir string) (outdir string) { var ( home = os.Getenv("HOME") pwd string @@ -18,9 +20,13 @@ func UnExpand(dir string) (outdir string) { outdir = filepath.Clean(dir) + if workdir != "" { + outdir = strings.Replace(outdir, workdir, ".", 1) + } + pwd, err = os.Getwd() if err == nil && home != pwd { - outdir = strings.Replace(outdir, pwd, "$PWD", 1) + outdir = strings.Replace(outdir, pwd, ".", 1) } outdir = strings.Replace(outdir, home, "~", 1) diff --git a/internal/tables/tables.go b/internal/tables/tables.go index aa0e4ee..8a6621d 100644 --- a/internal/tables/tables.go +++ b/internal/tables/tables.go @@ -89,7 +89,7 @@ func newInfosModel(is trash.Infos, width, height int, readonly, preselected bool } r := table.Row{ i.Name(), - dirs.UnExpand(filepath.Dir(i.OGPath())), + dirs.UnExpand(filepath.Dir(i.OGPath()), ""), t, b, } @@ -120,7 +120,7 @@ func newInfosModel(is trash.Infos, width, height int, readonly, preselected bool return m } -func newFilesModel(fs files.Files, width, height int, readonly, preselected bool) model { +func newFilesModel(fs files.Files, width, height int, readonly, preselected bool, workdir string) model { var ( fwidth int = int(math.Round(float64(width-woffset) * 0.4)) owidth int = int(math.Round(float64(width-woffset) * 0.2)) @@ -150,7 +150,7 @@ func newFilesModel(fs files.Files, width, height int, readonly, preselected bool } r := table.Row{ f.Name(), - dirs.UnExpand(f.Path()), + dirs.UnExpand(f.Path(), workdir), t, b, } @@ -473,8 +473,8 @@ func InfoTable(is trash.Infos, width, height int, readonly, preselected bool, mo } } -func FilesTable(fs files.Files, width, height int, readonly, preselected bool) ([]int, error) { - if endmodel, err := tea.NewProgram(newFilesModel(fs, width, height, readonly, preselected)).Run(); err != nil { +func FilesTable(fs files.Files, width, height int, readonly, preselected bool, workdir string) ([]int, error) { + if endmodel, err := tea.NewProgram(newFilesModel(fs, width, height, readonly, preselected, workdir)).Run(); err != nil { return []int{}, err } else { m, ok := endmodel.(model) diff --git a/main.go b/main.go index f78f1ee..9eda459 100644 --- a/main.go +++ b/main.go @@ -94,7 +94,8 @@ var ( return nil } - indices, err := tables.FilesTable(fls, termwidth, termheight, false, !f.Blank()) + log.Debugf("what is workdir? it's %s", workdir) + indices, err := tables.FilesTable(fls, termwidth, termheight, false, !f.Blank(), workdir) if err != nil { return err }