mbornet-hl / hl Goto Github PK
View Code? Open in Web Editor NEWHighlight (colorize) text data using regular expressions (efficient C program)
License: Other
Highlight (colorize) text data using regular expressions (efficient C program)
License: Other
The source does not compile on macOS. Errors attached in the log file here.
Compiling it on macOS 13.2.1 on a M2 MacBook
However, as suggested by j16sdiz I was able to compile on macOS by
removing the #define _POSIX_C_SOURCE
from cr_main.c ...
Now, The utility works but it does not have any of the included configurations:
Running hl -H
returns:
...........
...........
-P : display configuration(s) matching regexp
-x : display options count for each config (with -vH options)
Configurations :
Could you please update the code so that it compiles on macOS?
Many thanks...
Or is it that I am using the configurations incorrectly?
Are these compiled into the hl binary file itself or do I need to place the hl_bin folder in a specific location to get the configurations to work?
Every time I launch tools/hl/bin/1.62/amd/debian/7.8/hl, a file called "gmon.out" is generated in the current directory.
Please provide binaries which are NOT compiled with profiling enabled (i.e. without the -pg compile flag, iirc)
You can add a parameter file hl.hlrc with functions (in replacement of the specfic tree in the PATH.
For exemple the command netstat
netstat(){
if [ $# -gt 0 ]
then
param=$*
else
param=" "
fi
exec=which netstat
$exec $param | hl --netstat
}
Remove #define _POSIX_C_SOURCE
from CR_main.c fix the compilation on macOS
I'm starting to become more than a basic hl user and the config I have in mind is to highlight what is different from the line above. The idea is to compare from delimiter to delimiter a line with the line above it, and when a diff is detected, that "cell" is colored as well as the rest of the line, even if later cells are the same as previous. Here's an example I mocked up in an RTF editor:
This looks very useful. Do you plan to port it to OSX?
I use khard to search and edit my vcard contacts.
The main issue was that it was designed for the console, so I wrote a config for hl and a function to call it with khard.
For a simple listing, there is no issue:
But a more useful command in khard is show
to get details for one contact, it filters the list with options or by asking the user to provide an index number manually:
When khard show
is piped to hl the user prompt Enter Index (0 for None, q to quit):
is not visible before user input.
After the user input, there is an issue with the escaping sequence and the prompt appears on the first line of the output, with the name of the contact.
This kind of command (khard show) is probably not designed to be piped so I don't want to open an issue with khard at first.
Is there a way to solved that on hl side?
~/.config/khard/khard.conf
[addressbooks]
[[principal]]
path = ~/.contacts/fake/
[general]
debug = no
default_action = list
editor = vim, -i, NONE
merge_editor = vimdiff
[contact table]
display = first_name
group_by_addressbook = no
reverse = no
show_nicknames = yes
show_uids = yes
sort = last_name
localize_dates = yes
preferred_phone_number_type = pref, cell, home
preferred_email_address_type = pref, work, home
[vcard]
private_objects = Telegram, Matrix, XMPP, Tox
preferred_version = 4.0
search_in_source_files = yes
skip_unparsable = yes
~/.contacts/fake/Jane_Doe.vcf
BEGIN:VCARD
UID:02446dd0-6eb1-4d54-a9d5-387af78d0a6d
VERSION:4.0
PRODID:-//BBros.us llc//bvCard.com//EN
N:Doe;Jane;;;
FN:Jane Doe
EMAIL:[email protected]
ORG:Google
TEL:123-123-123
URL;type=pref:http://google.com
ADR:;;;;;;France
END:VCARD
~/.contacts/fake/John_Doe.vcf
BEGIN:VCARD
UID:bf675293-0b61-47ac-ad4a-4966bd7aacff
VERSION:3.0
PRODID:-//BBros.us llc//bvCard.com//EN
N:Doe;John;;;
FN:John Doe
EMAIL;TYPE=home:[email protected]
NOTE:Fake ID
ORG:Microsoft
TEL;TYPE=cell:+33600000000
URL;type=pref:http://microsoft.com
ADR:;;;;;;France
END:VCARD
khard :
-e
-3w '^[ ]{4}?[a-zA-Z][a-zA-Z -]{1,12}:'
-3g '^Address book: (.*)$'
-3y '^Index.*$'
-1y '^[0-9]+'
-2c 'Nickname:'
-1w '[ ]{4}([a-zA-Z]+:)'
-3r ': (\+?\(?[0-9]{1,3}\)?[0-9 -]{8,13}[0-9])'
-3b '([^ ]+)@[^ ]+\.[^ ]+'
-2b '[^ ]+(@[^ ]+\.[^ ]+)'
Hi,
I have an issue with the compilation process. After clone the repo, and go to /src and made "make" there is a kind of references problem. I saw the code but I did not find any problem. So I don't know what its going wrong.
I have this message in my terminal
cc -c -o cr_main.o cr_main.c
cc -c -o cr_gpri.o cr_gpri.c
lex -t cr_lex.l > cr_lex.c
cc -c -o cr_lex.o cr_lex.c
cr_main.o: In function cr_add_regexp': cr_main.c:(.text+0x125f): undefined reference to
cr_clear_marker_flags'
cr_main.o: In function main': cr_main.c:(.text+0x1401): undefined reference to
cr_clear_marker_flags'
cr_main.o: In function cr_disp_line': cr_main.c:(.text+0x2c1d): undefined reference to
cr_same_colors'
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'hl' failed
make: *** [hl] Error 1
rm cr_lex.c
Thanks..
hi, i know it is useful, but i really don't know how to begin, can you give a simple tutor step by step。thank you。
How is this supposed to work?
$ cd /d/more/src/tools/hl/hl_bin
$ export PATH=$PWD:$PATH
$ df
/d/more/src/tools/hl/hl_bin/df: line 48: hl: command not found
$ which hl
/d/more/src/tools/hl/hl_bin/hl
The hl script does:
PATH="$(echo "$PATH" | sed "s|^$dirname:||;s|:$dirname:|:|g")"
export PATH
hl/hl_bin/man colorizes the output of man, but loses the use of a pager. So the full man page gets printed out, while standard man would use a pager like less
to make it possible to read it page by page, go up, etc.
Of course one can work around it by piping hl_bin/man to less, but it would be more convenient if the use of hl was fully transparent.
In fact, this appears to fix it:
--- i/hl_bin/man
+++ w/hl_bin/man
@@ -45,8 +45,9 @@ if [ "$USE_HL" = "no" ]; then
else
# Default behaviour : colorization
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- hl -u --"$progname" < "$ERR" & hl --"$progname" < "$OUT" & \
- "$progname" "$@" > "$OUT" 2> "$ERR"
+ hl -u --"$progname" < "$ERR" &
+ ( hl --"$progname" < "$OUT" | less ) &
+ "$progname" "$@" > "$OUT" 2> "$ERR"
rc=$?
I'm not sure why the original syntax is a & b & c when the & means "detach", not "and". So it would be equivalent and more readable to do this on three lines anyway.
I guess my patch needs to be improved to not hardcode less and instead do like man does:
$MANPAGER, defaulting to $PAGER, defaulting to ... no idea, more, I guess?
In my case $PAGER is less.
I would like to include hl in aliases to provide an output like color=auto in some binutils which lack colors.
But, it needs to detect that the output is in a pipe or not in a terminal and disable the coloration.
Manualy, I do it like that:
hlauto () {
if [ -t 1 ]; then
hl $1
else
cat -
fi
}
alias df='df -Tha --total | hlauto --df'
It works great. The new alias df
ouput in color, but df | less
output without hl.
Would it be easy to include this feature in hl? Maybe like this?
alias df='df -Tha --total | color=auto hl --df'
Hello,
i really like your hl tool, but the parameter seams to be given in a definded order: e.g. works
ls | ./hl -2 -b Make
cr_cpri.h
cr_epri.h
...
but switching b and 2 does not work.
ls | ./hl -b -2 ak
./hl: missing argument for "-b" !
ARGS :
opts = "hHuVvEr:g:y:b:m:c:w:R:G:Y:B:M:C:W:n:DLdei1234%.:"
optarg = "(null)"
curr_ptrs = 0x21f1040
PTRS :
curr_arg = "-b"
curr_idx = 2
next_arg = "(null)"
prev = (nil)
config = (nil)
I would also suggest to add a default color so hl directly works without parameters.
best regards, Johannes
This seems like a nifty tool but it is a bit difficult to get started.
Please add a section that documents how to install it.
If it is included in some Linux distro, please link to it. I did not find any hl
package at https://packages.ubuntu.com/search?suite=groovy&searchon=names&keywords=hl as an example.
Also, please tell visitors in the intro how this tool differs from other similar tools, such as https://github.com/cornet/ccze.
When using the predefined configs, I get:
sami@pad:~ $ hl -V
hl: version 1.93
sami@pad:~ $ hl --du
input in flex scanner failed
sami@pad:~ $ hl --log_d
input in flex scanner failed
sami@pad:~ $ cat /var/log/auth.log | hl --log
input in flex scanner failed
sami@pad:~ $
Version number is visible above.
I'm on Ubuntu 20.04. Feel free to ask if you need to know other package versions. I am eager to help!
cp config_files/hl /etc/default
But, the config_files/hl
file does not exist, there are several hl_*.cfg
files in that folder. So we assume that there is an error in the writing.
sudo cp -R config_files/ /etc/default/hl/
df -h | hl --df
hl: cr_read_config_file() : "/etc/default/hl" is not a regular file !
sudo cp -R config_files/ /etc/default/hl/
export HL_CONF=/etc/default/hl
I think that maybe the default location is badly encoded in the source.
And I have one more weird issue at this point:
/etc/default/hl
existshl: cr_read_config_file() : "/etc/default/hl" is not a regular file!
) every time I open a new bash session in, even though I don't run hl to my knowledge.Hi, I use supercat for doing the highlighting: http://supercat.nosredna.net/
It is also written in C (& uses regcomp) etc.
Have you compared your tool against it, and if so, what are the benefits? (if any)
Knowing this will be helpful for people (who don't know much C) but want to decide which tool to use.
Thanks!
What is the hl_bin/hl
. It makes my system (Ubuntu 16.04) break. I think it calls it forever... maybe hl binary should be renamed to hl_prog (or something) while this script should be the real hl. What you think?
Would you consider creating a homebrew package for this utility?
This would then make this great utility a lot more accessible to macOS users
Thanks...
I used this command:
git clone http://github.com/mbornet-hl/hl
but when I want to use it in my command, I see this error message:
df -h | hl --df
-bash: hl: command not found
Hi, thanks for your great tool!
I am having some errors compiling on Ubuntu server. Hope you can have a look:
OS version
uname -a
Linux 4.15.0-109-generic #110-Ubuntu SMP Tue Jun 23 02:39:32 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
I have installed flex package version 2.6.4
lex -V
flex 2.6.4
But I get the following errors when running make:
make[1]: Entering directory '/usr/src/hl/src'
cr_main.o: In function `cr_read_config_file':
cr_main.c:(.text+0x182): undefined reference to `yyin'
cr_main.c:(.text+0x189): undefined reference to `yyin'
cr_main.c:(.text+0x1e2): undefined reference to `yylex'
collect2: error: ld returned 1 exit status
Makefile:18: recipe for target 'hl' failed
make[1]: *** [hl] Error 1
make[1]: Leaving directory '/usr/src/hl/src'
Makefile:6: recipe for target 'hl' failed
make: *** [hl] Error 2
Thanks
hl can be used on aix.
you must add a line in the makefile
CC=gxlc
and in the cr_cpri.h can you add the
before
and
before
the include file getopt.h don't exist on the aix but you can copy it from linux and it work
Please provide a toplevel Makefile which recurses to the src dir, a "make install" rule which copies hl into PREFIX/bin, and copies the default config file into a default location where it will be picked up. It could also suggest to add hl/hl_bin to the PATH by adding one line to .bashrc or .zshrc. This would make it easier to get started with hl.
# hl -V
hl: version 1.107
# hl -H
input in flex scanner failed
# hl/hl_bin/cal
input in flex scanner failed
input in flex scanner failed
# lsb_release -d
Description: Ubuntu 21.04
# dpkg -l flex
ii flex 2.6.4-8 amd64 fast lexical analyzer generator
# dpkg -l bison
ii bison 2:3.7.5+dfsg-1 amd64 YACC-compatible parser generator
Hi, can you help me with the setup?
I am trying some of your commands like, but I am having input in flex scanner failed
error.
$> df -h | hl --df
input in flex scanner failed
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.