repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

bootstripper code clean up

29404d934ca9512437fe745ba050899305099c7f

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Changed files (6)

bootstripper.java

Modified
1 1 import java.nio.file.*;
2 2 import java.io.*;
3 -import java.util.*;
5 -class bootstripper{
6 - public static void main(String[] arguments) throws Exception {
7 - if(arguments.length == 0){
4 +import static java.text.MessageFormat.format;
6 +class bootstripper {
7 + public static void main(String[] arguments) throws Throwable {
8 + var dorkfile_path_input = ".";
9 + if (arguments.length == 1) {
10 + dorkfile_path_input = arguments[0];
11 + } else if (arguments.length > 1){
8 12 usage();
9 - fail();
13 + throw fail();
11 - var dorkfiles_root = Path.of(arguments[0]).toRealPath();
12 - System.out.printf("Assuming dorkfiles root repo in %s.%n", emphasize_local(dorkfiles_root.toString()));
15 + var dorkfiles_root = Path.of(dorkfile_path_input).toRealPath();
16 + log("Assuming dorkfiles root repo in {0}.", emphasize_local(dorkfiles_root.toString()));
13 17 decrypt_secrets(dorkfiles_root.resolve("tresor"));
14 18 var hostname = hostname();
15 - System.out.printf("Hostname: %s%n", emphasize_global(hostname));
19 + log("Hostname: {0}", emphasize_global(hostname));
16 20 var symlinks_file = hostname + ".symlinks";
17 21 create_symlinks(dorkfiles_root, dorkfiles_root.resolve(symlinks_file));
20 - static void decrypt_secrets(Path secrets_root) throws Exception {
21 - System.out.printf("%s:Decrypting files in %s folder.%n", emphasize_global("TODO"), emphasize_local(secrets_root.getFileName().toString()));
24 + static void decrypt_secrets(Path secrets_root) throws Throwable {
25 + log("{0}:Decrypting files in {1} folder.", emphasize_global("TODO"),
26 + emphasize_local(secrets_root.getFileName().toString()));
24 - static void create_symlinks(Path root, Path symlinks_file) throws Exception {
25 - System.out.printf("Creating symlinks as defined in %s file.%n", emphasize_local(symlinks_file.getFileName().toString()));
29 + static void create_symlinks(Path root, Path symlinks_file) throws Throwable {
30 + log("Creating symlinks as defined in {0} file.",
31 + emphasize_local(symlinks_file.getFileName().toString()));
26 32 var lines = Files.readAllLines(symlinks_file);
27 33 String source = null;
28 34 String target = null;
29 - for(String line : lines){
30 - if(line.isBlank()) continue;
31 - if (source == null) source = line;
32 - else if (target == null) target = line;
33 - if(source != null && target != null){
35 + for (String line : lines) {
36 + if (line.isBlank())
37 + continue;
38 + if (source == null)
39 + source = line;
40 + else
41 + target = line;
42 + if (target != null) {
34 43 link(root, source, target);
35 44 source = null;
36 45 target = null;
41 - static void link(Path root, String source, String target) throws Exception {
50 + static void link(Path root, String source, String target) throws Throwable {
42 51 var home = System.getProperty("user.home");
43 52 var source_path = root.resolve(source).toAbsolutePath();
44 53 var target_path = Path.of(target.replace("~", home)).toAbsolutePath();
45 54 var is_directory = Files.isDirectory(source_path);
46 - if(Files.exists(target_path, LinkOption.NOFOLLOW_LINKS)){
47 - if(Files.exists(target_path)) {
48 - System.out.printf("%n✅ %s already exists!%nNot linking %s.%n", emphasize_global(target_path.toString()), emphasize_local(source_path.toString()));
55 + if (Files.exists(target_path, LinkOption.NOFOLLOW_LINKS)) {
56 + if (Files.exists(target_path)) {
57 + log("\n✓ {0} already exists!\nNot linking {1}.", emphasize_global(target_path.toString()),
58 + emphasize_local(source_path.toString()));
49 59 return;
50 - }
51 - else {
52 - System.out.printf("%n❌ %s exists, but it points into nirvana. Removing broken link!%n", target_path.toString());
60 + } else {
61 + log("\n❌ {0} exists, but it points into nirvana. Removing broken link!", target_path.toString());
53 62 Files.delete(target_path);
56 - System.out.printf("%n🔗 %s ➔ %s.%n", emphasize_local(source_path.toString()), emphasize_local(target_path.toString()));
65 + log("\n🔗 {0} ➔ {1}.", emphasize_local(source_path.toString()),
66 + emphasize_local(target_path.toString()));
57 67 Files.createDirectories(target_path.getParent());
58 - try{
68 + try {
59 69 Files.createSymbolicLink(target_path, source_path);
60 - }
61 - catch (Exception __) {
70 + } catch (Exception __) {
63 - * Creating symbolic links on Windows only recently became possible without admin rights.
64 - * However, most tools (including JDK) have not yet adapted to this change and still require admin rights.
65 - * Until that is fixed, we escape to a system tool that is known to behave correcty in this regard.
72 + * Creating symbolic links on Windows only recently became possible without
73 + * admin rights.
74 + * However, most tools (including JDK) have not yet adapted to this change and
75 + * still require admin rights.
76 + * Until that is fixed, we escape to a system tool that is known to behave
77 + * correcty in this regard.
67 79 var operating_system = System.getProperty("os.name");
68 - if(operating_system.toLowerCase().contains("win")){
80 + if (operating_system.toLowerCase().contains("win")) {
69 81 var process = new ProcessBuilder();
70 82 var command = process.command();
71 83 command.add("cmd.exe");
72 84 command.add("/c");
73 85 command.add("mklink");
74 - if(is_directory){
86 + if (is_directory) {
75 87 command.add("/d");
77 89 command.add(target_path.toString());
78 90 command.add(source_path.toString());
79 91 process.inheritIO()
80 - .start()
81 - .onExit()
82 - .join();
83 - }
84 - else {
92 + .start()
93 + .onExit()
94 + .join();
95 + } else {
85 96 __.printStackTrace();
86 - fail("Could not create symbolic link!");
97 + throw fail("Could not create symbolic link!");
93 104 Process process;
95 106 process = process_builder
96 - .start()
97 - .onExit()
98 - .join();
99 - }
100 - catch( IOException __ ) {
107 + .start()
108 + .onExit()
109 + .join();
110 + } catch (IOException __) {
101 111 process = new ProcessBuilder()
102 - .command("hostnamectl", "hostname")
103 - .start()
104 - .onExit()
105 - .join();
112 + .command("hostnamectl", "hostname")
113 + .start()
114 + .onExit()
115 + .join();
107 - try(var reader = new InputStreamReader(process.getInputStream()))
108 - {
117 + try (var reader = new InputStreamReader(process.getInputStream())) {
109 118 int character = -1;
110 119 var output = new StringBuilder();
111 - while((character = reader.read()) != -1){
112 - if(character == '\n' || character == '\r') continue;
113 - output.append((char)character);
120 + while ((character = reader.read()) != -1) {
121 + if (character == '\n' || character == '\r')
122 + continue;
123 + output.append((char) character);
115 125 return output.toString();
119 129 static void usage() {
120 - System.out.printf("Bootstraps bugabingas %s.%n", emphasize_local("dorkfiles"));
121 - System.out.printf("%s: java bootstripper.java <dotfiles root path>%n", emphasize_global("Usage"));
122 - }
124 - static void exit() {
125 - System.exit(0);
130 + log("Bootstraps bugabingas {0}.", emphasize_local("dorkfiles"));
131 + log("{0}: java bootstripper.java [dotfiles root path]", emphasize_global("Usage"));
128 134 static String emphasize_global(String message) {
133 139 return "\033[3m" + message + "\033[0m";
136 - static void fail(String message, Object... arguments) {
137 - System.out.printf(message, arguments);
138 - System.exit(-1);
142 + static Throwable fail(String message, Object... arguments) {
143 + log(message, arguments);
144 + return fail();
141 - static void fail() {
147 + static Throwable fail() {
142 148 System.exit(-1);
149 + return new Throwable("use 'throw fail()' for control flow");
152 + static void log(String message, Object... arguments) {
153 + System.out.println(format(message, arguments));

nushell/tools/cargo_tools.nu

Deleted
deleted file mode 100644
1 -let cargo_crates = [
2 - "sd"
3 - "fd-find"
4 - "ripgrep"
5 - "eva"
6 - "watchexec-cli"
7 - "mdcat"
8 - "hexyl"
9 - "hyperfine"
10 - "so"
11 - "tealdeer"
12 - "tokei"
13 - "bottom"
14 - "bat"
15 - "pastel"
16 - "diskonaut"
17 - "menyoki"
18 - "rpick"
19 - "grex"
20 - "xh"
21 - "comrak"
22 - "bandwhich"
23 - "linky"
24 - "viu"
25 - "licensor"
26 - "gib"
27 - "silicon"
28 -]
30 -let cargo_git_crates = [
31 - "https://github.com/mosmeh/indexa"
32 -]
34 -def install_hx [] {
35 - cd $env.WORKSPACE
36 - git clone https://github.com/helix-editor/helix
37 - cd helix
38 - cargo install --path helix-term
39 - hx --grammar fetch
40 - hx --grammar build
41 -}
43 -export def install[] {
44 - cargo install --locked $cargo_crates
45 - cargo install --locked nu --all-features
46 - $cargo_git_crates | each {|it| cargo install --locked --git $it }
47 - install_hx
48 -}

tools/cargo_tools.nu

Added
new file mode 100644
1 +let cargo_crates = [
2 + "sd"
3 + "fd-find"
4 + "ripgrep"
5 + "eva"
6 + "watchexec-cli"
7 + "mdcat"
8 + "hexyl"
9 + "hyperfine"
10 + "so"
11 + "tealdeer"
12 + "tokei"
13 + "bottom"
14 + "bat"
15 + "pastel"
16 + "diskonaut"
17 + "menyoki"
18 + "rpick"
19 + "grex"
20 + "xh"
21 + "comrak"
22 + "bandwhich"
23 + "linky"
24 + "viu"
25 + "licensor"
26 + "gib"
27 + "silicon"
30 +let cargo_git_crates = [
31 + "https://github.com/mosmeh/indexa"
34 +def install_hx [] {
35 + cd $env.WORKSPACE
36 + git clone https://github.com/helix-editor/helix
37 + cd helix
38 + cargo install --path helix-term
39 + hx --grammar fetch
40 + hx --grammar build
43 +export def install[] {
44 + cargo install --locked $cargo_crates
45 + cargo install --locked nu --all-features
46 + $cargo_git_crates | each {|it| cargo install --locked --git $it }
47 + install_hx

tools/pipi.pass

Deleted
deleted file mode 100644
1 -dein arsch stinkt nach märchenfleisch

tools/test_aes.nu

Deleted
deleted file mode 100644
1 -rm -f aes.java.enc
2 -rm -f aes.java.dec
3 -java aes.java en --password-file pipi.pass aes.java aes.java.enc
4 -java aes.java de --password-file pipi.pass aes.java.enc aes.java.dec
6 -delta aes.java aes.java.dec

wezterm/wezterm.lua

Modified
1 1 local wez = require'wezterm'
2 2 return {
3 - font = wez.font'BlexMono Nerd Font',
3 + font = wez.font'JetBrainsMono Nerd Font',
4 4 font_size = 11.0,
5 5 color_scheme = 'nord',
6 6 default_prog = {'nu'},