don't replace workdir anymore

This commit is contained in:
Lilian Jónsdóttir 2024-07-15 15:58:57 -07:00
parent 1a9e64d473
commit 26f5f383ce
2 changed files with 6 additions and 8 deletions

View file

@ -11,14 +11,12 @@ import (
// $HOME -> ~
// $PWD -> .
// workdir -> .
func UnExpand(dir, workdir string) (outdir string) {
func UnExpand(dir string) (outdir string) {
outdir = filepath.Clean(dir)
home := os.Getenv("HOME")
if pwd, err := os.Getwd(); err == nil && home != pwd {
outdir = strings.Replace(outdir, pwd, ".", 1)
} else if workdir != "" {
outdir = strings.Replace(outdir, workdir, "", 1)
}
outdir = strings.Replace(outdir, home, "~", 1)

View file

@ -279,7 +279,7 @@ func (m model) header() string {
default:
mode = m.mode.String()
if m.workdir != "" {
mode += fmt.Sprintf(" in %s ", dirs.UnExpand(m.workdir, ""))
mode += fmt.Sprintf(" in %s ", dirs.UnExpand(m.workdir))
}
}
mode += fmt.Sprintf(" %s %s", dot, strings.Join(select_keys, wide_dot))
@ -319,7 +319,7 @@ func (m model) selectedFiles() (outfile files.Files) {
return false
} */
func newRow(file files.File, workdir string) table.Row {
func newRow(file files.File) table.Row {
var t, b string
t = humanize.Time(file.Date())
if file.IsDir() {
@ -329,7 +329,7 @@ func newRow(file files.File, workdir string) table.Row {
}
return table.Row{
dirs.UnEscape(file.Name()),
dirs.UnExpand(filepath.Dir(file.Path()), workdir),
dirs.UnExpand(filepath.Dir(file.Path())),
t,
b,
}
@ -337,7 +337,7 @@ func newRow(file files.File, workdir string) table.Row {
func (m *model) freshRows(preselected bool) (rows []table.Row) {
for _, f := range m.files {
r := newRow(f, m.workdir)
r := newRow(f)
if !m.readonly {
r = append(r, getCheck(preselected))
@ -474,7 +474,7 @@ func (m *model) sort() {
slices.SortStableFunc(m.files, m.sorting.Sorter())
var rows []table.Row
for _, file := range m.files {
r := newRow(file, m.workdir)
r := newRow(file)
if !m.readonly {
r = append(r, getCheck(m.selected[file.String()]))
}