Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / grepfind.vim
Last active January 19, 2026 15:43
Set &grepprg / &findfunc to git-grep / git-ls-files inside repo and fall back rg, ugrep or grep / fd, ... outside of it
" Set &grepprg to git-grep inside repo, fall back rg, ugrep or grep otherwise.
" Assumes a global ignore file `$XDG_CONFIG_HOME/grep/ignore`; create it by,
" say `touch ~/.config/grep/ignore` to ensure its existence.
augroup vimrcFindGrep
autocmd!
augroup END
if has('unix') && executable('chrt') && executable('ionice')
let s:scheduler = 'chrt --idle 0 ionice -c2 -n7 '
@Konfekt
Konfekt / fzf.vim
Last active December 28, 2025 18:46
A command using FZF that takes a range to list only those files altered in last <range> commits
" A command using FZF to list all files in a Git repo;
" takes a range 0, N or N,M to restrict to files that have been, respectively,
" altered, altered in last N commits, altered in-between last N and M commits.
" From https://github.com/junegunn/fzf.vim/blob/879db51d0965515cdaef9b7f6bdeb91c65d2829e/autoload/fzf/vim.vim#L742
function! s:get_git_root(dir)
if empty(a:dir) && exists('*FugitiveWorkTree')
return FugitiveWorkTree()
endif
let dir = len(a:dir) ? a:dir : substitute(split(expand('%:p:h'), '[/\\]\.git\([/\\]\|$\)')[0], '^fugitive://', '', '')
@Konfekt
Konfekt / aegis2pass.py
Created December 28, 2025 07:52
Import Android Aegis authenticator (encrypted) JSON export to pass; superseded by pass-import but left as stand-alone tool here
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "cryptography>=42",
# ]
# [tool.uv]
# exclude-newer = "2025-12-26 00:00"
# ///
@Konfekt
Konfekt / select-pass.md
Last active December 26, 2025 19:21
passy: pastes anywhere passwords managed by password-store selected from a fuzzy finder menu
@Konfekt
Konfekt / pyrefly_operator.vim
Created December 25, 2025 18:15
check Python code snippets on the fly with pyrefly
" Check Python code snippets on the fly with pyrefly.
" Put into ~/.vim/plugins` and use the mapping `g4` on a visual selection or a text object.
if exists('g:loaded_pyrefly_operator') | finish | endif
let g:loaded_pyrefly_operator = 1
if !executable('pyrefly') | finish | endif
let s:pyrefly_efm = join([
\ '%E%\s%#ERROR %m',
@Konfekt
Konfekt / mailcap
Last active December 25, 2025 10:47
mailcap file to display files in and outside of terminal for mutt, less, ranger / lf, ..
# Save as ~/.mailcap. Then use run-mailcap to:
#
# - open files by `run-mailcap --action=view <file>`, or
# - view them in the terminal by `run-mailcap --action=cat <file>`.
#
# Useful
#
# - in mutt by `set mailcap_file $HOME/.mailcap`
# - in Vim by adding to your vimrc
#
@Konfekt
Konfekt / c_compdb.vim
Last active December 24, 2025 02:05
Automatically generate compile_commands.json for clangd Language Server in Vim; put into ~/.vim/ftplugin/
" Generate compile_commands.json for clangd.
" Prefer CMake export, else Ninja compdb, else Bear + Make with optional append:
" First check is whether need for (re)generation be at all, then where relative
" to the open file, then calling CMake, Ninja, or finally Bear if applicable (as
" background jobs). To make those builders work more predictably, additional
" flags are passed to ensure all files are indexed as, say, `bear -- make` falls
" short in presence of build artifacts.
if exists('b:did_c_compdb_ftplugin') | finish | endif
let b:did_c_compdb_ftplugin = 1
@Konfekt
Konfekt / git-multihook.sh
Last active December 1, 2025 16:37
use global git hooks as fallback to local hooks
#!/usr/bin/env bash
#
# Adaption of https://github.com/majutsushi/etc/commit/e62904088c698e064c17522d54dff91b629ee253#diff-53b7e445a85984949f551c277d4cc4ee9682287cb234e075e6d352be887e7494
# with https://github.com/pivotal-cf/git-hooks-core/blob/master/.base-hook
#
# This script is meant to be put into a directory pointed to by core.hooksPath
# in Git 2.9.
# Then for each hook you want to support, create a symlink "hookname -> multihook"
# and optionally a directory "hookname.d" where you can put all scripts for
# that hook
@Konfekt
Konfekt / RunOrRaise.ahk
Last active November 25, 2025 06:22
Autohotkey v2 Script to Run or Raise application using Shortcut
; Run or Raise Application using Shortcut
; From https://gist.github.com/dewaka/c494543b4cd2a2dcd09cc5a6aa0f7517 adapted to ah2
RunOrRaise(exePath, winID:="") {
if (winID == "") {
exeName := SubStr(exePath, InStr(exePath, "\", , -1)+1)
winID := "ahk_exe " . exeName
}
If not WinExist(winID) {
UserProfile := EnvGet("USERPROFILE")
@Konfekt
Konfekt / wacom2monitor.sh
Last active November 11, 2025 09:30
A shell script to map all Wacom devices to a given monitor, in particular to switch through all available monitors by repeatedly calling it with the parameter NEXT
#!/usr/bin/env bash
# exit on error or on use of undeclared variable or pipe error:
set -o errexit -o errtrace -o nounset -o pipefail
# optionally debug output by supplying TRACE=1
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
# Bash 4.4+ supports inherit_errexit; this improves error handling in functions and subshells. If unavailable, ignore.
shopt -s inherit_errexit 2>/dev/null || true
PS4='+\t '