replace workdir with . in tables

This commit is contained in:
Lilian Jónsdóttir 2024-06-19 22:21:35 -07:00
parent f7605f6eab
commit 966643fd2e
3 changed files with 15 additions and 8 deletions

View file

@ -9,7 +9,9 @@ import (
// UnExpand unexpands some directory shortcuts // UnExpand unexpands some directory shortcuts
// //
// $HOME -> ~ // $HOME -> ~
func UnExpand(dir string) (outdir string) { // $PWD -> .
// workdir -> .
func UnExpand(dir, workdir string) (outdir string) {
var ( var (
home = os.Getenv("HOME") home = os.Getenv("HOME")
pwd string pwd string
@ -18,9 +20,13 @@ func UnExpand(dir string) (outdir string) {
outdir = filepath.Clean(dir) outdir = filepath.Clean(dir)
if workdir != "" {
outdir = strings.Replace(outdir, workdir, ".", 1)
}
pwd, err = os.Getwd() pwd, err = os.Getwd()
if err == nil && home != pwd { if err == nil && home != pwd {
outdir = strings.Replace(outdir, pwd, "$PWD", 1) outdir = strings.Replace(outdir, pwd, ".", 1)
} }
outdir = strings.Replace(outdir, home, "~", 1) outdir = strings.Replace(outdir, home, "~", 1)

View file

@ -89,7 +89,7 @@ func newInfosModel(is trash.Infos, width, height int, readonly, preselected bool
} }
r := table.Row{ r := table.Row{
i.Name(), i.Name(),
dirs.UnExpand(filepath.Dir(i.OGPath())), dirs.UnExpand(filepath.Dir(i.OGPath()), ""),
t, t,
b, b,
} }
@ -120,7 +120,7 @@ func newInfosModel(is trash.Infos, width, height int, readonly, preselected bool
return m 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 ( var (
fwidth int = int(math.Round(float64(width-woffset) * 0.4)) fwidth int = int(math.Round(float64(width-woffset) * 0.4))
owidth int = int(math.Round(float64(width-woffset) * 0.2)) 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{ r := table.Row{
f.Name(), f.Name(),
dirs.UnExpand(f.Path()), dirs.UnExpand(f.Path(), workdir),
t, t,
b, 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) { 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)).Run(); err != nil { if endmodel, err := tea.NewProgram(newFilesModel(fs, width, height, readonly, preselected, workdir)).Run(); err != nil {
return []int{}, err return []int{}, err
} else { } else {
m, ok := endmodel.(model) m, ok := endmodel.(model)

View file

@ -94,7 +94,8 @@ var (
return nil 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 { if err != nil {
return err return err
} }