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:
mktemp
is not POSIX. This means thatlfcd
is also not POSIX (here, by POSIX I mean it only requires utilities/commands found in the POSIX specification and the obviouslf
). Whilemktemp
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).- 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?
- Lf can already write to a file, it would be trivial to instead print something to stdout.
- 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 "$@")
- 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