From 20c85c947744235e8309909d8bb1b99174c5b329 Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Thu, 1 Oct 2026 02:59:29 +0200 Subject: [PATCH] feat: support `cd -` (#2693) * feat: support `cd -` * docs: add documentation * docs: update `CHANGELOG.md` --- CHANGELOG.md | 4 ++++ doc.md | 1 + doc.txt | 3 ++- eval.go | 9 ++++++++- lf.1 | 4 +++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee2cb0bf..ad61dd2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## Unreleased +### Added + +- The `cd` command now supports `-` to change to the previous directory (#2693). + ### Fixed - Dead client connections no longer prevent the `quit` server command from terminating the server (#2643). diff --git a/doc.md b/doc.md index e23c847a..d588d020 100644 --- a/doc.md +++ b/doc.md @@ -674,6 +674,7 @@ Print given arguments to the message line at the bottom as `errorfmt` and also t ## cd Change the working directory to the given argument. +If the argument is `-`, change to the previous directory stored in the special bookmark `'`. ## select diff --git a/doc.txt b/doc.txt index 211b9548..36a84c90 100644 --- a/doc.txt +++ b/doc.txt @@ -707,7 +707,8 @@ also to the log file. cd -Change the working directory to the given argument. +Change the working directory to the given argument. If the argument is +-, change to the previous directory stored in the special bookmark '. select diff --git a/eval.go b/eval.go index 59b16796..b9c35754 100644 --- a/eval.go +++ b/eval.go @@ -989,13 +989,20 @@ func insert(app *app, arg string) { } func cd(app *app, path string) error { - wd := app.nav.currDir().path + if path == "-" { + prev, ok := app.nav.marks["'"] + if !ok { + return errors.New("no previous directory") + } + path = prev + } path, err := filepath.Abs(replaceTilde(path)) if err != nil { return fmt.Errorf("getting absolute path: %w", err) } + wd := app.nav.currDir().path if path == wd { return nil } diff --git a/lf.1 b/lf.1 index ec7db2b8..84b69645 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.7.0.2 .\" -.TH "LF" "1" "2026\-08\-11" "r43" "DOCUMENTATION" +.TH "LF" "1" "2026\-10\-01" "r43" "DOCUMENTATION" .SH NAME lf \- terminal file manager .SH SYNOPSIS @@ -676,6 +676,8 @@ Print given arguments to the message line at the bottom as \f[CR]errorfmt\f[R] and also to the log file. .SS cd Change the working directory to the given argument. +If the argument is \f[CR]\-\f[R], change to the previous directory +stored in the special bookmark \f[CR]\(aq\f[R]. .SS select Change the current file selection to the given argument. .SS source