Skip to content

Instantly share code, notes, and snippets.

@LaptopDev
LaptopDev / showdef.sh
Created September 2, 2025 22:01
User/session definition resolver that prints shell definitions for aliases, functions, and exported variables.
showdef () { # Check if alias, function, or environment variable & print the definition
if alias "$1" &> /dev/null; then # alias?
alias "$1";
elif declare -f "$1" &> /dev/null; then # function?
declare -f "$1";
elif [ -n "${!1}" ]; then # environment variable? (no$)
echo "${!1}";
else
echo "No alias, function, or environment variable found for '$1'";
fi;
@LaptopDev
LaptopDev / calibfind.sh
Created September 2, 2025 21:51
Lists ebook matches in user's default calibre library by title and (with arg) path.
calibfind ()
{
local cmd;
local title;
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --h | -help | --help)
echo "Usage:";
echo " calibfind <title> # list ebook info by title";
echo " calibfind -path <title> # return space-delimited quoted file paths";
@LaptopDev
LaptopDev / OpenThing.lua
Created July 23, 2025 03:58
Open URL/File under cursor in normal mode w/o selection - Neovim
local function trim_edges(s)
return (s or ""):gsub("^%s+", ""):gsub("%s+$", "")
:gsub('^[\'"()<>%[%],]+', ""):gsub('[\'"()<>%[%],]+$', "")
end
local function stat(p) return vim.loop.fs_stat(p) end
function OpenThing()
local candidates = {
vim.fn.expand("<cfile>"),
vim.fn.expand("<cWORD>"),
}
@LaptopDev
LaptopDev / dump.sh
Created April 1, 2025 19:00
shell function for kitty to dump the pane screen content to new file to prevent overwrite
dump ()
{
local id="$1";
local dir="/tmp/pane_dump";
local base="pane";
local index=1;
local file;
if [ -z "$id" ]; then
echo "Usage: dump <pane-id>" 1>&2;
return 1;
@LaptopDev
LaptopDev / stitch.py
Created April 1, 2025 18:37
a python script to stitch together uncopyable ncurses buffer dumps
#This was made for stitching uncopyable ncurses buffers textdumped to files
#Expects correct ordering of input, i.e.: pane1, pane2, pane3, etc.
#Accepts UTF-8 plain text files There is no restriction on file extension, but
# dumpfile names must regex match by 'pane\d+'
#If a proceeding pane contains completely new content it will be appended in full and in order,
# ortherwise it will append only non-overlapping tail of the next pane, effectively deduplicating overlaps.
#!/usr/bin/env python3
import os
import re
@LaptopDev
LaptopDev / paneid_alias.sh
Last active April 1, 2025 20:09
current kitty window pane query shell alias
alias paneid='kitty @ ls | jq -r ".[] | .tabs[] | select(.is_active) | .windows[] | select(.is_focused) | .id"'
@LaptopDev
LaptopDev / log_last_opened.lua
Created March 23, 2025 04:10
log opened files in neovim
-- Log file opening to last_opened.txt
vim.api.nvim_create_autocmd("BufReadPost", {
callback = function()
local date = os.date("%b %d, %Y") -- Format the current date
local file_path = vim.fn.shellescape(vim.fn.expand("<afile>:p"))
os.execute(string.format("sed -i '1i%s' /home/user/.config/nvim/last_opened.txt", date .. " " .. file_path))
end,
})
@LaptopDev
LaptopDev / vtt-to-srt.lua
Created March 16, 2025 05:15
Convert youtube .vtt to .srt
local input_file = "tG1hCDXoE-I.en.vtt" -- Change this to your VTT file path
local output_file = "output.srt"
-- Define input and output file paths.
-- Read the entire VTT file into an array of lines.
local lines = {}
for line in io.lines(input_file) do
table.insert(lines, line)
end
@LaptopDev
LaptopDev / log_last_watched.lua
Last active March 27, 2025 21:35
Log MPV watch history
--https://chatgpt.com/c/67e44b59-292c-800b-80b6-3e6b1c609524
local mp = require("mp")
local utils = require("mp.utils")
local log_file = utils.join_path(os.getenv("HOME"), ".config/mpv/last_watched.txt")
-- Function to log current playback
local function log_last_watched()
local path = mp.get_property("path")
if not path then return end
@LaptopDev
LaptopDev / ocr.py
Last active November 5, 2023 17:21
Tesseract OCR with Grim - also accepts CL image paths as arguments
# Tesseract OCR ; process images as arguments to convert image to text
## .bashrc:
# alias catpic='python3 $home/scripts/ocr.py'
## keybind that I use in my hyprland configuration file:
# bind = SUPER, o, exec, grim -g "$(slurp)" - | python3 $home/scripts/ocr.py | wl-copy