Skip to content

lfcd improvement proposal #1393

@nicolasdumitru

Description

Goal

Simplifying lfcd and making it more POSIX compliant.

Issue

Currently, lfcd uses temporary files that it creates with mktemp in order to store the path of the directory that was last open in lf and into it. This poses multiple problems:

  1. mktemp is not POSIX. This means that lfcd is also not POSIX (here, by POSIX I mean it only requires utilities/commands found in the POSIX specification and the obvious lf). While mktemp is pretty widely available as a GNU and BSD utility, it could be a problem on some POSIX compliant operating systems (e.g. non-GNU Linux distros).
  2. Usage of temporary files is messy, overcomplicated and potentially unsafe (in some cases, not necessarily here).

Solution

Add a flag/option to lf that is similar to -last-dir-path, but instead of writing to a file, outputs to stdout. Why?

  1. Lf can already write to a file, it would be trivial to instead print something to stdout.
  2. the lfcd function body becomes a trivial, much simpler, more POSIX-compliant and less prone to breakage one-liner: \cd $(\lf -new-flag-to-print-path-to-stdout "$@")
  3. lfcd doesn't have to check for the existence of a temporary file and then make sure it gets deleted.

The inspiration for this is fzf. By default, fzf prints the path to what you search for to stdout. Consequently, a user can do something like vim $(fzf) to edit a file that they don't know the exact path to or cd $(dirname $(fzf)) to do some fuzzy searching for a file and cd into the directory of said file. If you are interested and would like to try something similar without having to write a single line of code, try the above mentioned cd $(dirname $(fzf)) and search for a file or a directory where you have files.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions