]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/blob - README.md
Use pygmentize and highlight as fallback markdown renderers (#69)
[xdg-ninja.git] / README.md
1 <div>
2 <h1 align="center">xdg-ninja</h1>
3 <h5 align="center">Because you wouldn't let just anyone into your <i>$HOME</i></h5>
4 </div>
5
6 A shell script which checks your _$HOME_ for unwanted files and directories.
7
8 <p align="center">
9 <img src="https://s8.gifyu.com/images/Peek-2022-05-13-16-07.gif" width="500"/>
10 </p>
11
12 When it encounters a file it knows about, it will tell you whether it's possible to move this file to an appropriate location, and how to do it.
13
14 The configurations are from the [arch wiki page on XDG_BASE_DIR](https://wiki.archlinux.org/title/XDG_Base_Directory), [antidot](https://github.com/doron-cohen/antidot) (thanks to Scr0nch for writing a conversion tool), and contributed by other users.
15
16 ## Running
17
18 Clone the repository somewhere, then run the _./xdg-ninja.sh_ script.
19
20 This will run every test in the default configuration.
21
22 ## Dependencies
23
24 - your favorite POSIX-compliant shell ([bash](https://repology.org/project/bash/packages), [zsh](https://repology.org/project/zsh/packages), [dash](https://repology.org/project/dash-shell/packages), ...)
25 - [jq](https://repology.org/project/jq/packages) for parsing the json files
26
27 ### Optional
28
29 - [glow](https://repology.org/project/glow/packages) for rendering markdown in the terminal ([bat](https://repology.org/project/bat-cat/packages), [pygmentize](https://repology.org/project/pygments/versions) or [highlight](https://repology.org/project/highlight/packages) can be used as fallback, but glow's output is clearer and therefore glow is recommended)
30 - [cabal](https://repology.org/project/cabal/packages) for compiling the helper program for creating configurations
31
32 ## Configuration
33
34 The configuration is done in the _programs/_ directory.
35
36 You define a program, and then a list of files and directories which this program ruthlessly puts into your _$HOME_ directory.
37
38 For each file/directory, you specify if it can be (re)moved.
39
40 If this is the case, you also specify instructions on how to accomplish this in markdown.
41
42 Files in this directory can have any name, but using the name of the program is encouraged.
43
44 ### Automatically Generating Configuration
45
46 You need _haskell_ and _cabal_ installed. (To be clear, this is just for a tool that will help you automatically generate the config files, you still only need your shell to run the tests)
47
48 Run the following command:
49 ```sh
50 cabal run xdgnj add
51 ```
52
53 ### Manually
54
55 We're going to use _git_ as an example.
56
57 It puts the file _.gitconfig_ into _$HOME.
58
59 Luckily, the XDG spec is supported by git, so we can simply move the file to _XDG_CONFIG_HOME/git/config_.
60
61 We can use that last sentence as our instructions. In this case, there are no newlines, so escaping this string for use in json is trivial, however, this is how you should generally approach it:
62 ```sh
63 echo "Luckily, the XDG spec is supported by git, so we can simply move the file to _XDG_CONFIG_HOME/git/config_." | jq -aRs .
64 ```
65
66 Let's see what the output of this command looks like for something a little more sophisticated.
67 Here's an example file:
68 ```sh
69 cat example.md
70 ```
71 ```
72 Currently not fixable.
73
74 _(But you can probably just delete the dir)_
75 ```
76 Here's what catting this file to the _jq_ command produces:
77 ```sh
78 cat example.md | jq -aRs .
79 ```
80 ```
81 "Currently not fixable.\n\n_(But you can probably just delete the dir)_\n"
82 ```
83
84 Now, we can assemble our final json file:
85 ```json
86 {
87 "name": "git",
88 "files": [
89 {
90 "path": "$HOME/.gitconfig",
91 "movable": true,
92 "help": "Luckily, the XDG spec is supported by git, so we can simply move the file to _XDG_CONFIG_HOME/git/config_.\n"
93 }
94 ]
95 }
96 ```
97
98 Saving this as _git.json_ in the _programs/_ directory will result in the script picking it up and checking the file.
99
100 If you've created a configuration for a file that isn't in the offical repository yet, make sure to create a pull request so that other people can benefit from it as well.