From 9f3594e0d348bfe9f38b6d9b4542a3b8c8ba897a Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Tue, 18 Jun 2024 03:52:40 +0200 Subject: [PATCH] add bins and alternatives --- data/home/.local/bin/box-drawing-char.sh | 17 ++++++++++ data/home/.local/bin/choose.ts | 6 ++++ data/home/.local/bin/daemonize-thunar.sh | 3 ++ data/home/.local/bin/defer.sh | 3 ++ data/home/.local/bin/deno_quiet.sh | 3 ++ data/home/.local/bin/enable_wol.sh | 22 +++++++++++++ data/home/.local/bin/fix_cinnamon.sh | 3 ++ data/home/.local/bin/glava.sh | 3 ++ data/home/.local/bin/kill-nemo-desktop.sh | 3 ++ data/home/.local/bin/mk_vm.sh | 30 ++++++++++++++++++ data/home/.local/bin/poupette.sh | 5 +++ data/home/.local/bin/prefix | 5 --- data/home/.local/bin/prefix.ts | 33 +++++++++++++++++++ data/home/.local/bin/randomize_filename.ts | 17 ++++++++++ data/home/.local/bin/reparer_discord.ts | 7 ++++ data/home/.local/bin/screenshot.sh | 5 +++ data/home/.local/bin/sdparams.ts | 37 ++++++++++++++++++++++ data/home/.local/bin/start-rustdesk.sh | 3 ++ data/home/.local/bin/start_corectrl.sh | 2 ++ data/home/.local/bin/wait_pid.sh | 3 ++ data/home/.zprofile | 10 +++--- 21 files changed, 210 insertions(+), 10 deletions(-) create mode 100755 data/home/.local/bin/box-drawing-char.sh create mode 100755 data/home/.local/bin/choose.ts create mode 100755 data/home/.local/bin/daemonize-thunar.sh create mode 100755 data/home/.local/bin/defer.sh create mode 100755 data/home/.local/bin/deno_quiet.sh create mode 100755 data/home/.local/bin/enable_wol.sh create mode 100755 data/home/.local/bin/fix_cinnamon.sh create mode 100755 data/home/.local/bin/glava.sh create mode 100755 data/home/.local/bin/kill-nemo-desktop.sh create mode 100755 data/home/.local/bin/mk_vm.sh create mode 100755 data/home/.local/bin/poupette.sh delete mode 100755 data/home/.local/bin/prefix create mode 100755 data/home/.local/bin/prefix.ts create mode 100755 data/home/.local/bin/randomize_filename.ts create mode 100755 data/home/.local/bin/reparer_discord.ts create mode 100755 data/home/.local/bin/screenshot.sh create mode 100755 data/home/.local/bin/sdparams.ts create mode 100755 data/home/.local/bin/start-rustdesk.sh create mode 100755 data/home/.local/bin/start_corectrl.sh create mode 100755 data/home/.local/bin/wait_pid.sh diff --git a/data/home/.local/bin/box-drawing-char.sh b/data/home/.local/bin/box-drawing-char.sh new file mode 100755 index 0000000..db14208 --- /dev/null +++ b/data/home/.local/bin/box-drawing-char.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +echo 0x6a j ┘ +echo 0x6b k ┐ +echo 0x6c l ┌ +echo 0x6d m └ +echo 0x6e n ┼ +echo 0x71 q ─ +echo 0x74 t ├ +echo 0x75 u ┤ +echo 0x76 v ┴ +echo 0x77 w ┬ +echo 0x78 x │ +echo ┌─┬┐ +echo │ ││ +echo ├─┼┤ +echo └─┴┘ diff --git a/data/home/.local/bin/choose.ts b/data/home/.local/bin/choose.ts new file mode 100755 index 0000000..829754d --- /dev/null +++ b/data/home/.local/bin/choose.ts @@ -0,0 +1,6 @@ +#!/bin/env -S deno run + +const args = Deno.args; +const { floor, random } = Math; +const index = floor(random() * args.length); +console.log(args[index]); diff --git a/data/home/.local/bin/daemonize-thunar.sh b/data/home/.local/bin/daemonize-thunar.sh new file mode 100755 index 0000000..d8e296b --- /dev/null +++ b/data/home/.local/bin/daemonize-thunar.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +thunar --daemon diff --git a/data/home/.local/bin/defer.sh b/data/home/.local/bin/defer.sh new file mode 100755 index 0000000..829303e --- /dev/null +++ b/data/home/.local/bin/defer.sh @@ -0,0 +1,3 @@ +#!/bin/sh + + diff --git a/data/home/.local/bin/deno_quiet.sh b/data/home/.local/bin/deno_quiet.sh new file mode 100755 index 0000000..9bf819b --- /dev/null +++ b/data/home/.local/bin/deno_quiet.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sh -c 'echo "console.clear()"; cat' | deno diff --git a/data/home/.local/bin/enable_wol.sh b/data/home/.local/bin/enable_wol.sh new file mode 100755 index 0000000..474cc42 --- /dev/null +++ b/data/home/.local/bin/enable_wol.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +echo "done" > "/tmp/done.txt" + +set -e +sleep 15s + +function enable_wol_for() { + echo "[enable_wol] enabling wol on '$1'" + sudo ethtool -s $1 wol g + echo "[enable_wol] success" + sudo ethtool $1 | grep Wake-on +} + +for _ in $(seq 10) +do + ip link | grep enp | while read line; do + name=$(echo "$line" | cut -d ":" -f 2) + enable_wol_for "$name" + done + sleep 10s +done diff --git a/data/home/.local/bin/fix_cinnamon.sh b/data/home/.local/bin/fix_cinnamon.sh new file mode 100755 index 0000000..d6ab6fc --- /dev/null +++ b/data/home/.local/bin/fix_cinnamon.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pkill -HUP -f "cinnamon --replace" diff --git a/data/home/.local/bin/glava.sh b/data/home/.local/bin/glava.sh new file mode 100755 index 0000000..f2d1fa9 --- /dev/null +++ b/data/home/.local/bin/glava.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +glava -d diff --git a/data/home/.local/bin/kill-nemo-desktop.sh b/data/home/.local/bin/kill-nemo-desktop.sh new file mode 100755 index 0000000..799771b --- /dev/null +++ b/data/home/.local/bin/kill-nemo-desktop.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +killall nemo-desktop diff --git a/data/home/.local/bin/mk_vm.sh b/data/home/.local/bin/mk_vm.sh new file mode 100755 index 0000000..acb5fcd --- /dev/null +++ b/data/home/.local/bin/mk_vm.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +path=$1; +DISK_GB=4; +CPU_COUNT=8; +MEM_MB=2048; + +if [ $# -eq 0 ]; then + name="vm_$(date +%s)" + path="/tmp/$name" +fi + +echo "[mk_vm.sh] creating '$path'"; + +mkdir -p "$path"; +cd "$path"; + +if ! [ -f ./arch.iso ]; then + wget "http://archlinux.mirrors.ovh.net/archlinux/iso/latest/archlinux-x86_64.iso" -O "./arch.iso"; +fi + +if ! [ -f ./root.img ]; then + qemu-img create root.img "$DISK_GB"G; +fi + +# ARGS_GRAPHICS="-display egl-headless" +# ARGS_GRAPHICS="-nographic" + +ARGS="-drive file=root.img,format=raw -cdrom arch.iso -boot d -smp $CPU_COUNT -m $MEM_MB $ARGS_GRAPHICS" +screen -S vm qemu-system-x86_64 $ARGS; diff --git a/data/home/.local/bin/poupette.sh b/data/home/.local/bin/poupette.sh new file mode 100755 index 0000000..e624fe4 --- /dev/null +++ b/data/home/.local/bin/poupette.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +wget --quiet "https://poupette.barnulf.net/poupette.webp" -O "/tmp/poupette.webp" +convert "/tmp/poupette.webp" -resize 600x-1 "/tmp/poupette.jpg" +kitty +kitten icat "/tmp/poupette.jpg" diff --git a/data/home/.local/bin/prefix b/data/home/.local/bin/prefix deleted file mode 100755 index 540d58e..0000000 --- a/data/home/.local/bin/prefix +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -while read line -do echo "$@$line" -done diff --git a/data/home/.local/bin/prefix.ts b/data/home/.local/bin/prefix.ts new file mode 100755 index 0000000..0b7826d --- /dev/null +++ b/data/home/.local/bin/prefix.ts @@ -0,0 +1,33 @@ +#!/bin/env -S deno run + +import { crayon } from "https://deno.land/x/crayon@3.3.3/mod.ts"; + +async function read_line() { + const buf = new Uint8Array(1024); + const n = await Deno.stdin.read(buf); + if (n === null) return null; + const line = new TextDecoder().decode(buf.subarray(0, n)); + return line; +} + +function pick(arr: T[]) { + const index = Math.floor(arr.length * Math.random()); + return arr[index]; +} + +const [prefix] = Deno.args; +const colors = [ + crayon.red, + crayon.green, + crayon.blue, + crayon.yellow, + crayon.magenta, +]; +const color = pick(colors); + +while (true) { + let line = await read_line(); + if (line == null) break; + line = line.substring(0, line.length - 1); + console.log(`${color(`[${prefix}]`)} ${line}`); +} diff --git a/data/home/.local/bin/randomize_filename.ts b/data/home/.local/bin/randomize_filename.ts new file mode 100755 index 0000000..6963609 --- /dev/null +++ b/data/home/.local/bin/randomize_filename.ts @@ -0,0 +1,17 @@ +#!/bin/env -S deno run -A + +import { basename, dirname } from "https://deno.land/std@0.187.0/path/mod.ts"; + +const files = Deno.args; + +function rand_int(ceil = 1000) { + return Math.floor(Math.random() * ceil); +} + +const keyed = files.map((name) => ({ key: rand_int(files.length), name })); +keyed.sort(({ key: a }, { key: b }) => (a - b)); +await Promise.all(keyed.map(({ name }, index) => { + const dir = dirname(name); + const base = basename(name); + return Deno.rename(`${dir}/${base}`, `${dir}/${index}_${base}`); +})); diff --git a/data/home/.local/bin/reparer_discord.ts b/data/home/.local/bin/reparer_discord.ts new file mode 100755 index 0000000..9df5492 --- /dev/null +++ b/data/home/.local/bin/reparer_discord.ts @@ -0,0 +1,7 @@ +#!/usr/bin/env -S deno run -A --unstable + +const path = Deno.env.get("HOME") + "/.config/discord/settings.json" + +const config = JSON.parse(Deno.readTextFileSync(path)); +config["SKIP_HOST_UPDATE"] = true; +Deno.writeTextFileSync(path, JSON.stringify(config, null, 4)); diff --git a/data/home/.local/bin/screenshot.sh b/data/home/.local/bin/screenshot.sh new file mode 100755 index 0000000..30316d8 --- /dev/null +++ b/data/home/.local/bin/screenshot.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +name="screenshot-$(date +%s).png" +gnome-screenshot -a -f /tmp/$name +xclip -selection clipboard -t image/png -i /tmp/$name diff --git a/data/home/.local/bin/sdparams.ts b/data/home/.local/bin/sdparams.ts new file mode 100755 index 0000000..3a0a939 --- /dev/null +++ b/data/home/.local/bin/sdparams.ts @@ -0,0 +1,37 @@ +#!/bin/env -S deno run -A +import { crayon } from "https://deno.land/x/crayon@3.3.3/mod.ts"; +const [filename] = Deno.args; + +const args = [filename]; +const { stdout } = await new Deno + .Command("strings", { args, stdout: "piped" }) + .output(); +const strings = new TextDecoder().decode(stdout); + +let passed = false; +let rest = strings.split("\n").filter((l) => { + if (l === "IDATx") passed = true; + return !passed; +}).join("\n"); + +function split_once(text: string, sep: string) { + const [first, ...rest] = text.split(sep); + return [first, rest.join(sep)]; +} + +let _, prompt, negative, settings; +[_, rest] = split_once(rest, "parameters\n"); +[prompt, rest] = split_once(rest, "\nNegative prompt: "); +[negative, rest] = split_once(rest, "\nSteps: "); +[settings, _] = split_once(rest, "\nIDATx"); +settings = "Steps: " + settings; + +const pairs = settings.split(", ").map((p) => split_once(p, ": ")); + +for (const [key, value] of pairs) { + console.log(`${crayon.yellow.bold((key + ":").padEnd(12))} ${value}`); +} +console.log(`${crayon.yellow.bold("prompt:")} +${prompt} +${crayon.yellow.bold("negative:")} +${negative}`); diff --git a/data/home/.local/bin/start-rustdesk.sh b/data/home/.local/bin/start-rustdesk.sh new file mode 100755 index 0000000..2d2650c --- /dev/null +++ b/data/home/.local/bin/start-rustdesk.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +rustdesk diff --git a/data/home/.local/bin/start_corectrl.sh b/data/home/.local/bin/start_corectrl.sh new file mode 100755 index 0000000..7d91285 --- /dev/null +++ b/data/home/.local/bin/start_corectrl.sh @@ -0,0 +1,2 @@ +#!/bin/sh +corectrl --minimize-systray diff --git a/data/home/.local/bin/wait_pid.sh b/data/home/.local/bin/wait_pid.sh new file mode 100755 index 0000000..2316b36 --- /dev/null +++ b/data/home/.local/bin/wait_pid.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +tail --pid="${1}" -f /dev/null diff --git a/data/home/.zprofile b/data/home/.zprofile index 6e78177..6eacadd 100644 --- a/data/home/.zprofile +++ b/data/home/.zprofile @@ -83,13 +83,13 @@ alias "...."="../../.." alias "....."="../../../.." # edit default commands -alias ls=lsd +[ -f /usr/bin/lsd ] && alias ls=lsd alias bat="/usr/bin/bat --theme=ansi" -alias cat="bat --paging=never --style=snip" -alias cut=tuc -alias make="/usr/bin/make -j32" +[ -f /usr/bin/bat ] && alias cat="bat --paging=never --style=snip" +[ -f /usr/bin/tuc ] && alias cut=tuc +alias make="/usr/bin/make -j$(nproc)" alias mek=make -alias code="codium" +[ -f /usr/bin/codium ] && alias code="codium" alias untar="tar -xvf" alias paru="unset CARGO_TARGET_DIR; paru" alias pandoc="pandoc --pdf-engine=tectonic"