repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Merge branch 'trunk' of github.com:bugabinga/dotfiles into trunk

4c9230aebed64fbdc7358d48bc46fd391c7ead87

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (17)

justfile

Modified
16 16 java bootstripper.java decrypt
18 18 # install rust user land
19 -tools:
19 +crates:
20 20 cd tools;java install.java
22 +# install packages
23 +packages:
24 + cd tools;nu packages.nu
22 26 # typically the initial git remote for the dotfiles repo is https
23 27 # this command changes the remote to ssh
24 28 ssh-remote:

neovim/lua/bugabinga/file_explorer.lua

Modified
4 4 local puk = require 'std.puk'
5 5 local map = require 'std.map'
6 6 local icon = require 'std.icon'
8 8 local oil = puk 'oil'
10 +-- Declare a global function to retrieve the current directory
11 +function _G.get_oil_winbar()
12 + local dir = require("oil").get_current_dir()
13 + if dir then
14 + return vim.fn.fnamemodify(dir, ":~")
15 + else
16 + -- If there is no current directory (e.g. over ssh), just show the buffer name
17 + return vim.api.nvim_buf_get_name(0)
18 + end
19 +end
10 21 oil.setup {
11 - -- default_file_explorer = true,
22 + default_file_explorer = true,
12 23 -- Set to true to watch the filesystem for changes and reload oil
13 - -- experimental_watch_for_changes = true,
24 + watch_for_changes = true,
14 25 skip_confirm_for_simple_edits = true,
15 26 prompt_save_on_select_new_entry = false,
16 27 delete_to_trash = true,
15 26 columns = { 'icon' },
16 27 win_options = {
17 28 cursorline = true,
29 + -- show CWD in winbar. needs global function, see above
30 + winbar = "%!v:lua.get_oil_winbar()",
19 32 keymaps = {
20 33 ['q'] = 'actions.close',
22 35 ['<C-s>'] = 'actions.select_split',
23 36 ['`'] = 'actions.tcd',
24 37 ['~'] = '<cmd>edit $HOME<CR>',
25 - ['<F7>'] = 'actions.open_terminal',
26 - ['gd'] = {
27 - desc = 'Toggle detail view',
28 - callback = function()
29 - local oil = require 'oil'
30 - local config = require 'oil.config'
31 - if #config.columns == 1 then
32 - oil.set_columns { 'icon', 'permissions', 'size', { 'mtime', format = '%d/%m/%y %T' } }
33 - else
34 - oil.set_columns { 'icon' }
35 - end
36 - end,
37 - },
39 39 float = {
40 40 max_width = 69,
42 42 border = vim.g.border_style,
43 43 padding = 2,
45 + -- Configuration for the floating action confirmation window
46 + confirmation = {
47 + border = vim.g.border_style,
48 + },
49 + -- Configuration for the floating progress window
50 + progress = {
51 + border = vim.g.border_style,
52 + },
53 + -- Configuration for the floating SSH window
54 + ssh = {
55 + border = vim.g.border_style,
56 + },
45 57 -- Configuration for the floating keymaps help window
46 58 keymaps_help = {
47 59 border = vim.g.border_style,
49 61 view_options = {
50 - is_always_hidden = function(name, bufnr) return name == '..' end,
62 + is_always_hidden = function(name) return name == '..' end,
51 63 show_hidden = true,

neovim/lua/bugabinga/key_preview.lua

Modified
40 40 { mode = 'n', keys = '<Leader>l', desc = '+LSP' },
41 41 { mode = 'n', keys = '<Leader>lp', desc = '+Peek' },
42 42 { mode = 'n', keys = '<Leader>r', desc = '+Rules' },
43 + { mode = 'n', keys = '<Leader>f', desc = '+Find' },
44 + { mode = 'n', keys = '<Leader>x', desc = '+Neovim' },
43 45 clue.gen_clues.builtin_completion(),
44 46 clue.gen_clues.g(),
45 47 clue.gen_clues.marks(),

neovim/lua/std/ignored.lua

Modified
8 8 'ivy',
9 9 'lazy',
10 10 'notify',
11 + 'Glance',
11 12 'nvim-docs-view',
12 13 'oil',
13 14 'qf',

neovim/lua/std/puk.lua

Modified
1 -local load_pack = function ( plugin_name )
2 - vim.validate( 'plugin_name', plugin_name, 'string' )
3 - vim.cmd.packadd { plugin_name, bang = true }
4 - return require( plugin_name )
1 +local load_pack = function(plugin_name, load_plugin)
2 + vim.validate('plugin_name', plugin_name, 'string')
3 + vim.cmd.packadd { plugin_name, bang = not load_plugin }
4 + return require(plugin_name)
7 7 return setmetatable(
9 - defer = function ( plugin_name )
10 - return vim.schedule_wrap(function ( f )
11 - f( load_pack( plugin_name ) )
9 + defer = function(plugin_name)
10 + return vim.schedule_wrap(function(f)
11 + f(load_pack(plugin_name, true))
12 12 end)
13 - end ,
13 + end,
16 - __call = function ( _, plugin_name )
17 - return load_pack( plugin_name )
16 + __call = function(_, plugin_name)
17 + return load_pack(plugin_name, false)
18 18 end,

neovim/puk.plugins.nuon

Modified
67 67 --release
70 - [
71 - ivy,
72 - github,
73 - "AdeAttwood/ivy.nvim",
74 - "0.x",
75 - "cfa7e29ae4d955508d4f7f2ef08cc0c51ee745ed",
76 - [
77 - cargo,
78 - build,
79 - --release
80 - ]
81 - ],
83 71 nvim-surround,
84 72 github,

tools/aes.java

Modified
1 -import static java.lang.System.out;
2 -import static java.nio.file.StandardOpenOption.CREATE_NEW;
3 -import static java.nio.file.StandardOpenOption.READ;
4 -import static java.nio.file.StandardOpenOption.WRITE;
6 -import java.nio.file.*;
7 -import java.nio.charset.*;
8 -import java.nio.*;
9 -import java.io.*;
11 -import java.security.*;
13 -import javax.crypto.*;
14 -import javax.crypto.spec.*;
16 -class aes {
17 - enum Command {
18 - ENCRYPT, DECRYPT
19 - }
21 - static Cipher AES_GCM_PKCS5;
22 - static byte[] SALT = new byte[] { 116, 104, 101, 32, 109, 111, 111, 110, 32, 105, 115, 32, 104, 105, 100, 100, 101,
23 - 110, 32, 105, 110, 32, 112, 108, 97, 105, 110, 32, 118, 105, 101, 119 };
24 - static SecureRandom RANDOM = new SecureRandom();
25 - /*
26 - * 12 ist NIST recommendation. supposedly fast and secure enough...
27 - */
28 - static int GCM_IV_SIZE = 12;
29 - /*
30 - * AES encrypts 128-blocks internally, so this should be reasonable memory bufer
31 - * size.
32 - */
33 - static int READ_BUFFER_SIZE = 128;
34 - /*
35 - * Supported sizes for GCM authentication tags seem to be {128, 120, 112, 104,
36 - * 96}.
37 - * But we do not really care, since we do not use them here.
38 - */
39 - static int GCM_AUTH_TAG_SIZE = 96;
41 - public static void main(String[] arguments) throws Throwable {
42 - if (arguments.length == 0) {
43 - usage();
44 - throw fail();
45 - }
47 - var input_command = arguments[0];
48 - Command command;
49 - if ("encrypt".startsWith(input_command)) {
50 - command = Command.ENCRYPT;
51 - } else if ("decrypt".startsWith(input_command)) {
52 - command = Command.DECRYPT;
53 - } else {
54 - throw fail("unknown command %s given%n", emphasize_global(input_command));
55 - }
57 - AES_GCM_PKCS5 = Cipher.getInstance("AES/GCM/NoPadding");
59 - var console = System.console();
60 - /*
61 - * If there is no console, this program is most likely part of a pipe.
62 - * In such cases a `--password-file` flag is mandatory, because we cannot
63 - * interactively ask for the password.
64 - */
65 - if (console == null) {
66 - if (arguments.length != 3 || !"--password-file".equals(arguments[1])) {
67 - usage();
68 - throw fail(
69 - "When running %s non-interactively, the %s flag is required.%nOtherwise there is no way to securely obtain the password.%n",
70 - emphasize_local("aes"), emphasize_global("--password-file"));
71 - }
72 - var password_file = Path.of(arguments[2]);
73 - if (!Files.exists(password_file)) {
74 - throw fail("the given password file %s does not exist%n", emphasize_local(password_file.toString()));
75 - }
76 - var password = toChars(Files.readAllBytes(password_file));
77 - switch (command) {
78 - case ENCRYPT:
79 - encrypt(password, System.in, System.out);
80 - break;
81 - case DECRYPT:
82 - decrypt(password, System.in, System.out);
83 - break;
84 - }
85 - } else {
86 - if (arguments.length <= 1) {
87 - usage();
88 - throw fail("not enough arguments given%n");
89 - }
90 - char[] password;
91 - String input;
92 - String output;
93 - if ("--password-file".equals(arguments[1])) {
94 - if (arguments.length != 5) {
95 - usage();
96 - throw fail("the flag %s requires a path%n", emphasize_local("--password-file"));
97 - }
98 - var password_file = Path.of(arguments[2]);
99 - if (!Files.exists(password_file)) {
100 - throw fail("the given password file %s does not exist%n", emphasize_local(password_file.toString()));
101 - }
102 - password = toChars(Files.readAllBytes(password_file));
103 - input = arguments[3];
104 - output = arguments[4];
105 - } else {
106 - if (arguments.length != 3) {
107 - usage();
108 - throw fail("when encrypting/decrypting a file, an output path is required%n");
109 - }
110 - password = console.readPassword("[%s]:", emphasize_global("Password"));
111 - input = arguments[1];
112 - output = arguments[2];
113 - }
115 - var input_path = Path.of(input);
116 - if (!Files.exists(input_path)) {
117 - throw fail("the given input path %s does not exist%n", emphasize_global(input_path.toString()));
118 - }
119 - var output_path = Path.of(output);
120 - if (Files.exists(output_path)) {
121 - throw fail("the output path %s already exists%n", emphasize_global(output_path.toString()));
122 - }
124 - try (var input_stream = Files.newInputStream(input_path, READ);
125 - var output_stream = Files.newOutputStream(output_path, CREATE_NEW, WRITE);) {
126 - switch (command) {
127 - case ENCRYPT:
128 - encrypt(password, input_stream, output_stream);
129 - break;
130 - case DECRYPT:
131 - decrypt(password, input_stream, output_stream);
132 - break;
133 - }
134 - }
135 - }
136 - throw exit();
137 - }
139 - static void encrypt(char[] password, InputStream input, OutputStream output) throws Exception {
140 - // FIXME: generate random salt and append it here just like IV
141 - // in GCM the IV should be unique per encrypted thingy
142 - var initialization_vector = new byte[GCM_IV_SIZE];
143 - RANDOM.nextBytes(initialization_vector);
144 - // save the IV for the decryption step later. secure? nope. but how else are we
145 - // to share IVs between encryption/decryption?
146 - output.write(initialization_vector);
147 - var secret = toSecretKey(password);
148 - var parameter_spec = new GCMParameterSpec(GCM_AUTH_TAG_SIZE, initialization_vector);
150 - AES_GCM_PKCS5.init(Cipher.ENCRYPT_MODE, secret, parameter_spec);
151 - var read_buffer = new byte[READ_BUFFER_SIZE];
152 - var aes_buffer = new byte[READ_BUFFER_SIZE];
153 - int read_bytes_count = 0;
154 - while ((read_bytes_count = input.read(read_buffer)) != -1) {
155 - var aes_bytes_count = AES_GCM_PKCS5.update(read_buffer, 0, read_bytes_count, aes_buffer);
156 - output.write(aes_buffer, 0, aes_bytes_count);
157 - }
158 - output.write(AES_GCM_PKCS5.doFinal());
159 - }
161 - static void decrypt(char[] password, InputStream input, OutputStream output) throws Exception {
162 - // the IV get prepended to the data during encryption
163 - var initialization_vector = new byte[GCM_IV_SIZE];
164 - input.read(initialization_vector);
165 - var parameter_spec = new GCMParameterSpec(GCM_AUTH_TAG_SIZE, initialization_vector);
166 - var secret = toSecretKey(password);
168 - AES_GCM_PKCS5.init(Cipher.DECRYPT_MODE, secret, parameter_spec);
169 - var read_buffer = new byte[READ_BUFFER_SIZE];
170 - var aes_buffer = new byte[READ_BUFFER_SIZE];
171 - int read_bytes_count = 0;
172 - while ((read_bytes_count = input.read(read_buffer)) != -1) {
173 - var aes_bytes_count = AES_GCM_PKCS5.update(read_buffer, 0, read_bytes_count, aes_buffer);
174 - output.write(aes_buffer, 0, aes_bytes_count);
175 - }
176 - // the java impl of GCM seems to buffer the whole data in memory and only
177 - // releasing it on doFinal. yuck!
178 - // there is not much i can do about this other than to wait for JDK patches.
179 - // TODO: in the case of AES GCM the final byte block is the authentication tag.
180 - // as such it should porbably NOT be written to the output file.
181 - // or is this assumption wrong?
182 - output.write(AES_GCM_PKCS5.doFinal());
183 - // FIXME: when given a wrong password we get a nonsensical error. make this
184 - // nicer for human
185 - }
187 - static SecretKey toSecretKey(char[] password) throws Exception {
188 - var factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
189 - var spec = new PBEKeySpec(password, SALT, 65536, 256);
190 - return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES");
191 - }
193 - static char[] toChars(byte[] bytes) {
194 - var byte_buffer = ByteBuffer.wrap(bytes);
195 - var char_buffer = StandardCharsets.UTF_8.decode(byte_buffer);
196 - return char_buffer.array();
197 - }
199 - static void usage() {
200 - out.printf("%s encrypts/decrypts data.%n", emphasize_local("Symmetrically "));
201 - out.printf("%s: java aes.java <e(ncrypt)|d(ecrypt)> [--password-file <path>] <input path> <output path>%n",
202 - emphasize_global("Usage for files"));
203 - out.printf("%s: java aes.java <e(ncrypt)|d(ecrypt)> --password-file <path>%n",
204 - emphasize_global("Usage for stdin/stdout"));
205 - }
207 - static Throwable exit() {
208 - System.exit(0);
209 - // abuse control flow to make compiler realize `exit` will never return
210 - return new Throwable();
211 - }
213 - static String emphasize_global(String message) {
214 - return "\033[4m" + message + "\033[0m";
215 - }
217 - static String emphasize_local(String message) {
218 - return "\033[3m" + message + "\033[0m";
219 - }
221 - static Throwable fail(String message, Object... arguments) {
222 - out.printf(message, arguments);
223 - System.exit(-1);
224 - // abuse control flow to make compiler realize `fail` will never return
225 - return new Throwable();
226 - }
228 - static Throwable fail() {
229 - System.exit(-1);
230 - // abuse control flow to make compiler realize `fail` will never return
231 - return new Throwable();
232 - }
1 +import static java.lang.System.out;
2 +import static java.nio.file.StandardOpenOption.CREATE_NEW;
3 +import static java.nio.file.StandardOpenOption.READ;
4 +import static java.nio.file.StandardOpenOption.WRITE;
6 +import java.nio.file.*;
7 +import java.nio.charset.*;
8 +import java.nio.*;
9 +import java.io.*;
11 +import java.security.*;
13 +import javax.crypto.*;
14 +import javax.crypto.spec.*;
16 +class aes {
17 + enum Command {
18 + ENCRYPT, DECRYPT
19 + }
21 + static Cipher AES_GCM_PKCS5;
22 + static byte[] SALT = new byte[] { 116, 104, 101, 32, 109, 111, 111, 110, 32, 105, 115, 32, 104, 105, 100, 100, 101,
23 + 110, 32, 105, 110, 32, 112, 108, 97, 105, 110, 32, 118, 105, 101, 119 };
24 + static SecureRandom RANDOM = new SecureRandom();
25 + /*
26 + * 12 ist NIST recommendation. supposedly fast and secure enough...
27 + */
28 + static int GCM_IV_SIZE = 12;
29 + /*
30 + * AES encrypts 128-blocks internally, so this should be reasonable memory bufer
31 + * size.
32 + */
33 + static int READ_BUFFER_SIZE = 128;
34 + /*
35 + * Supported sizes for GCM authentication tags seem to be {128, 120, 112, 104,
36 + * 96}.
37 + * But we do not really care, since we do not use them here.
38 + */
39 + static int GCM_AUTH_TAG_SIZE = 96;
41 + public static void main(String[] arguments) throws Throwable {
42 + if (arguments.length == 0) {
43 + usage();
44 + throw fail();
45 + }
47 + var input_command = arguments[0];
48 + Command command;
49 + if ("encrypt".startsWith(input_command)) {
50 + command = Command.ENCRYPT;
51 + } else if ("decrypt".startsWith(input_command)) {
52 + command = Command.DECRYPT;
53 + } else {
54 + throw fail("unknown command %s given%n", emphasize_global(input_command));
55 + }
57 + AES_GCM_PKCS5 = Cipher.getInstance("AES/GCM/NoPadding");
59 + var console = System.console();
60 + /*
61 + * If there is no console, this program is most likely part of a pipe.
62 + * In such cases a `--password-file` flag is mandatory, because we cannot
63 + * interactively ask for the password.
64 + */
65 + if (console == null) {
66 + if (arguments.length != 3 || !"--password-file".equals(arguments[1])) {
67 + usage();
68 + throw fail(
69 + "When running %s non-interactively, the %s flag is required.%nOtherwise there is no way to securely obtain the password.%n",
70 + emphasize_local("aes"), emphasize_global("--password-file"));
71 + }
72 + var password_file = Path.of(arguments[2]);
73 + if (!Files.exists(password_file)) {
74 + throw fail("the given password file %s does not exist%n", emphasize_local(password_file.toString()));
75 + }
76 + var password = toChars(Files.readAllBytes(password_file));
77 + switch (command) {
78 + case ENCRYPT:
79 + encrypt(password, System.in, System.out);
80 + break;
81 + case DECRYPT:
82 + decrypt(password, System.in, System.out);
83 + break;
84 + }
85 + } else {
86 + if (arguments.length <= 1) {
87 + usage();
88 + throw fail("not enough arguments given%n");
89 + }
90 + char[] password;
91 + String input;
92 + String output;
93 + if ("--password-file".equals(arguments[1])) {
94 + if (arguments.length != 5) {
95 + usage();
96 + throw fail("the flag %s requires a path%n", emphasize_local("--password-file"));
97 + }
98 + var password_file = Path.of(arguments[2]);
99 + if (!Files.exists(password_file)) {
100 + throw fail("the given password file %s does not exist%n", emphasize_local(password_file.toString()));
102 + password = toChars(Files.readAllBytes(password_file));
103 + input = arguments[3];
104 + output = arguments[4];
105 + } else {
106 + if (arguments.length != 3) {
107 + usage();
108 + throw fail("when encrypting/decrypting a file, an output path is required%n");
110 + password = console.readPassword("[%s]:", emphasize_global("Password"));
111 + input = arguments[1];
112 + output = arguments[2];
115 + var input_path = Path.of(input);
116 + if (!Files.exists(input_path)) {
117 + throw fail("the given input path %s does not exist%n", emphasize_global(input_path.toString()));
119 + var output_path = Path.of(output);
120 + if (Files.exists(output_path)) {
121 + throw fail("the output path %s already exists%n", emphasize_global(output_path.toString()));
124 + try (var input_stream = Files.newInputStream(input_path, READ);
125 + var output_stream = Files.newOutputStream(output_path, CREATE_NEW, WRITE);) {
126 + switch (command) {
127 + case ENCRYPT:
128 + encrypt(password, input_stream, output_stream);
129 + break;
130 + case DECRYPT:
131 + decrypt(password, input_stream, output_stream);
132 + break;
136 + throw exit();
139 + static void encrypt(char[] password, InputStream input, OutputStream output) throws Exception {
140 + // FIXME: generate random salt and append it here just like IV
141 + // in GCM the IV should be unique per encrypted thingy
142 + var initialization_vector = new byte[GCM_IV_SIZE];
143 + RANDOM.nextBytes(initialization_vector);
144 + // save the IV for the decryption step later. secure? nope. but how else are we
145 + // to share IVs between encryption/decryption?
146 + output.write(initialization_vector);
147 + var secret = toSecretKey(password);
148 + var parameter_spec = new GCMParameterSpec(GCM_AUTH_TAG_SIZE, initialization_vector);
150 + AES_GCM_PKCS5.init(Cipher.ENCRYPT_MODE, secret, parameter_spec);
151 + var read_buffer = new byte[READ_BUFFER_SIZE];
152 + var aes_buffer = new byte[READ_BUFFER_SIZE];
153 + int read_bytes_count = 0;
154 + while ((read_bytes_count = input.read(read_buffer)) != -1) {
155 + var aes_bytes_count = AES_GCM_PKCS5.update(read_buffer, 0, read_bytes_count, aes_buffer);
156 + output.write(aes_buffer, 0, aes_bytes_count);
158 + output.write(AES_GCM_PKCS5.doFinal());
161 + static void decrypt(char[] password, InputStream input, OutputStream output) throws Exception {
162 + // the IV get prepended to the data during encryption
163 + var initialization_vector = new byte[GCM_IV_SIZE];
164 + input.read(initialization_vector);
165 + var parameter_spec = new GCMParameterSpec(GCM_AUTH_TAG_SIZE, initialization_vector);
166 + var secret = toSecretKey(password);
168 + AES_GCM_PKCS5.init(Cipher.DECRYPT_MODE, secret, parameter_spec);
169 + var read_buffer = new byte[READ_BUFFER_SIZE];
170 + var aes_buffer = new byte[READ_BUFFER_SIZE];
171 + int read_bytes_count = 0;
172 + while ((read_bytes_count = input.read(read_buffer)) != -1) {
173 + var aes_bytes_count = AES_GCM_PKCS5.update(read_buffer, 0, read_bytes_count, aes_buffer);
174 + output.write(aes_buffer, 0, aes_bytes_count);
176 + // the java impl of GCM seems to buffer the whole data in memory and only
177 + // releasing it on doFinal. yuck!
178 + // there is not much i can do about this other than to wait for JDK patches.
179 + // TODO: in the case of AES GCM the final byte block is the authentication tag.
180 + // as such it should porbably NOT be written to the output file.
181 + // or is this assumption wrong?
182 + output.write(AES_GCM_PKCS5.doFinal());
183 + // FIXME: when given a wrong password we get a nonsensical error. make this
184 + // nicer for human
187 + static SecretKey toSecretKey(char[] password) throws Exception {
188 + var factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
189 + var spec = new PBEKeySpec(password, SALT, 65536, 256);
190 + return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES");
193 + static char[] toChars(byte[] bytes) {
194 + var byte_buffer = ByteBuffer.wrap(bytes);
195 + var char_buffer = StandardCharsets.UTF_8.decode(byte_buffer);
196 + return char_buffer.array();
199 + static void usage() {
200 + out.printf("%s encrypts/decrypts data.%n", emphasize_local("Symmetrically "));
201 + out.printf("%s: java aes.java <e(ncrypt)|d(ecrypt)> [--password-file <path>] <input path> <output path>%n",
202 + emphasize_global("Usage for files"));
203 + out.printf("%s: java aes.java <e(ncrypt)|d(ecrypt)> --password-file <path>%n",
204 + emphasize_global("Usage for stdin/stdout"));
207 + static Throwable exit() {
208 + System.exit(0);
209 + // abuse control flow to make compiler realize `exit` will never return
210 + return new Throwable();
213 + static String emphasize_global(String message) {
214 + return "\033[4m" + message + "\033[0m";
217 + static String emphasize_local(String message) {
218 + return "\033[3m" + message + "\033[0m";
221 + static Throwable fail(String message, Object... arguments) {
222 + out.printf(message, arguments);
223 + System.exit(-1);
224 + // abuse control flow to make compiler realize `fail` will never return
225 + return new Throwable();
228 + static Throwable fail() {
229 + System.exit(-1);
230 + // abuse control flow to make compiler realize `fail` will never return
231 + return new Throwable();

tools/crates.csv

Added
new file mode 100644
1 +name;bin;cargo_args
2 +asm-cli-rust; asm-cli-rust; --git https://github.com/cch123/asm-cli-rust
3 +bat
4 +bk
5 +bottom; btm
6 +cargo-cache
7 +cargo-update;cargo-install-update
8 +carl
9 +calendar-rs;calendar
10 +du-dust; dust
11 +dotenv-linter
12 +diskonaut
13 +eva
14 +emplace
15 +eza; eza; --features vendored-openssl,vendored-libgit2
16 +fend
17 +fd-find;fd
18 +git-delta;delta
19 +gitu;gitu; --locked
20 +gitoxide;gix
21 +hexyl
22 +hyperfine
23 +inlyne
24 +jj-cli; jj; --locked --bin jj
25 +just
26 +lms
27 +lurk-cli; lurk
28 +lychee;lychee; --locked --no-default-features --features rustls-tls,email-check
29 +macchina
30 +mdbook
31 +mdcat
32 +monolith
33 +names
34 +netscanner
35 +neovide;neovide; --git https://github.com/neovide/neovide
36 +nu;nu; --locked
37 +nu_plugin_audio_hook; nu_plugin_audio_hook; --git https://github.com/FMotalleb/nu_plugin_audio_hook.git --features all-decoders
38 +ouch
39 +pastel
40 +presenterm
41 +pueue;pueue;--locked
42 +ripgrep;rg
43 +rbw
44 +skim;sk
45 +sbyte
46 +sniffnet
47 +taplo-cli;taplo; --locked --features lsp
48 +tealdeer;tldr
49 +tokei
50 +topgrade
51 +tsdl
52 +ttyper
53 +unison-fsmonitor
54 +ugdb
55 +vivid
56 +wthrr
57 +yazi-cli;ya; --locked
58 +yazi-fm;yazi; --locked
59 +zoxide

tools/download_jar.java

Modified
1 -import static java.lang.System.out;
3 -import java.io.*;
4 -import java.net.*;
5 -import java.net.http.*;
6 -import java.net.http.HttpResponse.*;
7 -import java.nio.file.*;
8 -import java.util.*;
9 -import java.util.concurrent.ConcurrentSkipListSet;
11 -class download_jar {
12 - public static void main(final String[] command_line_arguments) {
13 - help();
14 - var current_working_directory = Paths.get(System.getProperty("user.dir"));
15 - var download_directory = current_working_directory.resolve("downloaded_artifacts");
16 - var maven_repository = "https://repo.maven.apache.org/maven2";
17 - var expected_count_of_arguments = 3;
18 - if (contains(command_line_arguments, "-d")) {
19 - expected_count_of_arguments = expected_count_of_arguments + 2;
20 - try {
21 - var given_download_directory = command_line_arguments[index_of(command_line_arguments, "-d") + 1];
22 - download_directory = current_working_directory.resolve(given_download_directory);
23 - } catch (IndexOutOfBoundsException exception) {
24 - out.println("The -d option requires an argument.");
25 - usage();
26 - fail();
27 - }
28 - }
29 - if (contains(command_line_arguments, "-r")) {
30 - expected_count_of_arguments = expected_count_of_arguments + 2;
31 - try {
32 - var given_maven_repository = command_line_arguments[index_of(command_line_arguments, "-r") + 1];
33 - maven_repository = given_maven_repository;
34 - } catch (IndexOutOfBoundsException exception) {
35 - out.println("The -r option requires an argument.");
36 - usage();
37 - fail();
38 - }
39 - }
40 - if (command_line_arguments.length != expected_count_of_arguments) {
41 - usage();
42 - fail();
43 - }
44 - var maven_coordinates_reversed = new String[3];
45 - for (var index = 2; index >= 0; --index) {
46 - maven_coordinates_reversed[index] = command_line_arguments[expected_count_of_arguments - index - 1];
47 - }
48 - var group_id = maven_coordinates_reversed[2];
49 - var artifact_id = maven_coordinates_reversed[1];
50 - var version = maven_coordinates_reversed[0];
52 - if (Files.exists(download_directory) && Files.isRegularFile(download_directory)) {
53 - fail("The given download directory path %s already points to a file!%n", download_directory.toString());
54 - } else if (!Files.exists(download_directory)) {
55 - out.printf("Creating directory at %s%n.", emphasize_global(download_directory.toString()));
56 - try {
57 - Files.createDirectories(download_directory);
58 - } catch (IOException __) {
59 - fail("Unable to create directory at %s", emphasize_global(download_directory.toString()));
60 - }
61 - }
63 - var expected_artifact_base_url = guess_maven_artifact_url(maven_repository, group_id, artifact_id, version);
64 - var client = HttpClient.newHttpClient();
65 - var request = HttpRequest.newBuilder().uri(URI.create(expected_artifact_base_url)).build();
66 - var target_directory = download_directory;
67 - client.sendAsync(request, BodyHandlers.ofString()).thenApply(HttpResponse::statusCode).thenAccept(status -> {
68 - if (status > 299) {
69 - fail("Could not find maven artifact at %s.%n", expected_artifact_base_url);
70 - } else {
71 - download_ressource(client, target_directory,
72 - build_ressource_url(expected_artifact_base_url, artifact_id, version, ".jar"));
73 - download_ressource(client, target_directory,
74 - build_ressource_url(expected_artifact_base_url, artifact_id, version, "-sources.jar"));
75 - // FIXME BLOCKER! How do we implement the version clash resolution?
76 - // Preferably in a manner that avoids pointless downloads...
77 - var processed_cache = new ConcurrentSkipListSet<String>();
78 - process_pom(client, processed_cache,
79 - build_ressource_url(expected_artifact_base_url, artifact_id, version, ".pom"));
80 - }
81 - }).join();
83 - out.printf("download directory:\t%s%nmaven repository:\t%s%nmaven coordinates:\t%s:%s:%s%n",
84 - emphasize_global(download_directory.toString()), emphasize_global(maven_repository), emphasize_global(group_id),
85 - emphasize_global(artifact_id), emphasize_global(version));
86 - exit();
87 - }
89 - static Collection<String> process_pom(HttpClient client, Set<String> processed, String pom_url) {
90 - if (processed.contains(pom_url))
91 - return Collections.emptyList();
92 - var request = HttpRequest.newBuilder().uri(URI.create(pom_url)).build();
93 - return client.sendAsync(request, BodyHandlers.ofInputStream()).thenApply(input -> {
94 - // TODO add pom to list of processed so that a pom only ever gets read once
95 - processed.add(pom_url);
96 - // TODO traverse path to root of poms and collect managed dependencies
97 - // TODO collect declared dependencies from given pom
98 - return List.<String>of();
99 - }).join();
100 - }
102 - static void download_ressource(HttpClient client, Path target_directory, String ressource_url) {
103 - var request = HttpRequest.newBuilder().uri(URI.create(ressource_url)).build();
104 - var ressource_name = ressource_url.substring(ressource_url.lastIndexOf('/') + 1);
105 - var target_ressource_path = target_directory.resolve(ressource_name);
106 - client.sendAsync(request, BodyHandlers.ofFile(target_ressource_path)).join();
107 - }
109 - static String build_ressource_url(String base, String artifact_id, String version, String suffix) {
110 - var url = new StringBuilder(base);
111 - if (!base.endsWith("/"))
112 - url.append('/');
113 - url.append(artifact_id);
114 - url.append('-');
115 - url.append(version);
116 - url.append(suffix);
117 - return url.toString();
118 - }
120 - static String guess_maven_artifact_url(String base, String group_id, String artifact_id, String version) {
121 - var url = new StringBuilder(base);
122 - if (!base.endsWith("/"))
123 - url.append('/');
124 - url.append(group_id.replaceAll("\\.", "\\/"));
125 - url.append('/');
126 - url.append(artifact_id);
127 - url.append('/');
128 - url.append(version);
129 - url.append('/');
130 - return url.toString();
131 - }
133 - static class Dependency {
134 - String artifactId;
135 - String groupId;
136 - String version;
137 - String scope;
138 - boolean optional;
139 - }
141 - static <T> int index_of(T[] array, T item) {
142 - var length = array.length;
143 - if (length == 0)
144 - return -1;
145 - for (var index = 0; index < length; ++index) {
146 - var element = array[index];
147 - if (Objects.equals(element, item))
148 - return index;
149 - }
150 - return -1;
151 - }
153 - @SafeVarargs
154 - static <T> boolean contains(T[] array, T... items) {
155 - if (array.length == 0)
156 - return false;
157 - if (items.length == 0)
158 - return false;
159 - for (var element : array) {
160 - for (var argument : items) {
161 - if (element.equals(argument))
162 - return true;
163 - }
164 - }
165 - return false;
166 - }
168 - static void help() {
169 - out.printf("Downloads an artifact from a %s repository with its %s.%n", emphasize_local("maven"),
170 - emphasize_local("transitive dependencies"));
171 - }
173 - static void usage() {
174 - out.printf("%s: java download_jar.java <group id> <artifact id> <version>%n", emphasize_global("Usage"));
175 - }
177 - static void exit() {
178 - out.printf("%s!%n", emphasize_local("Done"));
179 - System.exit(0);
180 - }
182 - static String emphasize_global(String message) {
183 - return "\033[4m" + message + "\033[0m";
184 - }
186 - static String emphasize_local(String message) {
187 - return "\033[3m" + message + "\033[0m";
188 - }
190 - static void fail(String message, Object... arguments) {
191 - out.printf(message, arguments);
192 - System.exit(-1);
193 - }
195 - static void fail() {
196 - System.exit(-1);
197 - }
1 +import static java.lang.System.out;
3 +import java.io.*;
4 +import java.net.*;
5 +import java.net.http.*;
6 +import java.net.http.HttpResponse.*;
7 +import java.nio.file.*;
8 +import java.util.*;
9 +import java.util.concurrent.ConcurrentSkipListSet;
11 +class download_jar {
12 + public static void main(final String[] command_line_arguments) {
13 + help();
14 + var current_working_directory = Paths.get(System.getProperty("user.dir"));
15 + var download_directory = current_working_directory.resolve("downloaded_artifacts");
16 + var maven_repository = "https://repo.maven.apache.org/maven2";
17 + var expected_count_of_arguments = 3;
18 + if (contains(command_line_arguments, "-d")) {
19 + expected_count_of_arguments = expected_count_of_arguments + 2;
20 + try {
21 + var given_download_directory = command_line_arguments[index_of(command_line_arguments, "-d") + 1];
22 + download_directory = current_working_directory.resolve(given_download_directory);
23 + } catch (IndexOutOfBoundsException exception) {
24 + out.println("The -d option requires an argument.");
25 + usage();
26 + fail();
27 + }
28 + }
29 + if (contains(command_line_arguments, "-r")) {
30 + expected_count_of_arguments = expected_count_of_arguments + 2;
31 + try {
32 + var given_maven_repository = command_line_arguments[index_of(command_line_arguments, "-r") + 1];
33 + maven_repository = given_maven_repository;
34 + } catch (IndexOutOfBoundsException exception) {
35 + out.println("The -r option requires an argument.");
36 + usage();
37 + fail();
38 + }
39 + }
40 + if (command_line_arguments.length != expected_count_of_arguments) {
41 + usage();
42 + fail();
43 + }
44 + var maven_coordinates_reversed = new String[3];
45 + for (var index = 2; index >= 0; --index) {
46 + maven_coordinates_reversed[index] = command_line_arguments[expected_count_of_arguments - index - 1];
47 + }
48 + var group_id = maven_coordinates_reversed[2];
49 + var artifact_id = maven_coordinates_reversed[1];
50 + var version = maven_coordinates_reversed[0];
52 + if (Files.exists(download_directory) && Files.isRegularFile(download_directory)) {
53 + fail("The given download directory path %s already points to a file!%n", download_directory.toString());
54 + } else if (!Files.exists(download_directory)) {
55 + out.printf("Creating directory at %s%n.", emphasize_global(download_directory.toString()));
56 + try {
57 + Files.createDirectories(download_directory);
58 + } catch (IOException __) {
59 + fail("Unable to create directory at %s", emphasize_global(download_directory.toString()));
60 + }
61 + }
63 + var expected_artifact_base_url = guess_maven_artifact_url(maven_repository, group_id, artifact_id, version);
64 + var client = HttpClient.newHttpClient();
65 + var request = HttpRequest.newBuilder().uri(URI.create(expected_artifact_base_url)).build();
66 + var target_directory = download_directory;
67 + client.sendAsync(request, BodyHandlers.ofString()).thenApply(HttpResponse::statusCode).thenAccept(status -> {
68 + if (status > 299) {
69 + fail("Could not find maven artifact at %s.%n", expected_artifact_base_url);
70 + } else {
71 + download_ressource(client, target_directory,
72 + build_ressource_url(expected_artifact_base_url, artifact_id, version, ".jar"));
73 + download_ressource(client, target_directory,
74 + build_ressource_url(expected_artifact_base_url, artifact_id, version, "-sources.jar"));
75 + // FIXME BLOCKER! How do we implement the version clash resolution?
76 + // Preferably in a manner that avoids pointless downloads...
77 + var processed_cache = new ConcurrentSkipListSet<String>();
78 + process_pom(client, processed_cache,
79 + build_ressource_url(expected_artifact_base_url, artifact_id, version, ".pom"));
80 + }
81 + }).join();
83 + out.printf("download directory:\t%s%nmaven repository:\t%s%nmaven coordinates:\t%s:%s:%s%n",
84 + emphasize_global(download_directory.toString()), emphasize_global(maven_repository), emphasize_global(group_id),
85 + emphasize_global(artifact_id), emphasize_global(version));
86 + exit();
87 + }
89 + static Collection<String> process_pom(HttpClient client, Set<String> processed, String pom_url) {
90 + if (processed.contains(pom_url))
91 + return Collections.emptyList();
92 + var request = HttpRequest.newBuilder().uri(URI.create(pom_url)).build();
93 + return client.sendAsync(request, BodyHandlers.ofInputStream()).thenApply(input -> {
94 + // TODO add pom to list of processed so that a pom only ever gets read once
95 + processed.add(pom_url);
96 + // TODO traverse path to root of poms and collect managed dependencies
97 + // TODO collect declared dependencies from given pom
98 + return List.<String>of();
99 + }).join();
102 + static void download_ressource(HttpClient client, Path target_directory, String ressource_url) {
103 + var request = HttpRequest.newBuilder().uri(URI.create(ressource_url)).build();
104 + var ressource_name = ressource_url.substring(ressource_url.lastIndexOf('/') + 1);
105 + var target_ressource_path = target_directory.resolve(ressource_name);
106 + client.sendAsync(request, BodyHandlers.ofFile(target_ressource_path)).join();
109 + static String build_ressource_url(String base, String artifact_id, String version, String suffix) {
110 + var url = new StringBuilder(base);
111 + if (!base.endsWith("/"))
112 + url.append('/');
113 + url.append(artifact_id);
114 + url.append('-');
115 + url.append(version);
116 + url.append(suffix);
117 + return url.toString();
120 + static String guess_maven_artifact_url(String base, String group_id, String artifact_id, String version) {
121 + var url = new StringBuilder(base);
122 + if (!base.endsWith("/"))
123 + url.append('/');
124 + url.append(group_id.replaceAll("\\.", "\\/"));
125 + url.append('/');
126 + url.append(artifact_id);
127 + url.append('/');
128 + url.append(version);
129 + url.append('/');
130 + return url.toString();
133 + static class Dependency {
134 + String artifactId;
135 + String groupId;
136 + String version;
137 + String scope;
138 + boolean optional;
141 + static <T> int index_of(T[] array, T item) {
142 + var length = array.length;
143 + if (length == 0)
144 + return -1;
145 + for (var index = 0; index < length; ++index) {
146 + var element = array[index];
147 + if (Objects.equals(element, item))
148 + return index;
150 + return -1;
153 + @SafeVarargs
154 + static <T> boolean contains(T[] array, T... items) {
155 + if (array.length == 0)
156 + return false;
157 + if (items.length == 0)
158 + return false;
159 + for (var element : array) {
160 + for (var argument : items) {
161 + if (element.equals(argument))
162 + return true;
165 + return false;
168 + static void help() {
169 + out.printf("Downloads an artifact from a %s repository with its %s.%n", emphasize_local("maven"),
170 + emphasize_local("transitive dependencies"));
173 + static void usage() {
174 + out.printf("%s: java download_jar.java <group id> <artifact id> <version>%n", emphasize_global("Usage"));
177 + static void exit() {
178 + out.printf("%s!%n", emphasize_local("Done"));
179 + System.exit(0);
182 + static String emphasize_global(String message) {
183 + return "\033[4m" + message + "\033[0m";
186 + static String emphasize_local(String message) {
187 + return "\033[3m" + message + "\033[0m";
190 + static void fail(String message, Object... arguments) {
191 + out.printf(message, arguments);
192 + System.exit(-1);
195 + static void fail() {
196 + System.exit(-1);

tools/git-info

Modified
1 -#!/bin/sh
2 -#
3 -# git-info - shows information about a Git repository a la `svn info'
4 -#
5 -# How to use:
6 -# $ git info
7 -# $ git info ~/src/somewhere/somefile
8 -# $ git info some/relative/file_or_directory
9 -# $ git info ~/repos/something.git
11 -# Copyright (c) 2009-2022 Akinori MUSHA
13 -# All rights reserved.
15 -# Redistribution and use in source and binary forms, with or without
16 -# modification, are permitted provided that the following conditions
17 -# are met:
18 -# 1. Redistributions of source code must retain the above copyright
19 -# notice, this list of conditions and the following disclaimer.
20 -# 2. Redistributions in binary form must reproduce the above copyright
21 -# notice, this list of conditions and the following disclaimer in the
22 -# documentation and/or other materials provided with the distribution.
24 -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 -# SUCH DAMAGE.
37 -COLOR=
39 -main () {
40 - local opt
41 - local OPTS_SPEC="\
42 -$0 [<options>] [<path>]
44 -$0 shows information about a Git repository.
45 ---
46 -h,help show the help
47 -color?when show colored output (always|never|auto)
49 - eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt --stuck-long -- "$@" || echo exit $?)"
51 - while [ $# -gt 0 ]; do
52 - opt="$1"
53 - shift
55 - case "$opt" in
56 - --color)
57 - COLOR=always
58 - ;;
59 - --color\=*)
60 - COLOR="${opt#*=}"
61 - ;;
62 - --)
63 - break
64 - ;;
65 - *)
66 - die "Unexpected option: $opt"
67 - ;;
68 - esac
69 - done
71 - initialize_colors
73 - case "$#" in
74 - 1)
75 - ;;
76 - 0)
77 - if [ -n "$GIT_DIR" ]; then
78 - set -- "$GIT_DIR"
79 - else
80 - set -- .
81 - fi
82 - ;;
83 - *)
84 - die "Too many arguments"
85 - ;;
86 - esac
88 - git_info "$1"
91 -initialize_colors () {
92 - if [ -z "$COLOR" ]; then
93 - if git config --get-colorbool color.info; then
94 - COLOR=always
95 - else
96 - COLOR=never
97 - fi
98 - fi
100 - case "$COLOR" in
101 - always|never)
102 - COLOR_BRANCH=$COLOR
103 - ;;
104 - auto)
105 - if git config --get-colorbool color.branch; then
106 - COLOR_BRANCH=always
107 - else
108 - COLOR_BRANCH=never
109 - fi
110 - ;;
111 - *)
112 - die "option \`color' expects \"always\", \"auto\", or \"never\""
113 - ;;
114 - esac
116 - if [ "$COLOR" = always ]; then
117 - REMOTE_COLOR="$(get_color color.info.remote color.branch.remote red)"
118 - LOCAL_COLOR="$(get_color color.info.local color.branch.local green)"
119 - PATH_COLOR="$(get_color color.info.path '' 'bold')"
120 - REPOSITORY_COLOR="$(get_color color.info.repository '' 'bold')"
121 - ID_COLOR="$(get_color color.info.id '' 'yellow')"
122 - RESET_COLOR=$(printf "\033[m")
123 - else
124 - REMOTE_COLOR=
125 - LOCAL_COLOR=
126 - PATH_COLOR=
127 - REPOSITORY_COLOR=
128 - ID_COLOR=
129 - RESET_COLOR=
130 - fi
133 -get_color () {
134 - local key1="$1" key2="$2" fb="$3"
135 - local color="$(git config --get-color "$key1" '')"
136 - case "$color" in
137 - ''|'')
138 - git config --get-color "$key2" "$fb"
139 - ;;
140 - *)
141 - printf '%s' "$color"
142 - ;;
143 - esac
146 -git_info () {
147 - local path="$1" dir relpath root git_dir
149 - if [ -d "$path" ]; then
150 - dir="$(cd -P "$path" && pwd)" || die "$path: Cannot cd to the directory"
151 - case "$path" in
152 - *.git)
153 - git_dir="$dir"
154 - ;;
155 - esac
156 - elif [ -f "$path" ]; then
157 - dir="$(dirname "$path")"
158 - dir="$(cd -P "$dir" && pwd)" || die "$dir: Cannot cd to the directory"
159 - relpath="$(basename "$path")"
160 - else
161 - die "$path: No such file or directory"
162 - fi
164 - if [ -n "$git_dir" ]; then
165 - dir=
166 - relpath=
167 - elif case "$dir" in ?*.git) [ -d "$dir/objects" -a -d "$dir/refs" ] ;; *) false ;; esac; then
168 - git_dir="$dir"
169 - relpath=
170 - else
171 - root="$(
172 - cd "$dir" || exit 1
173 - while [ ! -e .git ]; do
174 - [ "$(pwd)" = / ] && exit 1
175 - cd ..
176 - done
177 - pwd
178 - )" || die "Not a git repository."
179 - git_dir="$root/.git"
180 - if [ "$dir" = "$root" ]; then
181 - relpath=.
182 - elif [ -n "$relpath" ]; then
183 - relpath="${dir#"$root/"}/$relpath"
184 - else
185 - relpath="${dir#"$root/"}"
186 - fi
187 - fi
189 - set -- "$git_dir"
190 - if [ -n "$relpath" ]; then
191 - set -- "$@" "$relpath"
192 - fi
194 - do_git_info "$@"
197 -do_git_info () {
198 - local git_dir="$1" relpath="$2" root line field color reset
200 - shift
202 - echo "Repository Path: $PATH_COLOR$git_dir$RESET_COLOR"
204 - if [ $# -gt 0 ]; then
205 - root="$(dirname "$git_dir")"
206 - if [ "$relpath" = . ]; then
207 - echo "Path: $PATH_COLOR$root$RESET_COLOR"
208 - else
209 - echo "Path: $PATH_COLOR$root/$relpath$RESET_COLOR"
210 - fi
211 - fi
213 - maketemp
215 - GIT_DIR="$git_dir" git remote -v > "$TEMPFILE"
216 - if [ -s "$TEMPFILE" ]; then
217 - echo "Remote Repositories:"
218 - sed -e "s/^\([^ ]\{1,\}\)\([ ]\{1,\}\)\([^ ]\{1,\}\)/$REMOTE_COLOR\1$RESET_COLOR\2$REPOSITORY_COLOR\3$RESET_COLOR/" \
219 - -e 's/^/ /' \
220 - "$TEMPFILE"
221 - fi
223 - GIT_DIR="$git_dir" git branch -r --color=$COLOR_BRANCH > "$TEMPFILE"
224 - if [ -s "$TEMPFILE" ]; then
225 - echo "Remote Branches:"
226 - sed -e "s/\([ ]\{1,\}->[ ]\{1,\}\)\([^ ]\{1,\}\)/\1$REMOTE_COLOR\2$RESET_COLOR/" \
227 - -e 's/^ */ /' "$TEMPFILE"
228 - fi
230 - GIT_DIR="$git_dir" git branch --color=$COLOR_BRANCH > "$TEMPFILE"
231 - if [ -s "$TEMPFILE" ]; then
232 - echo "Local Branches:"
233 - sed 's/^/ /' "$TEMPFILE"
234 - fi
236 - echo "Repository Configuration:"
237 - GIT_DIR="$git_dir" git config --local --list | sort | {
238 - prev_section=
239 - prev_subsection=
240 - while read line; do
241 - case "$line" in
242 - (*=*)
243 - lhs=$(expr "$line" : '\([^=]\{1,\}\)')
244 - rhs=$(expr "$line" : '[^=]\{1,\}=\(.*\)')
245 - case "$lhs" in
246 - (?*.?*.?*)
247 - section=$(expr "$lhs" : '\([^.]\{1,\}\)')
248 - subsection=$(expr "$lhs" : '[^.]\{1,\}\.\(.\{1,\}\)\.')
249 - key=$(expr "$lhs" : '[^.]\{1,\}\..\{1,\}\.\([^.]\{0,\}\)$')
250 - if [ "$section" != "$prev_section" -o "$subsection" != "$prev_subsection" ]; then
251 - prev_section=$section
252 - prev_subsection=$subsection
253 - case "$section" in
254 - (remote)
255 - subsection=$REMOTE_COLOR$subsection$RESET_COLOR
256 - ;;
257 - (branch)
258 - subsection=$LOCAL_COLOR$subsection$RESET_COLOR
259 - esac
260 - printf "\t[%s \"%s\"]\n" "$section" "$subsection"
261 - fi
262 - case "$section" in
263 - (remote)
264 - if [ "$key" = url ]; then
265 - rhs=$REPOSITORY_COLOR$rhs$RESET_COLOR
266 - fi
267 - ;;
268 - (branch)
269 - if [ "$key" = remote ]; then
270 - rhs=$REMOTE_COLOR$rhs$RESET_COLOR
271 - fi
272 - esac
273 - printf "\t\t%s = %s\n" "$key" "$rhs"
274 - ;;
275 - (?*.?*)
276 - section=$(expr "$lhs" : '\([^.]\{1,\}\)')
277 - key=$(expr "$lhs" : '[^.]\{1,\}\.\([^.]\{1,\}\)$')
278 - if [ "$section" != "$prev_section" -o -n "$prev_subsection" ]; then
279 - prev_section=$section
280 - prev_subsection=
281 - printf "\t[%s]\n" "$section"
282 - fi
283 - printf "\t\t$key = $rhs\n"
284 - ;;
285 - (*)
286 - esac
287 - esac
288 - done
289 - }
291 - (cd "$root" && GIT_DIR="$git_dir" git log --max-count=1 "$@") | {
292 - while read -r field line; do
293 - color=
294 - reset=
295 - case "$field" in
296 - commit)
297 - field='Commit ID:'
298 - color="$ID_COLOR"
299 - reset="$RESET_COLOR"
300 - ;;
301 - *:)
302 - ;;
303 - '')
304 - break
305 - ;;
306 - esac
307 - echo "Last Changed $field $color$line$reset"
308 - done
309 - cat > "$TEMPFILE"
310 - }
311 - echo "Last Changed Log:"
312 - sed 's/^ / /' "$TEMPFILE"
314 - finalize
317 -die () {
318 - [ "$#" -gt 0 ] && echo "$0: $@" >&2
319 - finalize
320 - exit 1
323 -TEMPFILE=
325 -maketemp () {
326 - if [ -z "$TEMPFILE" ]; then
327 - TEMPFILE="$(mktemp /tmp/git-info.XXXXXX)" || die
328 - trap "finalize; exit 130" 1 2 3 15
329 - fi
332 -finalize () {
333 - if [ -n "$TEMPFILE" ]; then
334 - rm -f "$TEMPFILE"
335 - fi
1 +#!/bin/sh
2 +#
3 +# git-info - shows information about a Git repository a la `svn info'
4 +#
5 +# How to use:
6 +# $ git info
7 +# $ git info ~/src/somewhere/somefile
8 +# $ git info some/relative/file_or_directory
9 +# $ git info ~/repos/something.git
11 +# Copyright (c) 2009-2022 Akinori MUSHA
13 +# All rights reserved.
15 +# Redistribution and use in source and binary forms, with or without
16 +# modification, are permitted provided that the following conditions
17 +# are met:
18 +# 1. Redistributions of source code must retain the above copyright
19 +# notice, this list of conditions and the following disclaimer.
20 +# 2. Redistributions in binary form must reproduce the above copyright
21 +# notice, this list of conditions and the following disclaimer in the
22 +# documentation and/or other materials provided with the distribution.
24 +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 +# SUCH DAMAGE.
37 +COLOR=
39 +main () {
40 + local opt
41 + local OPTS_SPEC="\
42 +$0 [<options>] [<path>]
44 +$0 shows information about a Git repository.
45 +--
46 +h,help show the help
47 +color?when show colored output (always|never|auto)
49 + eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt --stuck-long -- "$@" || echo exit $?)"
51 + while [ $# -gt 0 ]; do
52 + opt="$1"
53 + shift
55 + case "$opt" in
56 + --color)
57 + COLOR=always
58 + ;;
59 + --color\=*)
60 + COLOR="${opt#*=}"
61 + ;;
62 + --)
63 + break
64 + ;;
65 + *)
66 + die "Unexpected option: $opt"
67 + ;;
68 + esac
69 + done
71 + initialize_colors
73 + case "$#" in
74 + 1)
75 + ;;
76 + 0)
77 + if [ -n "$GIT_DIR" ]; then
78 + set -- "$GIT_DIR"
79 + else
80 + set -- .
81 + fi
82 + ;;
83 + *)
84 + die "Too many arguments"
85 + ;;
86 + esac
88 + git_info "$1"
91 +initialize_colors () {
92 + if [ -z "$COLOR" ]; then
93 + if git config --get-colorbool color.info; then
94 + COLOR=always
95 + else
96 + COLOR=never
97 + fi
98 + fi
100 + case "$COLOR" in
101 + always|never)
102 + COLOR_BRANCH=$COLOR
103 + ;;
104 + auto)
105 + if git config --get-colorbool color.branch; then
106 + COLOR_BRANCH=always
107 + else
108 + COLOR_BRANCH=never
109 + fi
110 + ;;
111 + *)
112 + die "option \`color' expects \"always\", \"auto\", or \"never\""
113 + ;;
114 + esac
116 + if [ "$COLOR" = always ]; then
117 + REMOTE_COLOR="$(get_color color.info.remote color.branch.remote red)"
118 + LOCAL_COLOR="$(get_color color.info.local color.branch.local green)"
119 + PATH_COLOR="$(get_color color.info.path '' 'bold')"
120 + REPOSITORY_COLOR="$(get_color color.info.repository '' 'bold')"
121 + ID_COLOR="$(get_color color.info.id '' 'yellow')"
122 + RESET_COLOR=$(printf "\033[m")
123 + else
124 + REMOTE_COLOR=
125 + LOCAL_COLOR=
126 + PATH_COLOR=
127 + REPOSITORY_COLOR=
128 + ID_COLOR=
129 + RESET_COLOR=
130 + fi
133 +get_color () {
134 + local key1="$1" key2="$2" fb="$3"
135 + local color="$(git config --get-color "$key1" '')"
136 + case "$color" in
137 + ''|'')
138 + git config --get-color "$key2" "$fb"
139 + ;;
140 + *)
141 + printf '%s' "$color"
142 + ;;
143 + esac
146 +git_info () {
147 + local path="$1" dir relpath root git_dir
149 + if [ -d "$path" ]; then
150 + dir="$(cd -P "$path" && pwd)" || die "$path: Cannot cd to the directory"
151 + case "$path" in
152 + *.git)
153 + git_dir="$dir"
154 + ;;
155 + esac
156 + elif [ -f "$path" ]; then
157 + dir="$(dirname "$path")"
158 + dir="$(cd -P "$dir" && pwd)" || die "$dir: Cannot cd to the directory"
159 + relpath="$(basename "$path")"
160 + else
161 + die "$path: No such file or directory"
162 + fi
164 + if [ -n "$git_dir" ]; then
165 + dir=
166 + relpath=
167 + elif case "$dir" in ?*.git) [ -d "$dir/objects" -a -d "$dir/refs" ] ;; *) false ;; esac; then
168 + git_dir="$dir"
169 + relpath=
170 + else
171 + root="$(
172 + cd "$dir" || exit 1
173 + while [ ! -e .git ]; do
174 + [ "$(pwd)" = / ] && exit 1
175 + cd ..
176 + done
177 + pwd
178 + )" || die "Not a git repository."
179 + git_dir="$root/.git"
180 + if [ "$dir" = "$root" ]; then
181 + relpath=.
182 + elif [ -n "$relpath" ]; then
183 + relpath="${dir#"$root/"}/$relpath"
184 + else
185 + relpath="${dir#"$root/"}"
186 + fi
187 + fi
189 + set -- "$git_dir"
190 + if [ -n "$relpath" ]; then
191 + set -- "$@" "$relpath"
192 + fi
194 + do_git_info "$@"
197 +do_git_info () {
198 + local git_dir="$1" relpath="$2" root line field color reset
200 + shift
202 + echo "Repository Path: $PATH_COLOR$git_dir$RESET_COLOR"
204 + if [ $# -gt 0 ]; then
205 + root="$(dirname "$git_dir")"
206 + if [ "$relpath" = . ]; then
207 + echo "Path: $PATH_COLOR$root$RESET_COLOR"
208 + else
209 + echo "Path: $PATH_COLOR$root/$relpath$RESET_COLOR"
210 + fi
211 + fi
213 + maketemp
215 + GIT_DIR="$git_dir" git remote -v > "$TEMPFILE"
216 + if [ -s "$TEMPFILE" ]; then
217 + echo "Remote Repositories:"
218 + sed -e "s/^\([^ ]\{1,\}\)\([ ]\{1,\}\)\([^ ]\{1,\}\)/$REMOTE_COLOR\1$RESET_COLOR\2$REPOSITORY_COLOR\3$RESET_COLOR/" \
219 + -e 's/^/ /' \
220 + "$TEMPFILE"
221 + fi
223 + GIT_DIR="$git_dir" git branch -r --color=$COLOR_BRANCH > "$TEMPFILE"
224 + if [ -s "$TEMPFILE" ]; then
225 + echo "Remote Branches:"
226 + sed -e "s/\([ ]\{1,\}->[ ]\{1,\}\)\([^ ]\{1,\}\)/\1$REMOTE_COLOR\2$RESET_COLOR/" \
227 + -e 's/^ */ /' "$TEMPFILE"
228 + fi
230 + GIT_DIR="$git_dir" git branch --color=$COLOR_BRANCH > "$TEMPFILE"
231 + if [ -s "$TEMPFILE" ]; then
232 + echo "Local Branches:"
233 + sed 's/^/ /' "$TEMPFILE"
234 + fi
236 + echo "Repository Configuration:"
237 + GIT_DIR="$git_dir" git config --local --list | sort | {
238 + prev_section=
239 + prev_subsection=
240 + while read line; do
241 + case "$line" in
242 + (*=*)
243 + lhs=$(expr "$line" : '\([^=]\{1,\}\)')
244 + rhs=$(expr "$line" : '[^=]\{1,\}=\(.*\)')
245 + case "$lhs" in
246 + (?*.?*.?*)
247 + section=$(expr "$lhs" : '\([^.]\{1,\}\)')
248 + subsection=$(expr "$lhs" : '[^.]\{1,\}\.\(.\{1,\}\)\.')
249 + key=$(expr "$lhs" : '[^.]\{1,\}\..\{1,\}\.\([^.]\{0,\}\)$')
250 + if [ "$section" != "$prev_section" -o "$subsection" != "$prev_subsection" ]; then
251 + prev_section=$section
252 + prev_subsection=$subsection
253 + case "$section" in
254 + (remote)
255 + subsection=$REMOTE_COLOR$subsection$RESET_COLOR
256 + ;;
257 + (branch)
258 + subsection=$LOCAL_COLOR$subsection$RESET_COLOR
259 + esac
260 + printf "\t[%s \"%s\"]\n" "$section" "$subsection"
261 + fi
262 + case "$section" in
263 + (remote)
264 + if [ "$key" = url ]; then
265 + rhs=$REPOSITORY_COLOR$rhs$RESET_COLOR
266 + fi
267 + ;;
268 + (branch)
269 + if [ "$key" = remote ]; then
270 + rhs=$REMOTE_COLOR$rhs$RESET_COLOR
271 + fi
272 + esac
273 + printf "\t\t%s = %s\n" "$key" "$rhs"
274 + ;;
275 + (?*.?*)
276 + section=$(expr "$lhs" : '\([^.]\{1,\}\)')
277 + key=$(expr "$lhs" : '[^.]\{1,\}\.\([^.]\{1,\}\)$')
278 + if [ "$section" != "$prev_section" -o -n "$prev_subsection" ]; then
279 + prev_section=$section
280 + prev_subsection=
281 + printf "\t[%s]\n" "$section"
282 + fi
283 + printf "\t\t$key = $rhs\n"
284 + ;;
285 + (*)
286 + esac
287 + esac
288 + done
291 + (cd "$root" && GIT_DIR="$git_dir" git log --max-count=1 "$@") | {
292 + while read -r field line; do
293 + color=
294 + reset=
295 + case "$field" in
296 + commit)
297 + field='Commit ID:'
298 + color="$ID_COLOR"
299 + reset="$RESET_COLOR"
300 + ;;
301 + *:)
302 + ;;
303 + '')
304 + break
305 + ;;
306 + esac
307 + echo "Last Changed $field $color$line$reset"
308 + done
309 + cat > "$TEMPFILE"
311 + echo "Last Changed Log:"
312 + sed 's/^ / /' "$TEMPFILE"
314 + finalize
317 +die () {
318 + [ "$#" -gt 0 ] && echo "$0: $@" >&2
319 + finalize
320 + exit 1
323 +TEMPFILE=
325 +maketemp () {
326 + if [ -z "$TEMPFILE" ]; then
327 + TEMPFILE="$(mktemp /tmp/git-info.XXXXXX)" || die
328 + trap "finalize; exit 130" 1 2 3 15
329 + fi
332 +finalize () {
333 + if [ -n "$TEMPFILE" ]; then
334 + rm -f "$TEMPFILE"
335 + fi
338 338 main "$@"

tools/gnome-settings.nu

Modified
1 -#!/usr/bin/env nu
3 -def main [] {
4 - const background_settings = [
5 - ['key', 'value'];
6 - ['picture-uri', 'none']
7 - ['color-shading-type', 'solid']
8 - ['primary-color', '#131313']
9 - ['secondary-color', '#131313']
10 - ]
12 - $background_settings | each { | setting |
13 - run-external gsettings set 'org.gnome.desktop.background' $setting.key $setting.value
14 - }
16 - null
17 -}
1 +#!/usr/bin/env nu
3 +def main [] {
4 + const background_settings = [
5 + ['key', 'value'];
6 + ['picture-uri', 'none']
7 + ['color-shading-type', 'solid']
8 + ['primary-color', '#131313']
9 + ['secondary-color', '#131313']
10 + ]
12 + $background_settings | each { | setting |
13 + run-external gsettings set 'org.gnome.desktop.background' $setting.key $setting.value
14 + }
16 + null

tools/install.java

Modified
1 -import static java.lang.System.out;
2 -import static java.lang.System.err;
4 -import java.nio.file.Files;
5 -import java.nio.file.Path;
6 -import java.nio.file.Paths;
7 -import java.util.Arrays;
9 -final class install {
10 - // TODO: platform key in die csv, um os zu unterscheiden.
11 - static final String CARGO_PACKAGES_CSV_FILE = "tools.csv";
13 - public static void main(String[] __)
14 - throws Throwable {
15 - exec("cargo", "--version");
17 - var csv = Path.of(CARGO_PACKAGES_CSV_FILE);
18 - if (!Files.exists(csv)) {
19 - throw fail("Expected a CSV file with cargo crates!");
20 - }
22 - var lines = Files.lines(csv).toArray(String[]::new);
23 - for (int index = 1; index < lines.length; ++index) {
24 - var line = lines[index];
25 - var spec = parse(line);
26 - if (spec != null && !which(spec.bin)) {
27 - install(spec);
28 - }
29 - }
30 - }
32 - static boolean which(String program) {
33 - var pathEnv = System.getenv("PATH");
35 - if (pathEnv == null || pathEnv.isEmpty()) {
36 - return false;
37 - }
39 - var paths = pathEnv.split(System.getProperty("path.separator"));
40 - var extensions = new String[] { "", ".exe", ".bat", ".cmd", ".com" };
42 - for (var path : paths) {
43 - for (var extension : extensions) {
44 - var fullPath = Paths.get(path, program + extension);
45 - if (Files.exists(fullPath) && Files.isExecutable(fullPath)) {
46 - return true;
47 - }
48 - }
49 - }
51 - return false;
52 - }
54 - static void exec(String... command)
55 - throws Throwable {
56 - var proc = new ProcessBuilder(command).inheritIO().start();
57 - proc.waitFor();
58 - var exit = proc.exitValue();
59 - if (exit != 0) {
60 - throw fail("process failed to exec with code %d.%nproc: %s", exit, emphasize_local(Arrays.toString(command)));
61 - }
62 - }
64 - static void install(Spec spec)
65 - throws Throwable {
66 - out("cargo install %s (%s) %s",
67 - emphasize_global(spec.name),
68 - emphasize_local(spec.bin),
69 - emphasize_local(Arrays.toString(spec.flags)));
71 - var cmd = new String[3 + spec.flags.length];
72 - cmd[0] = "cargo";
73 - cmd[1] = "install";
74 - cmd[2] = spec.name;
76 - System.arraycopy(spec.flags, 0, cmd, 3, spec.flags.length);
78 - exec(cmd);
79 - }
81 - record Spec(String name, String bin, String... flags) {
82 - };
84 - static Spec parse(String line)
85 - throws Throwable {
86 - if (line.startsWith("#"))
87 - {
88 - return null;
89 - }
90 - var by_comma = line.split(";");
91 - if (by_comma.length == 0) {
92 - throw fail("empty line in CSV");
93 - }
94 - if (by_comma.length > 3) {
95 - throw fail("line in CSV should have 1-3 fields%nfound: %s", emphasize_local(line));
96 - }
97 - var name = by_comma[0].strip();
98 - var bin = name;
99 - if (by_comma.length > 1) {
100 - bin = by_comma[1].strip();
101 - }
102 - var flags = new String[] {};
103 - if (by_comma.length == 3) {
104 - flags = by_comma[2].strip().split(" ");
105 - }
106 - return new Spec(name, bin, flags);
107 - }
109 - static void out(String fmt, Object... args) {
110 - out.printf(fmt, args);
111 - out.println();
112 - }
114 - static void dbg(String fmt, Object... args) {
115 - System.err.print("[DBG]: ");
116 - System.err.printf(fmt, args);
117 - System.err.println();
118 - }
120 - static Throwable exit() {
121 - System.exit(0);
122 - // abuse control flow to make compiler realize `exit` will never return
123 - return new Throwable();
124 - }
126 - static String emphasize_global(String message) {
127 - return "\033[4m" + message + "\033[0m";
128 - }
130 - static String emphasize_local(String message) {
131 - return "\033[3m" + message + "\033[0m";
132 - }
134 - static Throwable fail(String message, Object... arguments) {
135 - err.printf(message, arguments);
136 - System.exit(-1);
137 - // abuse control flow to make compiler realize `fail` will never return
138 - return new Throwable();
139 - }
141 - static Throwable fail() {
142 - System.exit(-1);
143 - // abuse control flow to make compiler realize `fail` will never return
144 - return new Throwable();
145 - }
1 +import static java.lang.System.out;
2 +import static java.lang.System.err;
4 +import java.nio.file.Files;
5 +import java.nio.file.Path;
6 +import java.nio.file.Paths;
7 +import java.util.Arrays;
9 +final class install {
10 + // TODO: platform key in die csv, um os zu unterscheiden.
11 + static final String CARGO_PACKAGES_CSV_FILE = "crates.csv";
13 + public static void main(String[] __)
14 + throws Throwable {
15 + exec("cargo", "--version");
17 + var csv = Path.of(CARGO_PACKAGES_CSV_FILE);
18 + if (!Files.exists(csv)) {
19 + throw fail("Expected a CSV file with cargo crates!");
20 + }
22 + var lines = Files.lines(csv).toArray(String[]::new);
23 + for (int index = 1; index < lines.length; ++index) {
24 + var line = lines[index];
25 + var spec = parse(line);
26 + if (spec != null && !which(spec.bin)) {
27 + install(spec);
28 + }
29 + }
30 + }
32 + static boolean which(String program) {
33 + var pathEnv = System.getenv("PATH");
35 + if (pathEnv == null || pathEnv.isEmpty()) {
36 + return false;
37 + }
39 + var paths = pathEnv.split(System.getProperty("path.separator"));
40 + var extensions = new String[] { "", ".exe", ".bat", ".cmd", ".com" };
42 + for (var path : paths) {
43 + for (var extension : extensions) {
44 + var fullPath = Paths.get(path, program + extension);
45 + if (Files.exists(fullPath) && Files.isExecutable(fullPath)) {
46 + return true;
47 + }
48 + }
49 + }
51 + return false;
52 + }
54 + static void exec(String... command)
55 + throws Throwable {
56 + var proc = new ProcessBuilder(command).inheritIO().start();
57 + proc.waitFor();
58 + var exit = proc.exitValue();
59 + if (exit != 0) {
60 + throw fail("process failed to exec with code %d.%nproc: %s", exit, emphasize_local(Arrays.toString(command)));
61 + }
62 + }
64 + static void install(Spec spec)
65 + throws Throwable {
66 + out("cargo install %s (%s) %s",
67 + emphasize_global(spec.name),
68 + emphasize_local(spec.bin),
69 + emphasize_local(Arrays.toString(spec.flags)));
71 + var cmd = new String[3 + spec.flags.length];
72 + cmd[0] = "cargo";
73 + cmd[1] = "install";
74 + cmd[2] = spec.name;
76 + System.arraycopy(spec.flags, 0, cmd, 3, spec.flags.length);
78 + exec(cmd);
79 + }
81 + record Spec(String name, String bin, String... flags) {
82 + };
84 + static Spec parse(String line)
85 + throws Throwable {
86 + if (line.startsWith("#"))
87 + {
88 + return null;
89 + }
90 + var by_comma = line.split(";");
91 + if (by_comma.length == 0) {
92 + throw fail("empty line in CSV");
93 + }
94 + if (by_comma.length > 3) {
95 + throw fail("line in CSV should have 1-3 fields%nfound: %s", emphasize_local(line));
96 + }
97 + var name = by_comma[0].strip();
98 + var bin = name;
99 + if (by_comma.length > 1) {
100 + bin = by_comma[1].strip();
102 + var flags = new String[] {};
103 + if (by_comma.length == 3) {
104 + flags = by_comma[2].strip().split(" ");
106 + return new Spec(name, bin, flags);
109 + static void out(String fmt, Object... args) {
110 + out.printf(fmt, args);
111 + out.println();
114 + static void dbg(String fmt, Object... args) {
115 + System.err.print("[DBG]: ");
116 + System.err.printf(fmt, args);
117 + System.err.println();
120 + static Throwable exit() {
121 + System.exit(0);
122 + // abuse control flow to make compiler realize `exit` will never return
123 + return new Throwable();
126 + static String emphasize_global(String message) {
127 + return "\033[4m" + message + "\033[0m";
130 + static String emphasize_local(String message) {
131 + return "\033[3m" + message + "\033[0m";
134 + static Throwable fail(String message, Object... arguments) {
135 + err.printf(message, arguments);
136 + System.exit(-1);
137 + // abuse control flow to make compiler realize `fail` will never return
138 + return new Throwable();
141 + static Throwable fail() {
142 + System.exit(-1);
143 + // abuse control flow to make compiler realize `fail` will never return
144 + return new Throwable();

tools/packages.nu

Added
new file mode 100644
1 +#
2 +# This "package manager" can only isntall single executable files for now.
3 +# TODO: add support for "folder based" software
4 +# TODO: create symlinks
5 +#
7 +let OS = sys host | get name
9 +def main [] {
10 + let install_path = make-install-path
11 + let cache_path = make-cache-path 'net.bugabinga.packages'
12 + let packages = open 'packages.nuon'
14 + install-packages $install_path $cache_path $packages
15 + null
18 +def make-install-path [] {
19 + let install_path = $env.TOOLS | path join bin
20 + mkdir $install_path
21 + $install_path
24 +def make-cache-path [
25 + name: string # application name, for which to generate a stable system location for cache files
26 +] {
27 + let os = sys host | get name
28 + let system_location = if $OS =~ "Windows" {
29 + $env.LOCALAPPDATA
30 + } else if $os =~ "Linux" {
31 + $env | get-or-else XDG_CACHE_HOME ($env.HOME | path join .cache)
32 + } else {
33 + error make {
34 + msg: "unsupported operating system detected! initialising self destruct sequence..."
35 + }
36 + }
37 + let cache_path = $system_location | path join $name
38 + mkdir $cache_path
39 + $cache_path
42 +# Gets value of a column, or falls back to given alternative value.
43 +#
44 +def get-or-else [
45 + column: string # name of the column to get its value from
46 + value: any # alternative value to return, in case `get` gets nothing
47 +]: [
48 + record -> any
49 + table -> any
50 +] {
51 + select -i $column | update $column { if ( $in | is-empty ) { $value } else { $in } } | get $column
54 +def install-packages [
55 + install_path: path # path where to install packages to
56 + cache_path: path # path where to cache downloaded packed in
57 + packages: list<any> # packages to install
58 +] {
59 + $packages | par-each {
60 + | package |
61 + if ($package | is-installed-in $install_path $cache_path) {
62 + print $"Package ($package.name) is already installed."
63 + } else {
64 + let artifact = download-package? $package $cache_path
65 + if $artifact == null {
66 + print $'Package ($package.name) is not available for current operating system. Skipping it!'
67 + return
68 + }
69 + let executable = unpack-executable $package $artifact
70 + install-executable $package $executable $install_path
71 + }
72 + }
75 +def download-package? [
76 + package: record # package specification
77 + cache: path # cache path for packages
78 +] {
79 + let artifact_path = make-artifact-path? $package $cache
80 + if $artifact_path == null {
81 + return null
82 + }
83 + if ($artifact_path | path exists) {
84 + return $artifact_path
85 + } else {
86 + mkdir ($artifact_path | path dirname)
87 + let url = make-url? $package
88 + http get --raw --max-time 30sec $url | save --progress --raw $artifact_path
89 + return $artifact_path
90 + }
93 +def make-url? [
94 + package: record # package specification
95 +] {
96 + let url_format = match $OS {
97 + "Windows" => { $package.win32_url }
98 + $os if $os =~ "Linux" => { $package.lnx_url }
99 + _ => { error make { msg: "unknown operating system" } }
101 + if $url_format == null {
102 + return null
104 + $url_format | str replace --all --regex '\{\s*version\s*\}' $package.version
107 +def make-artifact-path? [
108 + package: record # package specification
109 + cache: path # cache path for packages
110 +] {
111 + let url = make-url? $package
112 + if $url == null {
113 + return null
115 + let artifact_parent_path = [ $cache $package.name ] | path join
116 + let extension = $url | url parse | get path | get-extension
117 + ($artifact_parent_path | path join $package.version) + "." + $extension
120 +def get-extension []: path -> string {
121 + let path = $in | path parse
122 + if ($path.stem | str ends-with '.tar') {
123 + return ('tar.' + $path.extension)
124 + } else {
125 + return $path.extension
129 +def unpack-executable [
130 + package: record # package specification
131 + artifact: path # archive or executable
132 +] {
133 + if ($artifact | is-archive ) {
134 + let tmpdir = mktemp --directory --tmpdir 'net.bugabinga.packages.XXXXXX'
135 + run-external ouch '--quiet' decompress '--dir' $tmpdir $artifact
136 + let exe_glob = '(?i)' + $'($tmpdir)/**/*($package.binary)*' | str replace --all '\' '/' | str replace ':' '\:'
137 + let executable = glob --no-dir --no-symlink $exe_glob |
138 + filter { is-executable } |
139 + first
140 + return $executable
142 + } else if ($artifact | is-executable) {
143 + let tmpdir = mktemp --directory --tmpdir 'net.bugabinga.packages.XXXXXX'
144 + cp $artifact $tmpdir
145 + let copy = [ $tmpdir ($artifact | path basename)] | path join
146 + return $copy
147 + } else {
148 + error make {
149 + msg: "unknown package type"
150 + label: {
151 + text: "trying to unpack this artifact failed"
152 + span: (metadata $artifact).span
158 +def is-archive []: path -> bool {
159 + let magic_headers = [
160 + 0x[FD 37 7A 58 5A 00] # xz
161 + 0x[50 4B] # ZIP
162 + 0x[1F 8B] # gzip
163 + 0x[75 73 74 61 72] # tar
165 + $in | is-magic-file $magic_headers
168 +def is-executable []: path -> bool {
169 + let magic_headers = [
170 + 0x[7F 45 4C 46] # elf
171 + 0x[4D 5A] # DOS MZ
173 + $in | is-magic-file $magic_headers
176 +def is-magic-file [
177 + magic_headers: list<binary> # list of magic headers to check file against
178 +]: path -> bool {
179 + let max_size = $magic_headers | each { length } | math max
180 + let header = open $in | into binary | first $max_size
181 + $magic_headers | any { |magic| $header | bytes starts-with $magic }
184 +def install-executable [
185 + package: record # package specification
186 + executable: path # path to an executable to install
187 + installs: path # path to all installed packages
188 +] {
189 + let target = make-target-path $package $installs
190 + mv --interactive --verbose --update $executable $target
193 +def is-installed-in [
194 + installs: path # path to all installed packages
195 + cache: path # path to cache of all packages
196 +]: record -> bool {
197 + let package = $in
198 + let is_installed = make-target-path $package $installs | path exists
199 + let artifact_path = make-artifact-path? $package $cache
200 + if $artifact_path == null {
201 + return false
203 + let is_cached = $artifact_path | path exists
204 + $is_installed and $is_cached
207 +def make-target-path [
208 + package: record # package specification
209 + installs: path # path to all installed packages
210 +] {
211 + let target = $installs | path join ($package | get binary | to-executable-name)
212 + return $target
215 +def to-executable-name []: string -> string {
216 + [ $in (if $OS =~ "Windows" { '.exe' } else { '' } ) ] | str join

tools/packages.nuon

Added
new file mode 100644
1 +[
2 + [name binary version win32_url lnx_url];
3 + [
4 + ouch
5 + ouch
6 + 0.5.1
7 + https://github.com/ouch-org/ouch/releases/download/{ version }/ouch-x86_64-pc-windows-msvc.zip
8 + https://github.com/ouch-org/ouch/releases/download/{ version }/ouch-x86_64-unknown-linux-musl.tar.gz
9 + ],
10 + [
11 + heatseaker
12 + hs
13 + 1.7.2
14 + https://github.com/rschmitt/heatseeker/releases/download/v{ version }/heatseeker-v{ version }-x86_64-pc-windows-msvc.zip
15 + https://github.com/rschmitt/heatseeker/releases/download/v{ version }/heatseeker-v{ version }-x86_64-unknown-linux-musl.tar.gz
16 + ],
17 + [
18 + ijq
19 + ijq
20 + 1.1.2
21 + https://git.sr.ht/~gpanders/ijq/refs/download/v{ version }/ijq-{ version }-windows-amd64.tar.gz
22 + https://git.sr.ht/~gpanders/ijq/refs/download/v{ version }/ijq-{ version }-linux-amd64.tar.gz
23 + ],
24 + [
25 + spoon
26 + spoon
27 + 0.0.9
28 + https://github.com/Bios-Marcel/spoon/releases/download/v{ version }/spoon.exe
29 + null
30 + ],
31 + [
32 + ttyper
33 + ttyper
34 + 1.6.0
35 + https://github.com/max-niederman/ttyper/releases/download/v{ version }/ttyper-x86_64-pc-windows-msvc.zip
36 + https://github.com/max-niederman/ttyper/releases/download/v{ version }/ttyper-x86_64-unknown-linux-musl.tar.gz
37 + ],
38 + [
39 + tree-sitter
40 + tree-sitter
41 + 0.24.4
42 + https://github.com/tree-sitter/tree-sitter/releases/download/v{ version }/tree-sitter-windows-x64.gz
43 + https://github.com/tree-sitter/tree-sitter/releases/download/v{ version }/tree-sitter-linux-x64.gz
44 + ],
45 + [
46 + win32yank
47 + win32yank
48 + 0.1.1
49 + https://github.com/equalsraf/win32yank/releases/download/v{ version }/win32yank-x64.zip
50 + null
51 + ],
52 + [
53 + ltex-ls
54 + ltex-ls
55 + 16.0.0
56 + https://github.com/valentjn/ltex-ls/releases/download/{ version }/ltex-ls-{ version }-windows-x64.zip
57 + https://github.com/valentjn/ltex-ls/releases/download/{ version }/ltex-ls-{ version }-linux-x64.tar.gz
58 + ],
59 + [
60 + Contextive.LanguageServer
61 + Contextive.LanguageServer
62 + 1.12.1
63 + https://github.com/dev-cycles/contextive/releases/download/v{ version }/Contextive.LanguageServer-win-x64-{ version }.zip
64 + https://github.com/dev-cycles/contextive/releases/download/v{ version }/Contextive.LanguageServer-linux-x64-{ version }.zip
65 + ],

tools/rbwsearch

Modified
1 -#!/bin/bash
3 -rbwsearch() {
4 - SEARCH_ARGS=()
5 - RBW_ARGS=()
7 - while [[ $# -gt 0 ]]; do
8 - case $1 in
9 - -f|--field)
10 - RBW_ARGS+=("$1" "$2")
11 - shift
12 - shift
13 - ;;
14 - -*)
15 - RBW_ARGS+=("$1")
16 - shift
17 - ;;
18 - *)
19 - SEARCH_ARGS+=("$1")
20 - shift
21 - ;;
22 - esac
23 - done
24 - rbw unlocked || rbw unlock || return
25 - IFS=$'\t' read -r NAME FOLDER < <(rbw list --fields name,folder|sk -q "${SEARCH_ARGS[*]}")
26 - if [ -n "$FOLDER" ]; then
27 - RBW_ARGS+=("--folder" "$FOLDER")
28 - fi
29 - rbw get --clipboard "${RBW_ARGS[@]}" "$NAME"
30 -}
32 -rbwsearch $@
1 +#!/bin/bash
3 +rbwsearch() {
4 + SEARCH_ARGS=()
5 + RBW_ARGS=()
7 + while [[ $# -gt 0 ]]; do
8 + case $1 in
9 + -f|--field)
10 + RBW_ARGS+=("$1" "$2")
11 + shift
12 + shift
13 + ;;
14 + -*)
15 + RBW_ARGS+=("$1")
16 + shift
17 + ;;
18 + *)
19 + SEARCH_ARGS+=("$1")
20 + shift
21 + ;;
22 + esac
23 + done
24 + rbw unlocked || rbw unlock || return
25 + IFS=$'\t' read -r NAME FOLDER < <(rbw list --fields name,folder|sk -q "${SEARCH_ARGS[*]}")
26 + if [ -n "$FOLDER" ]; then
27 + RBW_ARGS+=("--folder" "$FOLDER")
28 + fi
29 + rbw get --clipboard "${RBW_ARGS[@]}" "$NAME"
32 +rbwsearch $@

tools/tools.csv

Deleted
deleted file mode 100644
1 -name;bin;cargo_args
2 -asm-cli-rust; asm-cli-rust; --git https://github.com/cch123/asm-cli-rust
3 -bat
4 -bk
5 -bottom; btm
6 -cargo-cache
7 -cargo-update;cargo-install-update
8 -carl
9 -calendar-rs;calendar
10 -du-dust; dust
11 -dotenv-linter
12 -diskonaut
13 -eva
14 -emplace
15 -eza; eza; --features vendored-openssl,vendored-libgit2
16 -fend
17 -fd-find;fd
18 -git-delta;delta
19 -gitu;gitu; --locked
20 -gitoxide;gix
21 -hexyl
22 -hyperfine
23 -inlyne
24 -jj-cli; jj; --locked --bin jj
25 -just
26 -lms
27 -lurk-cli; lurk
28 -lychee;lychee; --locked --no-default-features --features rustls-tls,email-check
29 -macchina
30 -mdbook
31 -mdcat
32 -monolith
33 -names
34 -netscanner
35 -neovide;neovide; --git https://github.com/neovide/neovide
36 -nu;nu; --locked
37 -nu_plugin_audio_hook; nu_plugin_audio_hook; --git https://github.com/FMotalleb/nu_plugin_audio_hook.git --features all-decoders
38 -ouch
39 -pastel
40 -presenterm
41 -pueue;pueue;--locked
42 -ripgrep;rg
43 -rbw
44 -skim;sk
45 -sbyte
46 -sniffnet
47 -taplo-cli;taplo; --locked --features lsp
48 -tealdeer;tldr
49 -tokei
50 -topgrade
51 -tsdl
52 -ttyper
53 -unison-fsmonitor
54 -ugdb
55 -vivid
56 -wthrr
57 -yazi-cli;ya; --locked
58 -yazi-fm;yazi; --locked
59 -zoxide

tools/wezterm_terminfo.sh

Modified
1 -tempfile=$(mktemp) \
2 - && curl -o "$tempfile" https://raw.githubusercontent.com/wez/wezterm/main/termwiz/data/wezterm.terminfo \
3 - && tic -x -o ~/.terminfo "$tempfile" \
4 - && rm "$tempfile"
1 +tempfile=$(mktemp) \
2 + && curl -o "$tempfile" https://raw.githubusercontent.com/wez/wezterm/main/termwiz/data/wezterm.terminfo \
3 + && tic -x -o ~/.terminfo "$tempfile" \
4 + && rm "$tempfile"