diff options
Diffstat (limited to '.local/share/bin')
| -rwxr-xr-x | .local/share/bin/= | 44 | ||||
| -rwxr-xr-x | .local/share/bin/brave | 7 | ||||
| -rwxr-xr-x | .local/share/bin/dbg | 40 | ||||
| -rwxr-xr-x | .local/share/bin/dox-open | 31 | ||||
| -rwxr-xr-x | .local/share/bin/editor | 2 | ||||
| -rwxr-xr-x | .local/share/bin/fontfix | 39 | ||||
| -rwxr-xr-x | .local/share/bin/labels2lrc | 22 | ||||
| -rwxr-xr-x | .local/share/bin/lrc2labels | 6 | ||||
| -rwxr-xr-x | .local/share/bin/mk | 15 | ||||
| -rwxr-xr-x | .local/share/bin/nginx-dev | 4 | ||||
| -rwxr-xr-x | .local/share/bin/preview | 4 | ||||
| -rwxr-xr-x | .local/share/bin/screenrecord | 6 | ||||
| -rwxr-xr-x | .local/share/bin/sdk10_compiledb | 38 | ||||
| -rwxr-xr-x | .local/share/bin/set-default | 32 |
14 files changed, 263 insertions, 27 deletions
diff --git a/.local/share/bin/= b/.local/share/bin/= index 59b9b45..8f3345d 100755 --- a/.local/share/bin/= +++ b/.local/share/bin/= @@ -1,2 +1,42 @@ -#!/bin/sh -python3 -c "from math import *; deg = pi / 180; print($*)" +#!/bin/python3 -- +from sys import argv as _argv +from os import environ as _environ, path as _path +from math import * + +_ans_path = _path.join(_environ["XDG_CACHE_HOME"], "calc_ans") +try: + _ans_file = open(_ans_path, "r+") +except: + _ans_file = open(_ans_path, "w+") +_exit_code = 0 + +ans = 0 +try: + _ans_str = _ans_file.read() + if "." in _ans_str: + ans = float(_ans_str) + else: + ans = int(_ans_str) +except: + pass + +deg = pi / 180 + +MIN = min +MAX = max +BIT = lambda n: 1 << n +GENMASK = lambda h, l: (BIT(MAX(h, l) + 1) - 1) ^ (BIT(MIN(h, l)) - 1) + +try: + ans = eval(" ".join(_argv[1:])) + print(ans) +except: + pass + +_ans_file.truncate(0) +_ans_file.seek(0) +_ans_file.write(str(ans)) +_ans_file.close() + +exit(_exit_code) + diff --git a/.local/share/bin/brave b/.local/share/bin/brave index 1dea360..5089377 100755 --- a/.local/share/bin/brave +++ b/.local/share/bin/brave @@ -1,8 +1,7 @@ #!/bin/sh -# the remote debugging is so brave can be hooked into by -# ~/.local/share/mode/reload.d/brave. this is probaby bad for security if -# you're not the only user on the system -# --remote-debugging-port=9222 \ +# - make brave automatically load the `mode` theme +# - don't use kwallet (i don't save passwords in chrome anyways) /usr/bin/brave \ --load-extension="$XDG_CACHE_HOME/mode/chromium" \ + --password-store=basic \ "$@" diff --git a/.local/share/bin/dbg b/.local/share/bin/dbg new file mode 100755 index 0000000..424110b --- /dev/null +++ b/.local/share/bin/dbg @@ -0,0 +1,40 @@ +#!/bin/sh +progname="$(basename "$(readlink -f "$0")")" +die() { + ec="$1" + shift + echo "$@" + exit "$ec" +} + +GDB="arm-none-eabi-gdb" + +[ $# -lt 1 ] && die 1 "usage: $progname DEVICE [gdb args...]" +DEVICE="$1" +shift + +if [ $# -eq 0 ] ; then + # automatically add --se flag if executable can be found + exec="$(find . -maxdepth 3 -name '*.elf' | head -n1)" + [ -n "$exec" ] && set -- --se="$exec" +fi + +[ -n "$(echo "$*" | grep -i zephyr)" ] && GDB="arm-zephyr-eabi-gdb" + +fork JLinkGDBServerCLExe \ + -device "$DEVICE" \ + -select USB \ + -endian little \ + -if SWD \ + -speed auto \ + -singlerun \ + -noir \ + -nologtofile \ + -silent + +# append startup attach command to args +set -- --eval-command="target extended-remote :2331" "$@" + +# launch gdb and forward any other args to it +exec "$GDB" "$@" + diff --git a/.local/share/bin/dox-open b/.local/share/bin/dox-open new file mode 100755 index 0000000..493c435 --- /dev/null +++ b/.local/share/bin/dox-open @@ -0,0 +1,31 @@ +#!/bin/node + +import { glob, readFile } from 'node:fs/promises'; +import { spawn } from 'node:child_process'; +import { argv, chdir, cwd } from 'node:process'; +import { join } from 'node:path'; + +argv.shift(); +argv.shift(); +chdir("search"); + +var symbols = {}; +for await (const chunk of glob('all_*.js')) { + const contents = await readFile(chunk); + const searchData = eval(`${contents}; searchData`); + const here = cwd(); + + for (const [ _id, [ symbol, ...entry ] ] of searchData) { + symbols[symbol] = entry.map(e => `file://${join(here, e[0])}`); + } +} + +for (const symbol of argv) { + if (!(symbol in symbols)) { + console.error(`No doxygen index for symbol \`${symbol}\``); + continue; + } + const urls = symbols[symbol]; + spawn('xdg-open', [ urls[0], ]); +} + diff --git a/.local/share/bin/editor b/.local/share/bin/editor new file mode 100755 index 0000000..d4bf664 --- /dev/null +++ b/.local/share/bin/editor @@ -0,0 +1,2 @@ +#!/bin/sh +exec nvim -p "$@" diff --git a/.local/share/bin/fontfix b/.local/share/bin/fontfix new file mode 100755 index 0000000..1c9beaf --- /dev/null +++ b/.local/share/bin/fontfix @@ -0,0 +1,39 @@ +#!/bin/python3 + +import os +import sys +from pathlib import Path + +from fontTools import ttLib + +PROPID_FAMILY = 1 +PROPID_SUBFAMILY = 2 +PROPID_FULLNAME = 4 +PROPID_PSNAME = 6 + +PLATFORM_MS = 1 +PLATFORM_MAC = 3 + +# see +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html +# for magic numbers + +for folder in Path(".").iterdir(): + print(f"{folder}/") + family_name = str(folder.stem) + for file in folder.glob("*.ttf"): + subfamily_name = file.stem.removeprefix(family_name).strip() + with ttLib.TTFont(file) as ttf: + nametable = ttf["name"] + full_name = f"{family_name} {subfamily_name}" + postscript_name = f"{family_name}-{subfamily_name}".replace(" ", "") + nametable.setName(family_name, PROPID_FAMILY, PLATFORM_MS, 0, 0) + nametable.setName(family_name, PROPID_FAMILY, PLATFORM_MAC, 1, 1033) + nametable.setName(subfamily_name, PROPID_SUBFAMILY, PLATFORM_MS, 0, 0) + nametable.setName(subfamily_name, PROPID_SUBFAMILY, PLATFORM_MAC, 1, 1033) + nametable.setName(full_name, PROPID_FULLNAME, PLATFORM_MS, 0, 0) + nametable.setName(full_name, PROPID_FULLNAME, PLATFORM_MAC, 1, 1033) + nametable.setName(postscript_name, PROPID_PSNAME, PLATFORM_MS, 0, 0) + nametable.setName(postscript_name, PROPID_PSNAME, PLATFORM_MAC, 1, 1033) + ttf.save(file) + print(f" {file.name}: [{family_name} :: {subfamily_name}]") diff --git a/.local/share/bin/labels2lrc b/.local/share/bin/labels2lrc index 1491dae..38630c1 100755 --- a/.local/share/bin/labels2lrc +++ b/.local/share/bin/labels2lrc @@ -1,13 +1,17 @@ -#!/bin/sh -cat "$@" |\ - awk ' +#!/bin/gawk -f BEGIN { FS = "\t" } { - seconds = $1 - minutes = int(seconds / 60) - seconds = seconds % 60 - millis = (seconds * 100) % 100 + time = $1 + time = gensub(/([0-9]+)\.([0-9]{,2})([0-9]*)/, "\\1\\2.\\3", "g", time) + time = int(time + 0.5) + + millis = time % 100 + time = int(time / 100) + + seconds = time % 60 + time = int(time / 60) + + minutes = time % 100 + printf("[%02d:%02d.%02d]%s\n", minutes, seconds, millis, $3) } -' - diff --git a/.local/share/bin/lrc2labels b/.local/share/bin/lrc2labels index 31aa4be..a23b299 100755 --- a/.local/share/bin/lrc2labels +++ b/.local/share/bin/lrc2labels @@ -1,11 +1,7 @@ -#!/bin/sh -cat "$@" |\ - gawk ' +#!/bin/gawk -f match($0, /^\[([0-9]{2}):([0-9]{2}\.[0-9]{2})\](.*)/, group) { time = group[1] * 60 + group[2] lyric = group[3] printf("%.2f\t%.2f\t%s\n", time, time, lyric) } -' - diff --git a/.local/share/bin/mk b/.local/share/bin/mk index b7e2b41..54b6908 100755 --- a/.local/share/bin/mk +++ b/.local/share/bin/mk @@ -1,6 +1,9 @@ #!/bin/sh progname="$(basename "$0")" showmode() { + ! [ -n "$FROM_PROMPT" ] && return + ! [ -t 1 ] && return + mode=" ($1)" col=$(( $(tput cols) - $(echo "$mode" | wc -L) + 1 )) printf '\e[1A\e['$col'G\e[1;30m%s\e[0m\n' "$mode" @@ -23,11 +26,17 @@ mode_cmake() { # re-run configuration if fresh or CMakeLists was changed if [ ! -e "$builddir/build.ninja" ] || - [ "CMakeLists.txt" -nt "$builddir/build.ninja" ] ; then - cmake --log-level WARNING -B "$builddir" + [ "CMakeLists.txt" -nt "$builddir/build.ninja" ] ; then + cmake --log-level WARNING -B "$builddir" fi - exec cmake --build "$builddir" -- "$@" + # build + cmake --build "$builddir" -- "$@" || exit $? + + # generate vim tags (continue after mk exits) + ninja -C "$builddir" -t deps | sed -n 's/^ \{4\}//p' | sort -u | ctags -L - -f "$builddir/tags" & + + exit 0 } [ -e "CMakeLists.txt" ] && mode_cmake "$@" diff --git a/.local/share/bin/nginx-dev b/.local/share/bin/nginx-dev index 10987fd..40e73ad 100755 --- a/.local/share/bin/nginx-dev +++ b/.local/share/bin/nginx-dev @@ -4,6 +4,8 @@ port=8080 try_files='/$uri /$uri.html /$uri/index.html =404' access_log='/dev/stdout' cache_control=' + proxy_store off; + proxy_cache off; add_header Last-Modified $date_gmt; add_header Cache-Control "private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; if_modified_since off; @@ -35,7 +37,7 @@ while getopts hvp:Ct:qx OPT; do p) port="$OPTARG" ;; t) try_files="$OPTARG" ;; v) print_config=1 ;; - C) cache_control="" ;; + C) cache_control='' ;; q) access_log="/dev/null" ;; x) open_browser=1 ;; \?|*) usage 1 ;; diff --git a/.local/share/bin/preview b/.local/share/bin/preview index 2fe9c4d..141d03c 100755 --- a/.local/share/bin/preview +++ b/.local/share/bin/preview @@ -12,6 +12,7 @@ MIMETYPE="$(file --mime-type -Lb "$FILE")" EXT="${FILE#*.}" [ "$EXT" = "md" ] && [ "$MIMETYPE" = "text/plain" ] && MIMETYPE="application/markdown" +[ "$MIMETYPE" = "application/javascript" ] && MIMETYPE="text/javascript" render_manpage() { exec groff -T utf8 -m man -rcR=1 -rIN=0 -rLL="${WIDTH}n" << EOF @@ -49,6 +50,9 @@ case "$MIMETYPE" in application/markdown) pandoc --from=gfm --to=man "$FILE" | render_manpage ;; + application/json) + jq --color-output . "$FILE" + ;; *) echo "$MIMETYPE" file -b "$FILE" | fold --width="$WIDTH" --spaces diff --git a/.local/share/bin/screenrecord b/.local/share/bin/screenrecord index d595cc8..1045a6e 100755 --- a/.local/share/bin/screenrecord +++ b/.local/share/bin/screenrecord @@ -1,8 +1,8 @@ #!/bin/sh exec giph "$@" \ - --framerate=60 \ + --framerate 60 \ --select \ - --bordersize=4 \ - --color=255,255,255 \ + --bordersize 4 \ + --color 255,255,255 \ "$(date +'%Y-%m-%d_%H-%M-%S.mp4')" diff --git a/.local/share/bin/sdk10_compiledb b/.local/share/bin/sdk10_compiledb new file mode 100755 index 0000000..6e62d47 --- /dev/null +++ b/.local/share/bin/sdk10_compiledb @@ -0,0 +1,38 @@ +#!/bin/python3 + +from shlex import split, join +from sys import argv +from os import getcwd +import subprocess + +process = subprocess.run(argv[1:], stdout=subprocess.PIPE, stderr=None, env={"LANG": "C"}) + +dir_stack = [getcwd()] +expanded_output = [] + +for line in process.stdout.decode('utf-8').split('\n'): + expanded_args = [] + args = split(line) + + if line.startswith('make: Entering directory'): + dir_stack.append(args[-1]) + expanded_output.append(line) + continue + if line.startswith('make: Leaving directory'): + dir_stack.pop() + expanded_output.append(line) + continue + + for arg in args: + if not arg.startswith('@'): + expanded_args.append(arg) + continue + with open(dir_stack[-1] + '/' + arg[1:], 'r') as file: + expanded_args += split(file.read()) + expanded_output.append(subprocess.list2cmdline(expanded_args)) + +process = subprocess.Popen(["compiledb"], stdin=subprocess.PIPE, stdout=None, stderr=None, text=True) +process.stdin.write("\n".join(expanded_output)) +process.stdin.close() +process.wait() + diff --git a/.local/share/bin/set-default b/.local/share/bin/set-default new file mode 100755 index 0000000..d93f65c --- /dev/null +++ b/.local/share/bin/set-default @@ -0,0 +1,32 @@ +#!/bin/sh +SCRIPT_NAME="$(basename "$0")" + +usage() { + code=0 + if [ -z "$1" ] ; then + cat << EOF +Set desktop entry ENTRY as default application for opening files with the same +type as FILE + +EOF + else + echo "error: $1" >&2 + code=1 + fi + cat << EOF +usage: + $SCRIPT_NAME ENTRY FILE [FILE] +EOF + exit $code +} + +[ $# -eq 0 ] && usage +DESKTOP_ENTRY="$1"; shift +[ -z "$DESKTOP_ENTRY" ] && usage "no desktop entry" +[ $# -lt 1 ] && usage "no reference file(s)" + +for file in "$@" ; do + mimetype="$(xdg-mime query filetype "$file")" + xdg-mime default "$DESKTOP_ENTRY" "$mimetype" +done + |