an alternative way to pass directories out back to the shell, without costume wrappers #2060
Replies: 3 comments 22 replies
-
To be honest, this seems more hacky then the current approach. I don't like this hardcoded script at all. It assumes |
Beta Was this translation helpful? Give feedback.
-
By using |
Beta Was this translation helpful? Give feedback.
-
The nested shell also increments
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I've been researching solutions to the directory inheritance problem that lf (and most CLI tools) face. I really appreciate how lf addresses this with the lfcd wrapper scripts - it's a clean solution that works well.
I've been exploring an alternative approach that might simplify the setup process for users, and I wanted to get the community's thoughts on the trade-offs.
Current approach (lfcd scripts)
Wrapper function captures lf's output via -print-last-dir
Shell function manually calls cd after lf exits
Requires users to source shell-specific scripts
Works reliably across different workflows
Alternative approach (process replacement)
Instead of wrapper scripts, the application itself could handle the transition:
When lf exits, instead of returning to the shell immediately
lf replaces its own process with a small transition script:
bash#!/bin/bash
cd "/final/directory"
exec $SHELL
User ends up in the final directory without any setup
the implementation I came up with for testing
exact changes
possible future
autocd docs themselves
While lf's current lfcd scripts exemplify classic Unix composability by externalizing
the cd logic, my proposed --autocd method offers an alternative, integrated approach.
This feature is entirely opt-in; when the --autocd flag is not used, lf functions as a standard Unix command, fully compatible with pipes and redirections. By leveraging the exec syscall—a fundamental Unix primitive—to directly transition the shell, this approach provides a seamless user experience without fundamentally violating Unix principles, offering a different design choice for how an application can integrate its navigational state with the user's shell.
im looking for advise? am I being dumb with my approach? I feel like it works reliably?
Beta Was this translation helpful? Give feedback.
All reactions