https://github.com/sukibaby/reversefirtree
Sorts a list of variables into reverse fir tree (reverse XMAS tree / reverse Christmas tree) formatting. Written in PowerShell.
https://github.com/sukibaby/reversefirtree
c-plus-plus formatter formatting helper-script helper-tool kernel-development powershell-script reverse-christmas-tree reverse-fir-tree reverse-xmas-tree reversefirtree reversexmastree xmas-tree
Last synced: about 2 months ago
JSON representation
Sorts a list of variables into reverse fir tree (reverse XMAS tree / reverse Christmas tree) formatting. Written in PowerShell.
- Host: GitHub
- URL: https://github.com/sukibaby/reversefirtree
- Owner: sukibaby
- License: mit
- Created: 2025-06-19T13:59:45.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-06-19T14:53:55.000Z (12 months ago)
- Last Synced: 2025-06-19T15:26:16.641Z (12 months ago)
- Topics: c-plus-plus, formatter, formatting, helper-script, helper-tool, kernel-development, powershell-script, reverse-christmas-tree, reverse-fir-tree, reverse-xmas-tree, reversefirtree, reversexmastree, xmas-tree
- Language: PowerShell
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/sukibaby/ReverseFirTree/actions/workflows/powershell.yml)
I didn't find any tool to easily format a list of variables as reverse fir tree (a.k.a. reverse christmas tree, reverse XMAS tree), so I threw together a little PowerShell script. :-)
Running this script on a text file named `input.txt` with the following contents:
```
int samplebits = 16;
unsigned int last_cursor_pos = 0;
int preferred_writeahead = 8192;
WAVEHDR pcm = nullptr;
bool bInit = false;
array1 = {};
int32_t sample_rate_thing_ = 44100;
float myCooolFloat = 16;
array2 ={} ;
```
will provide a nicely formatted output file `input_formatted.txt` with the following contents:
```
int32_t sample_rate_thing_ = 44100;
unsigned int last_cursor_pos = 0;
int preferred_writeahead = 8192;
float myCooolFloat = 16;
WAVEHDR pcm = nullptr;
int samplebits = 16;
bool bInit = false;
array1 = {};
array2 = {};
```
It is capable of tie-breaking for commonly known C++ datatypes, and falls back on alphabetical sorting.
It uses PowerShell features which were introdued in PowerShell 3.0, so it should run as-is on the PowerShell that ships with Windows 8 and higher. Windows 7 users may need to upgrade first though.
Reverse fir tree styling is not very well documented, but is recommended in Kernel Maintainers [KVM 5.4.2 "Coding Style"](https://docs.kernel.org/process/maintainer-kvm-x86.html).
I would welcome any suggestions on ways the sorting mechanism could be further refined.