Skip to content

Commit

Permalink
feat: allow navigation into symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
ALX99 committed May 20, 2024
1 parent 5d71c0a commit 7b354fc
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions internal/models/main_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,37 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, m.loadDir(path.Dir(m.cwd))

case m.cfg.Settings.Keymap.NavIn:
if len(m.files) > 0 && m.files[m.cursorOffset()].IsDir() {
return m, m.loadDir(path.Join(m.cwd, m.files[m.cursorOffset()].Name()))
if len(m.files) <= 0 {
return m, nil
}

currentFile := m.files[m.cursorOffset()]

if currentFile.IsDir() {
return m, m.loadDir(path.Join(m.cwd, currentFile.Name()))
}

if currentFile.Type() != fs.ModeSymlink {
return m, nil
}

path, err := os.Readlink(path.Join(m.cwd, currentFile.Name()))
if err != nil {
m.lastError = err
return m, nil
}

info, err := os.Stat(path)
if err != nil {
m.lastError = err
return m, nil
}

if info.IsDir() {
return m, m.loadDir(path)
}
return m, nil

case m.cfg.Settings.Keymap.NavHome:
home, err := os.UserHomeDir()
if err != nil {
Expand Down

0 comments on commit 7b354fc

Please sign in to comment.