diff options
author | David Peter <mail@david-peter.de> | 2022-05-29 22:51:10 +0200 |
---|---|---|
committer | David Peter <mail@david-peter.de> | 2022-05-29 22:51:10 +0200 |
commit | aa35cb52c47ef143ed2564dbc9f15d625fef4c7c (patch) | |
tree | 37bbc34f02593ea9fd75d2d8cc68da6049d5bd2b | |
parent | 446b9181e6c27b65e057397884fa64ffbbb572cf (diff) |
Add exemplary hexyl pluginbat-plugins
-rw-r--r-- | plugins/hexyl.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/hexyl.lua b/plugins/hexyl.lua new file mode 100644 index 00000000..b98ad285 --- /dev/null +++ b/plugins/hexyl.lua @@ -0,0 +1,21 @@ +-- Note: this plugin depends on the existence of 'inspect' [1] and 'hexyl' [2] +-- +-- [1] https://github.com/sharkdp/content_inspector +-- [2] https://github.com/sharkdp/hexyl + +function is_binary(path) + local stream = assert(io.popen("inspect '" .. path .. "'")) + local output = stream:read('*all') + stream:close() + return string.find(output, ": binary\n") +end + +function preprocess(path) + if is_binary(path) then + tmpfile = os.tmpname() + os.execute("hexyl --length 1024 --no-position --border=none --no-squeezing '" .. path .. "' > '" .. tmpfile .. "'") + return tmpfile + else + return path + end +end |