Make Cd_on_quit More Cross Platform And More Clean.
Introduction
The cd_on_quit
feature in Superfile is a powerful tool that allows users to automatically switch to the last directory they were in when they quit the application. However, this feature is not yet fully cross-platform, and its implementation can be improved for better user experience. In this article, we will explore the current state of cd_on_quit
and discuss possible solutions to make it more cross-platform and clean.
Current Implementation
The current implementation of cd_on_quit
uses the --print-last-dir
option, which was added in #488. This option prints the last directory to the console, and users can then use the cd
command to switch to that directory. However, as we can see from the conversation above, this approach has some limitations.
➜ ~ [10:46:39] DIR=$(spf --print-last-dir); echo "DIR is $DIR"; cd $DIR
DIR is /Users/kuknitin
cd: file name too long: ^[[?25l^[[?1049h^[[2J^[[H^[[?25l^[[?2004h^[[?1002h^[[?1006h^[]2;SuperFile^G^[[H^M Terminal size too small: ^M\n Width = 0 Height = 0 ^M\n ^M\nNeeded for current config:^M\n Width = 60 Height = 24 ^[[5;H^[[2K^M^[[?2004l^[[?25h^[[?1002l^[[?1003l^[[?1006l^[[?1049l^[[?25h/Users/kuknitin
➜ ~ [10:46:53]
As we can see, the cd
command fails with a "file name too long" error. This is because the --print-last-dir
option prints the last directory in a format that is not compatible with the cd
command.
Alternative Approaches
One possible solution to this problem is to introduce new arguments in the spf path-list
command, as suggested by @lazysegtree. This would allow users to specify the last directory and log file separately, making it easier to switch to the last directory.
spf path-list --last-dir
spf path-list --log-file
Then, users can use the following command to switch to the last directory:
DIR=$(spf path-list --last-dir); spf; source $DIR
This approach is similar to how yazi
does it using its --cwd-file
argument. Another possible solution is to use a different approach to print the last directory, one that is compatible with the cd
command.
Conclusion
In conclusion, the cd_on_quit
feature in Superfile is a powerful tool that can be improved for better user experience. By introducing new arguments in the spf path-list
command or using a different approach to print the last directory, we can make cd_on_quit
more cross-platform and clean. We hope that this article has provided valuable insights into the current state of cd_on_quit
and has inspired developers to contribute to its improvement.
Future Work
There are several areas where we can improve cd_on_quit
further. One possible area of improvement is to make the --print-last-dir
option more compatible with the cd
command. Another possible area of improvement is to introduce new features that make it easier to switch to the last directory.
References
Acknowledgments
Q: What is cd_on_quit?
A: cd_on_quit
is a feature in Superfile that allows users to automatically switch to the last directory they were in when they quit the application.
Q: Why is cd_on_quit not working on my system?
A: There are several reasons why cd_on_quit
may not be working on your system. One possible reason is that the --print-last-dir
option is not compatible with the cd
command on your system. Another possible reason is that the underlying bubbletea
library is not working correctly.
Q: How can I make cd_on_quit more cross-platform?
A: There are several ways to make cd_on_quit
more cross-platform. One possible approach is to introduce new arguments in the spf path-list
command, as suggested by @lazysegtree. Another possible approach is to use a different approach to print the last directory, one that is compatible with the cd
command.
Q: Can I use cd_on_quit with other file managers?
A: Yes, you can use cd_on_quit
with other file managers. However, you may need to modify the --print-last-dir
option to work with the specific file manager you are using.
Q: How can I troubleshoot issues with cd_on_quit?
A: There are several ways to troubleshoot issues with cd_on_quit
. One possible approach is to check the output of the --print-last-dir
option to see if it is printing the correct directory. Another possible approach is to check the underlying bubbletea
library to see if it is working correctly.
Q: Can I customize the behavior of cd_on_quit?
A: Yes, you can customize the behavior of cd_on_quit
. One possible way to customize the behavior is to modify the --print-last-dir
option to print the last directory in a specific format. Another possible way to customize the behavior is to use a different approach to print the last directory.
Q: How can I contribute to the improvement of cd_on_quit?
A: There are several ways to contribute to the improvement of cd_on_quit
. One possible way to contribute is to report issues with cd_on_quit
and suggest possible solutions. Another possible way to contribute is to modify the --print-last-dir
option to work with specific file managers or to use a different approach to print the last directory.
Q: What is the current status of cd_on_quit?
A: The current status of cd_on_quit
is that it is a feature in Superfile that allows users to automatically switch to the last directory they were in when they quit the application. However, the feature is not yet fully cross-platform, and its implementation can be improved for better user experience.
Q: Who can I contact for more information about cd_on_quit?
A: You can contact the Superfile team for more information about cd_on_quit
. You can also contact the maintainers of the bubbletea
library for more information about its implementation.
Q: What are the future plans for cd_on_quit?
A: The future plans for cd_on_quit
include making it more cross-platform and improving its implementation for better user experience. The Superfile team is also considering introducing new features that make it easier to switch to the last directory.