Comments (13)
@dumblob We can implement --
convention to handle filenames starting with -
.
from lf.
I could use this for my implementation of bookmarks for example. But since it relies on another feature request, we shouldn't speculate too much about how it would work.
from lf.
Silly me, I just realized os.Args
and flag.Args
are different things and I don't have to rewrite flag parsing from stratch, sweet. This should now work as intended including the --
convention for directories startings with -
. Sorry everyone for the long delay.
from lf.
I think this is not possible with the standard flag package so we may need to iterate arguments manually which is not difficult either. In the meantime, you can simulate that functionality with something like lf () { [ -n "$1" ] && cd "$1"; lf }
in your shell configuration file or by adding a similar line to lf.sh.
from lf.
@lenormf did you mean passing the dir/file flag as the last argument or as the first argument? I'd prefer the last argument.
Anyway, it would be nice to have it behave as follows. If the argument is a directory or a symbolic link to a directory, lf
would switch to it and focus the first line, done. But if the argument is a file or a symbolic link to a file, lf
would first switch to the directory where the file/symbolic_link_to_a_file is (i.e. do cd "$(dirname "$argument")"
) and then focus the file/symbolic_link_to_a_file itself (i.e. focus the result of basename "$argument"
).
lf () { [ -n "$1" ] && cd "$1"; lf }
... lf.sh
Both leave the current shell environment polluted - in the first case the current directory stays changed even after lf
exits (disregarding whether correctly or by crashing) and in the second, there is the tmp
variable (disregarding whether the function is interrupted or not).
A safer solution taking into account these objections could be something like lf() (a="$1"; [ -d "$a" ] || a="$(dirname "$a")"; { if [ -d "$a" ]; then cd "$a"; else true; fi; } && exec lf)
from lf.
@dumblob Those are just examples. If you don't want to change the directory after you quit then your solution might work better for you. For tmp
variable, I think you might be able to prefix it with local
if you're using bash.
Flags are already prefixed with -
and the other optional argument should point to the directory if any so I think we can implement this as a position invariant way.
from lf.
so I think we can implement this as a position invariant way.
Hm, and what about a file called e.g. -server
? Or did I misunderstood something?
from lf.
@dumblob I don't think you misunderstood anything. It is just that somehow every issue you're involved with converges to more or less the same issue. I wonder do you have a file named -server
somewhere?
from lf.
It is just that somehow every issue you're involved with converges to more or less the same issue.
Please accept my greatest apologies. It's not my intention. It's just that working on the core of RHEL (the base system, different packages, etc. - nearly everything critical), on real-time UNIX-based SCADA systems for power plants (yes, there were lots of different files and operations with them and file naming was crucial), etc. gave me a lesson.
I wonder do you have a file named
-server
somewhere?
I ran find "$HOME" -name '-server'
and it returned 0 results. But find "$HOME" -name '*-server'
returned 16 results (that's even beyond my expectation) and find "$HOME" -name '*-server*'
137 results. It's way too easy to create such a file by moving, cutting, or just mentioning the file with an unwanted space in the middle creating a -server
file.
But from now on, I'll stop with file names fuss unless someone explicitly asks me.
from lf.
One more thought - how about just exposing completely all lf
arguments (or at least all such lf
arguments which are unknown to lf
) through lf -remote 'args'
returning a \0
-separated list of them (\0
can be used on POSIX systems if lf
implements lf -cmd read0 my_var
proposed in #47 (comment) ). And leaving everything else up to the user who can then write her own handling of them - e.g. cd
to the directory given as the first argument after --
.
from lf.
@dumblob What is the use case for that?
from lf.
Exactly as @lenormf said. I myself would use it to cd
to it if it's a directory and to cd
to the dirname
of it if it's not a directory. A second use-case of mine would be to leverage the filetype handling I've written inside of lfrc
(lf
would be a mime opener for anything - I know it's against the separation of concerns, but for me it's useful thanks to its portability across POSIX systems).
from lf.
This works now @lenormf I guess we could close this.
from lf.
Related Issues (20)
- Return to startup directory HOT 3
- sixel image preview not working with script but outputs multiple lines of characters when quitting lf HOT 2
- On Windows with pwsh, external trash command doesn't work with $Env:fx variable HOT 7
- on-redraw not being called on terminal resize HOT 3
- Bug: Tags broken on windows
- Problem with disown command HOT 7
- Feature Request: sepparate glob option for filter command HOT 1
- [BUG] When move failed with "permission denied" copy/cut buffer clearing. HOT 1
- setlocal depth/glob specification
- Dircount in previous pane not updated
- Bug: lf crashes when shell command is run in config file HOT 5
- Set shell interpreter seems not working for integrations HOT 4
- Video thumbnail previews with chafa HOT 5
- "set period 1" causes flickering in sixel image previews HOT 2
- Stopped working on Android HOT 2
- r33 changelog (preview) HOT 1
- r32 prints `^[[I` or `I` in libvte-based terminals HOT 5
- Setting a custom "root" directory HOT 1
- Alternate paste workflow (select then move/copy) doesnt work with multiple instances HOT 8
- Hidden file patterns for windows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lf.