Comments (4)
interesting idea. I have a few concerns about the idea which I want to share in case we can somehow address them:
- I would worry that many paths are relative paths and there would be no easy way to check that they exist or not, especially when piping stdin.
- Would it somehow be smart enough to ignore relative urls so there aren't a lot of false negatives? (i.e. most unix-like paths start with
/lib
,/home/
,/etc/
,/var/
that sort of thing, and could perhaps be "hardcoded"?) - Would it cater for Windows paths as well?
- It would have to be a post-processing step, which could slow
bat
down (running the regex patterns and checking whether the paths exist could be fairly expensive operations?) and complicate the codebase. (Likely, the slowness is mitigated by having it only execute when the command line argument is supplied, as it wouldn't be enabled by default.) - It could conflict with the syntax highlighting - I'm imagining JSON strings where
\t
represents a tab etc. which could be fun for Windows paths like.\tests\
...
from bat.
I would worry that many paths are relative paths and there would be no easy way to check that they exist or not
If a path is relative, shouldn't it be relative to the file then? In this case we can check for files relative to the given file and check if those paths exist or not
especially when piping stdin.
Do you mean something like: cat /folder/test.txt | bat
(bad example, but you get the idea :D) - hmmm, in this case this wouldn't be easy. Maybe we just start with absolute paths or only highlighting existing paths, or disable paths at all for piped stdin
Would it somehow be smart enough to ignore relative urls so there aren't a lot of false negatives? (i.e. most unix-like paths start with /lib, /home/, /etc/ , /var/ that sort of thing, and could perhaps be "hardcoded"?)
I'm very against hardcoding (especially since the reason why I initially opened this feature request was that I wanted my /media
folders to be checked :D). This is another point that would speak for only highlighting existing paths
Would it cater for Windows paths as well?
I don't really use Windows myself, but I know that Windows' path just differ from starting with something like C:
or D:
and using the escape character instead of the backslash - building an regex for that would be as trivial as building one for unix.
It would have to be a post-processing step, which could slow bat down (running the regex patterns and checking whether the paths exist could be fairly expensive operations?)
I haven't looked into the codebase yet, so you know more about I do here :D However, if we just parse the currently visible paged content, that will make stuff faster. Also, regarding:
I'm imagining JSON strings where \t represents a tab etc
to avoid this we simply cache the files existence, this way the tab character will only be checked once.
It could conflict with the syntax highlighting
why?
which could be fun for Windows paths like .\tests...
I don't quite get your point here - could you elaborate?
So based on this, I'd propose we only check for existing paths for the first iteration. Also always check relatively to the file. When some content is passed through stdin, let's just check relative to cwd.
What do you think about this?
from bat.
I'm imagining JSON strings where \t represents a tab etc
to avoid this we simply cache the files existence, this way the tab character will only be checked once.
It could conflict with the syntax highlighting
why?
which could be fun for Windows paths like .\tests...
I don't quite get your point here - could you elaborate?
imagine some JSON like:
{
"test": ".\test"
}
it might at first glance look like a relative Windows path, but the \t
will initially be correctly syntax highlighted as a character escape. So further highlighting it as a path would presumably override that and - if it is meant to be a valid path, make the mistake harder to spot because the literal path .\test
could exist. And having special logic depending on the type of file, the position of the path (inside a string etc where different escaping rules apply) in the file sounds like a can of worms I don't want to open ;)
from bat.
{
"test": ".\test"
}
Wouldn't you use:
{
"test": ".\\test"
}
instead?
I think those cases are quite rare and most of the time we will be able to detect them correctly.
I'll take a look at the code when I got some free time and will then open a PR. I think this feature would be much more helpful than it could harm, especially since it will be opt-in.
from bat.
Related Issues (20)
- Option to omit binary content even when writing to a file
- Syntax request: RDF 🐢 Turtle & SPARQL (*.ttl, *.ttls, etc.)
- compatibility issue with cat while piping in scripts
- Gherkin support
- Add option to ship vendored libgit2 dependency
- Please support .debdiff files HOT 13
- Support for alternative theme file format(s) HOT 2
- Allow --line-range to count from the back of the file to act similar to "tail" HOT 1
- Bat can't find the theme, even though it's present HOT 6
- Should TOML-mapping-implemented file extension globs look like standard supported extensions? HOT 1
- Theme Preview just prints theme name
- Control C exits with return 130 HOT 3
- How to enable Solarized (light) theme HOT 2
- Theme resets on closing / new window HOT 2
- JSON Syntax is not highlighted in JSONC files HOT 1
- bat - Apple Silicon Support HOT 1
- Update README to include GNOME/GTK version of Dark Mode macOS alias. PR:#2963 HOT 1
- Using `batcat --pager "less -R" </path_to_file>` doesen't convert ANSI characters in Kali
- Syntax Request: Astro HOT 3
- Maybe patch the newest lisp syntaxes? 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 bat.