Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fralau/xmlshow
Settle for LESS: a fast and super-simple XML viewer for command-line
https://github.com/fralau/xmlshow
bash-script large-files syntax-highlighting unix-command viewer xml
Last synced: 23 days ago
JSON representation
Settle for LESS: a fast and super-simple XML viewer for command-line
- Host: GitHub
- URL: https://github.com/fralau/xmlshow
- Owner: fralau
- License: mit
- Created: 2018-03-14T15:14:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T08:25:42.000Z (over 6 years ago)
- Last Synced: 2024-10-04T13:35:26.500Z (about 1 month ago)
- Topics: bash-script, large-files, syntax-highlighting, unix-command, viewer, xml
- Language: Shell
- Homepage:
- Size: 472 KB
- Stars: 18
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xmlshow: A super-simple and powerful viewer for large XML files, for the command-line
## Introduction
Ever found yourself with an XML file just too large for your editor or your browser, and did you (like me) spent your time trying to find a simple solution on the Web? This one may be for you.
And if it isn't, you may have found enough material to create your own, just with standard utilities.
### Features
xmlshow is a super-simple XML viewer for the Unix command line, which should provide most everything you could wish,
since uses the features of [less](https://ss64.com/bash/less.html).- It will display any **large** XML file in a breeze.
- It has syntax highlighting
- If it is a zip file, it will unzip it in the process (zipping is *both* indispensable and effective,
since XML is wonderfully redundant).
- It has line numbering
- You can navigate forward and backward
- You can use sed search patterns.### Limitations
There are two things, however, that it won't do:
- Modifying the file
- Prepare or serve coffee### Usage
Just type:$ xmlshow
It will also read from stdin if no argument is provided. Hence if some utility outputs some well-form XML on stdout, you can pipe it into xml show:
$ some-utility | xmlshow
## How it works
It combines:- unzip, to extract the file
- file to check the mime type of the input file
- [xmllint](http://xmlsoft.org/xmllint.html), for beautifying the XML.
- highlight to highlight the syntax
- [less](https://ss64.com/bash/less.html) to view the file and add the line numbers.
The script does it for you, but this is the substance:
xmllint --format | highlight --syntax=xml --out-format=xterm-256 | less -R -N
(the `-R` parameter in `less` is for raw (i.e. to preserve the escape codes for colors), and `-N` is for numbering)
That's all there is to it: it's just a typical shell hack with Unix pipes, sufficiently long to warrant a script file, and sufficiently useful to be put on github.## How to install it
1. Download the .sh file an install it some directory in your path (type `echo $PATH`to find out).
2. Make it executable: `chmod +x xmlshow.sh`
2. In that same directory, create a soft link: `ln -s xmlshow.sh xmlshow`
3. If it fails, make sure that utilities mentioned above (typically xmllint and highlight) are installed on your system. If not use your favorite package manager
- On Debian, `apt get install`
- On MacOs, `brew install` is your friend (see [instructions to install brew](https://brew.sh/))*Voilà*, you should be all set.
## Tips### Navigating the file
The [less](https://ss64.com/bash/less.html) utility has actually quite a few tricks up its sleeves.Beside the usual commands, remember that:
- `z`jumps one window forward
- `w`jumps one window backward
- **`h` calls a help, with plenty of good features you may not have suspected (use q to quit)**
- To search for a pattern just type `/pattern`### Viewing more text
It is also worth remembering that it is often easy to display more text at once, either by getting a smaller font on your terminal pane (on MacOS: `CMD -`, `CMD 0` to get to normal), or by increasing the size of the window or pane!### Consulting the XML content of a docx document
Since you can use xmlshow in a pipe, you can do something like this:unzip -p myfile.docx word/document.xml | xmlshow
It tells unzip to decompress the document.xml file and to send it to stdout, ready to be piped into xmlshow.