Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
mikeslattery / briefmarks.lua
Last active March 18, 2024 14:18
which_key.nvim extension to limit how many marks are shown.
local M = {}
--
-- $HOME/.config/nvim/lua/which-key/plugins/briefmarks.lua
--
-- This extends which-key/plugins/marks.lua with these changes:
--
-- * Only show subset of marks
-- * Letters
-- * ^ . quote
@mikeslattery
mikeslattery / git-syncr
Last active February 25, 2024 20:23
Git Directory Synchronizer
#!/bin/bash
help() { cat<<HELP
git-syncr - git worktree synchronizer
Usage: git syncr <command>
COMMANDS:
create <path> [<branch>]
Create new worktree at <path> forked from current directory.
@mikeslattery
mikeslattery / gvim-ide-intg.md
Last active January 26, 2024 14:02
How to loosely integrate IdeaVim and gVim

This will allow you to switch between a Jetbrains IDE and gVim at the same file/line/column by hitting <leader>i. Hit <leader><leader>i to start gVim (once).

I've also done this with terminal Vim, but it's much more complex and varies depending on your environment (OS, DE, multiplexers, terminal).

Steps:

Install gVim and the IdeaVim plugin

In IDE: Settings > Build,Execution,Deployment > check "Allow unsigned requests"

@mikeslattery
mikeslattery / webcam2html.sh
Last active November 16, 2023 21:11
AI Webcam to html
#!/bin/bash
# Takes a photo and converts to a project text artifact.
# Just experimental for now.
set -euo pipefail
THISDIR="$(dirname "$0")"
#shellcheck disable=SC1091
source "$THISDIR/.env"
@mikeslattery
mikeslattery / ssh2config.sh
Last active April 27, 2023 12:11
Convert shell history or CLI args into ~/.ssh/config format.
#!/bin/bash
ssh2append() {
ssh -G "$@" | sed -n 's/^hostname /Host /p'
comm -23 <(ssh -G "$@" 2>/dev/null | sort) <(ssh -G . 2>/dev/null | sort) | sed 's/^/ /'
# This loop+if is for remote command, -N, -W as -G lacks support
while getopts '1246AaCfGgKkMNnqsTtVvXxYyB:b:c:D:E:e:F:I:i:J:L:l:m:O:o:p:Q:R:S:W:w:' opt; do
#shellcheck disable=SC2254
case "$opt" in
docker system df
df -h
# Delete builds and workspaces more 6+ months old
find /var/lib/jenkins/jobs -maxdepth 6 -mtime +180 -name build.xml -print0 | xargs -0 -I{} dirname {} | xargs -d '\n' -r rm -rf
find /var/lib/jenkins/jobs -maxdepth 3 -mtime +180 -name workspace -print0 | xargs -0 -r rm -rf
# Stop containers running more than 2 days, except Jenkins
docker ps | grep -E 'days|weeks|months' | grep -Ev "$(hostname)|CONTAINER" | awk '{ print $1; }' | xargs -r docker stop
@mikeslattery
mikeslattery / .vimrc
Last active February 23, 2023 20:19
Beginner's Minimal Vim Config
" This is a beginners .vimrc or init.vim file
" with sane defaults so you can be productive at the start.
" Not designed to work with Neovim.
" Sane defaults.
source $VIMRUNTIME/defaults.vim
set mouse=a " Enable mouse
set clipboard+=unnamed,unnamedplus " Use desktop's clipboard
set hidden " Allow switch buffers if current not saved
set noswapfile autoread " Swap file annoyance. Use git.
@mikeslattery
mikeslattery / x-platform.sh
Last active January 30, 2023 15:44
Cross Platform Bash Snippet for Linux, WSL 1, Cygwin, Msys, and GitBash.
#!/bin/bash
# shebang added only to appease shellcheck
# Cross-platform for bash.
# Worry less about when writting a script that must run on Windows and Linux.
# Meant to be used with "source" command in scripts or .bashrc/.zshrc
export USER="${USER:-${USERNAME:-$(whoami)}}"
export USERNAME="${USERNAME:-$USER}"
export HOSTNAME="${HOSTNAME:-${MACHINENAME:-$(hostname)}}"
@mikeslattery
mikeslattery / clone_to_docker.sh
Last active February 23, 2022 17:24
Convert local Linux distro into a container.
#!/bin/bash
# Usage - clone_to_docker.sh <image-name>
# This will convert the local distro to a container image and run it.
# Also works for WSL.
# The container will run as the user that created the image.
# If using WSL, you should mount (or symlink) /c to /mnt/c
image="wsl"
@mikeslattery
mikeslattery / runimage.sh
Last active January 13, 2022 16:51
Run containers as if they are locally installed tools
#!/bin/bash
# Run containers as if they are locally installed tools.
# This is useful for images such as "python" or "maven".
# Edit the "image" variable and place in your ~/bin directory.
# For "Docker Desktop for Windows" under these environments:
# * WSL: if /c is mounted to C: and run from a dir under /c, but /tmp and $HOME volumes should be removed.
# * Msys/GitBash: but /tmp volume should be removed.
# * Cygwin: Will not work as-is due to path differences.