3 Commits

Author SHA1 Message Date
Claude
7444f5b97b Remove pointless exports from ssh/rc, add process-model comment
ssh/rc runs as a sshd child process so exports never reach the user's
shell. SSH_REMOTE_AUTH_SOCK was set and exported but never used (a
leftover from a prior failed fix attempt). SSH_AUTH_SOCK was reassigned
to the symlink path and exported, also to no effect. Remove both.

https://claude.ai/code/session_01RhXaFzxJA5D2BcGcz18ipA
2026-04-19 02:19:05 +00:00
Claude
c5e1157f47 Fix shenv clobbering forwarded SSH socket with local agent in tmux
ssh/rc env changes (including SSH_REMOTE_AUTH_SOCK) are lost because
ssh/rc runs as a sshd child process, not the user's shell. The shell
always receives SSH_AUTH_SOCK set to the raw forwarded socket path.

Fresh SSH login worked fine (step 1 catches the raw socket). The bug
was in tmux new windows: SSH_AUTH_SOCK there is our stable symlink, so
step 1 fails, then steps 2/3 look up the system agent and overwrite the
symlink that ssh/rc just set to the forwarded socket.

Fix: only run the system agent lookup when the stable symlink is already
broken. A valid symlink means ssh/rc (or a previous shenv run) already
set it correctly; don't clobber it.

https://claude.ai/code/session_01RhXaFzxJA5D2BcGcz18ipA
2026-04-19 01:47:36 +00:00
Claude
6b50be84a9 Fix SSH agent forwarding clobbered by local agent in shenv
ssh/rc saves the raw forwarded socket in SSH_REMOTE_AUTH_SOCK before
rewriting SSH_AUTH_SOCK to the stable symlink. shenv was ignoring that
variable, so it saw SSH_AUTH_SOCK as "our link" and fell through to the
systemd lookup, which could overwrite the symlink with a local agent
socket and silently drop the forwarded one.

Now shenv checks SSH_REMOTE_AUTH_SOCK first, giving forwarded sockets
priority over any local agent.

https://claude.ai/code/session_01RhXaFzxJA5D2BcGcz18ipA
2026-04-19 01:43:12 +00:00
44 changed files with 144 additions and 1074 deletions

View File

@@ -1,7 +1,5 @@
tap "dart-lang/dart", trusted: true tap "dart-lang/dart"
tap "espressif/eim" tap "sass/sass"
tap "holtwick/tap"
tap "sass/sass", trusted: true
brew "ack" brew "ack"
brew "acme.sh" brew "acme.sh"
@@ -10,50 +8,37 @@ brew "autoconf"
brew "automake" brew "automake"
brew "b2-tools" brew "b2-tools"
brew "bat" brew "bat"
brew "bazelisk"
brew "binwalk" brew "binwalk"
brew "cask" brew "cask"
brew "ccache" brew "ccache"
brew "certbot" brew "certbot"
brew "cloudflared"
brew "cmake" brew "cmake"
brew "colima" brew "colima"
brew "devcontainer" brew "devcontainer"
brew "dfu-util" brew "dfu-util"
brew "difftastic" brew "difftastic"
brew "direnv" brew "direnv"
brew "dua-cli"
brew "duck" brew "duck"
brew "dust"
brew "earthly" brew "earthly"
brew "espressif/eim/eim", trusted: true
brew "esptool" brew "esptool"
brew "fish"
brew "fq"
brew "gh" brew "gh"
brew "ghidra", link: false brew "ghidra", link: false
brew "git" brew "git"
brew "git-delta" brew "git-delta"
brew "git-lfs" brew "git-lfs"
brew "glib"
brew "gnupg" brew "gnupg"
brew "go" brew "go"
brew "gradle" brew "gradle"
brew "hashcat"
brew "hf" brew "hf"
brew "holtwick/tap/bx", trusted: true
brew "htop" brew "htop"
brew "httpie" brew "httpie"
brew "huggingface-cli"
brew "hugo" brew "hugo"
brew "imagemagick" brew "imagemagick"
brew "john-jumbo" brew "john-jumbo"
brew "jq" brew "jq"
brew "kubeconform"
brew "kubectx"
brew "libgcrypt"
brew "librsvg"
brew "libslirp"
brew "lima" brew "lima"
brew "minikube"
brew "mise" brew "mise"
brew "mosh" brew "mosh"
brew "neovim" brew "neovim"
@@ -63,27 +48,22 @@ brew "ollama"
brew "p7zip" brew "p7zip"
brew "pipenv" brew "pipenv"
brew "pipx" brew "pipx"
brew "pixman"
brew "pkgconf" brew "pkgconf"
brew "protobuf" brew "protobuf"
brew "pwgen" brew "pwgen"
brew "pwntools" brew "pwntools"
brew "python@3.13"
brew "python@3.14"
brew "qemu" brew "qemu"
brew "restic" brew "restic"
brew "ripgrep" brew "ripgrep"
brew "ruby", link: false brew "ruby"
brew "ruby@3.3" brew "ruby@3.3"
brew "rustup" brew "rustup"
brew "sass/sass/migrator" brew "sass/sass/migrator"
brew "sass/sass/sass" brew "sass/sass/sass"
brew "sdl2"
brew "shellcheck" brew "shellcheck"
brew "smartmontools" brew "smartmontools"
brew "starship" brew "starship"
brew "tmux" brew "tmux"
brew "todoist-cli"
brew "uv" brew "uv"
brew "virtualenvwrapper" brew "virtualenvwrapper"
brew "wget" brew "wget"
@@ -92,7 +72,6 @@ brew "zlib"
brew "zsh-syntax-highlighting" brew "zsh-syntax-highlighting"
cask "codeql" cask "codeql"
cask "codex"
cask "cyberduck" cask "cyberduck"
cask "font-fira-code-nerd-font" cask "font-fira-code-nerd-font"
cask "font-fira-mono-nerd-font" cask "font-fira-mono-nerd-font"
@@ -114,7 +93,6 @@ cask "rectangle"
cask "scroll-reverser" cask "scroll-reverser"
cask "temurin" cask "temurin"
cask "veracrypt" cask "veracrypt"
cask "wezterm"
cask "zulu@17" cask "zulu@17"
def is_corp? def is_corp?
@@ -122,21 +100,13 @@ def is_corp?
`profiles status -type enrollment 2>/dev/null`.include?("Enrolled via DEP: Yes") `profiles status -type enrollment 2>/dev/null`.include?("Enrolled via DEP: Yes")
end end
if is_corp?
brew "bazelisk", link: false
end
# non-corp # non-corp
if !is_corp? if !is_corp?
brew "bazelisk" brew "bazel"
brew "openssh" brew "openssh"
brew "virt-manager"
cask "claude-code" cask "claude-code"
cask "cryptomator" cask "cryptomator"
cask "keepassxc"
cask "gcloud-cli" cask "gcloud-cli"
cask "keybase" cask "google-cloud-sdk"
cask "orbstack" cask "orbstack"
cask "jordanbaird-ice@beta"
end end

View File

@@ -12,17 +12,8 @@ fi
trap "test -f ${FILENAME} && rm -f ${FILENAME}" EXIT trap "test -f ${FILENAME} && rm -f ${FILENAME}" EXIT
IOENGINE="libaio"
DIRECT=1
if [ "$(uname)" = "Darwin" ]; then
IOENGINE="posixaio"
# macOS doesn't support O_DIRECT in the same way, but fio's direct=1
# handles it via F_NOCACHE if supported.
DIRECT=1
fi
fio --loops=5 --size=${BENCHMARK_SIZE} --filename=${FILENAME} \ fio --loops=5 --size=${BENCHMARK_SIZE} --filename=${FILENAME} \
--stonewall --ioengine=${IOENGINE} --direct=${DIRECT} \ --stonewall --ioengine=libaio --direct=1 \
--name=Seqread --bs=1m --rw=read \ --name=Seqread --bs=1m --rw=read \
--name=Seqwrite --bs=1m --rw=write \ --name=Seqwrite --bs=1m --rw=write \
--name=512Kread --bs=512k --rw=randread \ --name=512Kread --bs=512k --rw=randread \

View File

@@ -1,10 +1,6 @@
#!/bin/bash #!/bin/bash
CHROME_BINS="google-chrome-beta google-chrome" CHROME_BINS="google-chrome-beta google-chrome"
if [ "$(uname)" = "Darwin" ]; then
CHROME_BINS="${CHROME_BINS} /Applications/Google\ Chrome\ Beta.app/Contents/MacOS/Google\ Chrome\ Beta /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
fi
for bin in ${CHROME_BINS} ; do for bin in ${CHROME_BINS} ; do
if command -v ${bin} >/dev/null 2>&1 ; then if command -v ${bin} >/dev/null 2>&1 ; then
CHROME=$(command -v ${bin}) CHROME=$(command -v ${bin})
@@ -22,4 +18,4 @@ export HOME=${HOME}/.chrome-pentest
mkdir -p ${HOME} mkdir -p ${HOME}
# Launch chrome for burp # Launch chrome for burp
exec "${CHROME}" --user-data-dir=${HOME}/chrome-pentest --proxy-server=127.0.0.1:8080 exec ${CHROME} --user-data-dir=${HOME}/chrome-pentest --proxy-server=127.0.0.1:8080

View File

@@ -251,13 +251,7 @@ def main(args):
if last_type and e.pkg_type != last_type: if last_type and e.pkg_type != last_type:
output_lines.append("") output_lines.append("")
last_type = e.pkg_type last_type = e.pkg_type
output_lines.extend(e.to_lines())
lines = e.to_lines()
# If we just added a blank line, and the new lines start with one, skip the first new line
if output_lines and output_lines[-1] == "" and lines and lines[0] == "":
output_lines.extend(lines[1:])
else:
output_lines.extend(lines)
new_content = "\n".join(output_lines) new_content = "\n".join(output_lines)
if footer: if footer:

View File

@@ -1,212 +0,0 @@
#!/usr/bin/env bash
# Exit on error, undefined variables, and pipe failures
set -euo pipefail
show_help() {
cat << EOF
Usage: $(basename "$0") [options] <note_name_or_path>
Create a new note in your Obsidian vault.
Options:
-v, --vault <dir> Specify the Obsidian vault directory.
--overwrite Overwrite the file if it already exists.
-h, --help Show this help message.
EOF
}
VAULT_DIR=""
OVERWRITE="false"
NOTE_PATH=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--vault)
if [[ -z "${2:-}" ]]; then
echo "Error: --vault requires a directory path." >&2
exit 1
fi
VAULT_DIR="$2"
shift 2
;;
--overwrite)
OVERWRITE="true"
shift
;;
-h|--help)
show_help
exit 0
;;
-*)
echo "Error: Unknown option: $1" >&2
show_help
exit 1
;;
*)
if [[ -n "$NOTE_PATH" ]]; then
echo "Error: Multiple note paths provided: $NOTE_PATH and $1" >&2
exit 1
fi
NOTE_PATH="$1"
shift
;;
esac
done
if [[ -z "$NOTE_PATH" ]]; then
echo "Error: Missing note path/name." >&2
show_help
exit 1
fi
# 1. Find the Obsidian vault.
if [[ -n "$VAULT_DIR" ]]; then
# -v/--vault was passed. Check that the directory exists and contains a .obsidian directory.
if [[ ! -d "$VAULT_DIR" ]]; then
echo "Error: Specified vault directory does not exist: $VAULT_DIR" >&2
exit 1
fi
if [[ ! -d "$VAULT_DIR/.obsidian" ]]; then
echo "Error: Specified directory is not an Obsidian vault (missing .obsidian): $VAULT_DIR" >&2
exit 1
fi
VAULT_DIR="$(cd "$VAULT_DIR" && pwd)"
else
# Search directories upward for a parent (or current) directory containing a .obsidian subdirectory.
# Stop at the user's home directory or a filesystem boundary.
CURRENT_DIR="$PWD"
FOUND_VAULT=""
get_device_id() {
local dir="$1"
if [[ "$(uname)" == "Darwin" ]]; then
stat -f '%d' "$dir" 2>/dev/null || echo ""
else
stat -c '%d' "$dir" 2>/dev/null || echo ""
fi
}
CURRENT_DEV="$(get_device_id "$CURRENT_DIR")"
while [[ "$CURRENT_DIR" != "/" && "$CURRENT_DIR" != "$HOME" ]]; do
if [[ -d "$CURRENT_DIR/.obsidian" ]]; then
FOUND_VAULT="$CURRENT_DIR"
break
fi
PARENT_DIR="$(dirname "$CURRENT_DIR")"
if [[ "$PARENT_DIR" == "$CURRENT_DIR" ]]; then
break
fi
# Check filesystem boundary
PARENT_DEV="$(get_device_id "$PARENT_DIR")"
if [[ -n "$CURRENT_DEV" && -n "$PARENT_DEV" && "$CURRENT_DEV" != "$PARENT_DEV" ]]; then
break
fi
CURRENT_DIR="$PARENT_DIR"
CURRENT_DEV="$PARENT_DEV"
done
# Check the last checked directory (could be HOME or /)
if [[ -z "$FOUND_VAULT" && -d "$CURRENT_DIR/.obsidian" ]]; then
FOUND_VAULT="$CURRENT_DIR"
fi
if [[ -n "$FOUND_VAULT" ]]; then
VAULT_DIR="$FOUND_VAULT"
else
# Fallback paths in order: ~/Notes, ~/Obsidian/Notes, ~/Personal/Notes, ~/Projects/Notes.
FALLBACKS=(
"$HOME/Notes"
"$HOME/notes"
"$HOME/Obsidian/Notes"
"$HOME/Obsidian/notes"
"$HOME/Personal/Notes"
"$HOME/Personal/notes"
"$HOME/Projects/Notes"
"$HOME/Projects/notes"
)
for path in "${FALLBACKS[@]}"; do
if [[ -d "$path" && -d "$path/.obsidian" ]]; then
VAULT_DIR="$(cd "$path" && pwd)"
break
fi
done
fi
fi
if [[ -z "$VAULT_DIR" ]]; then
echo "Error: Could not find an Obsidian vault. Please specify one with -v/--vault." >&2
exit 1
fi
# Strip leading slash from NOTE_PATH to handle relative paths properly
NOTE_PATH="${NOTE_PATH#/}"
# 2. Determine if current working directory is within the vault.
# Resolve physical paths to handle symlinks cleanly.
RESOLVED_PWD="$(pwd -P)"
RESOLVED_VAULT="$(cd "$VAULT_DIR" && pwd -P)"
if [[ "$RESOLVED_PWD" == "$RESOLVED_VAULT" || "$RESOLVED_PWD" == "$RESOLVED_VAULT"/* ]]; then
# Within the vault, treat relative to CWD
TARGET_FILE="$PWD/$NOTE_PATH"
else
# Not within the vault, treat relative to vault root
TARGET_FILE="$VAULT_DIR/$NOTE_PATH"
fi
TARGET_DIR="$(dirname "$TARGET_FILE")"
TARGET_BASE="$(basename "$TARGET_FILE")"
# If there's no file extension on the argument, add .md.
if [[ "$TARGET_BASE" != *.* ]]; then
TARGET_BASE="$TARGET_BASE.md"
fi
TARGET_FILE="$TARGET_DIR/$TARGET_BASE"
# If the necessary directory components don't exist, create them.
if [[ ! -d "$TARGET_DIR" ]]; then
mkdir -p "$TARGET_DIR"
fi
# 3. If the file exists and there's no --overwrite argument, throw an error.
if [[ -f "$TARGET_FILE" && "$OVERWRITE" != "true" ]]; then
echo "Error: File already exists: $TARGET_FILE (use --overwrite to replace it)" >&2
exit 1
fi
# 4. If the path ends in .md (case-insensitive), generate appropriate YAML front matter and write it to the new file.
if [[ "${TARGET_BASE,,}" == *.md ]]; then
NOTE_TITLE="${TARGET_BASE%.*}"
CURRENT_DATE="$(date +"%Y-%m-%d %H:%M")"
cat << EOF > "$TARGET_FILE"
---
title: "$NOTE_TITLE"
date: $CURRENT_DATE
tags: []
---
EOF
else
# Just touch the file to ensure it exists
touch "$TARGET_FILE"
fi
# 5. Open the user's $EDITOR (falling back to vim/vi if unset) pointing to the new file.
EDITOR="${EDITOR:-}"
if [[ -z "$EDITOR" ]]; then
if command -v vim >/dev/null 2>&1; then
EDITOR="vim"
else
EDITOR="vi"
fi
fi
exec "$EDITOR" "$TARGET_FILE"

View File

@@ -1,63 +0,0 @@
#!/bin/bash
set -euo pipefail
# QUARTZ_DIR search logic
if [ -z "${QUARTZ_DIR:-}" ]; then
if [ -f "quartz.config.ts" ]; then
QUARTZ_DIR="$PWD"
elif [ -d "$HOME/Personal/notes-quartz" ]; then
QUARTZ_DIR="$HOME/Personal/notes-quartz"
elif [ -d "$HOME/Projects/notes-quartz" ]; then
QUARTZ_DIR="$HOME/Projects/notes-quartz"
else
echo "Error: QUARTZ_DIR could not be found." >&2
exit 1
fi
fi
if [ ! -d "$QUARTZ_DIR" ]; then
echo "Error: QUARTZ_DIR '$QUARTZ_DIR' is not a directory." >&2
exit 1
fi
# NOTES_DIR search logic
PARSE_NOTES_DIR=""
# Use a copy of args to find -d/--directory
ARGS=("$@")
for ((i=0; i<${#ARGS[@]}; i++)); do
if [[ "${ARGS[i]}" == "-d" || "${ARGS[i]}" == "--directory" ]]; then
if [[ $((i+1)) -lt ${#ARGS[@]} ]]; then
PARSE_NOTES_DIR="${ARGS[i+1]}"
fi
break
fi
done
if [ -n "$PARSE_NOTES_DIR" ]; then
NOTES_DIR="$PARSE_NOTES_DIR"
elif [ -z "${NOTES_DIR:-}" ]; then
if [ -d "$HOME/Notes" ]; then
NOTES_DIR="$HOME/Notes"
elif [ -d "$HOME/Personal/notes" ]; then
NOTES_DIR="$HOME/Personal/notes"
elif [ -d "$HOME/Projects/notes" ]; then
NOTES_DIR="$HOME/Projects/notes"
else
echo "Error: NOTES_DIR could not be found." >&2
exit 1
fi
fi
if [ ! -d "$NOTES_DIR" ]; then
echo "Error: NOTES_DIR '$NOTES_DIR' is not a directory." >&2
exit 1
fi
cd "$QUARTZ_DIR"
# Run npx quartz
# Following the prompt's structure but using NOTES_DIR for the flag
# npx quartz ${argv[1]} --directory ${NOTES_DIR} "$@"
# We use ${1:-} for argv[1] to handle cases with no arguments.
npx quartz "${1:-}" --directory "$NOTES_DIR" "$@"

View File

@@ -18,7 +18,7 @@ HOST_SPECIFIC_SCRIPT="${RESTIC_SCRIPTS_DIR}/${HOSTNAME}"
# Check if the script exists and is executable # Check if the script exists and is executable
if [[ -f "${HOST_SPECIFIC_SCRIPT}" && -x "${HOST_SPECIFIC_SCRIPT}" ]]; then if [[ -f "${HOST_SPECIFIC_SCRIPT}" && -x "${HOST_SPECIFIC_SCRIPT}" ]]; then
echo "Executing restic script for hostname: ${HOSTNAME}" echo "Executing restic script for hostname: ${HOSTNAME}"
"${HOST_SPECIFIC_SCRIPT}" "$@" "${HOST_SPECIFIC_SCRIPT}"
else else
echo "Error: No executable restic script found for hostname '${HOSTNAME}' at '${HOST_SPECIFIC_SCRIPT}'." >&2 echo "Error: No executable restic script found for hostname '${HOSTNAME}' at '${HOST_SPECIFIC_SCRIPT}'." >&2
echo "Please create an executable script at that path if you want to use this functionality." >&2 echo "Please create an executable script at that path if you want to use this functionality." >&2

View File

@@ -5,14 +5,8 @@
set -ue set -ue
TOOLS="flameshot scrot" TOOLS="flameshot scrot"
if [ "$(uname)" = "Darwin" ]; then
TOOLS="screencapture ${TOOLS}"
fi
SCREENDIR=${SCREENDIR:-${HOME}/Pictures/Screenshots} SCREENDIR=${SCREENDIR:-${HOME}/Pictures/Screenshots}
SCROT_FORMAT="%F-%T.png" SCROT_FORMAT="%F-%T.png"
# Filename for screencapture
FILE_NAME=$(date "+%Y-%m-%d-%H%M%S.png")
function default_screenshot_command { function default_screenshot_command {
for tool in ${TOOLS} ; do for tool in ${TOOLS} ; do
@@ -47,29 +41,10 @@ function scrot_full_capture {
scrot "${SCREENDIR}/${SCROT_FORMAT}" scrot "${SCREENDIR}/${SCROT_FORMAT}"
} }
function mac_capture {
local mode="${1}"
local target="${SCREENDIR}/${FILE_NAME}"
case "${mode}" in
region)
screencapture -i "${target}"
;;
window)
screencapture -i -w "${target}"
;;
full)
screencapture "${target}"
;;
esac
}
case "${CMD}" in case "${CMD}" in
region|window|full) region|window|full)
mkdir -p "${SCREENDIR}" mkdir -p "${SCREENDIR}"
case "${TOOL}" in case "${TOOL}" in
screencapture)
mac_capture "${CMD}"
;;
flameshot) flameshot)
case "${CMD}" in case "${CMD}" in
region|window) region|window)

View File

@@ -1,310 +0,0 @@
#!/usr/bin/env bash
# update-authorized-keys - Manage ~/.ssh/authorized_keys from multiple sources
#
# BEHAVIOR:
# 1. Collects SSH public keys from one or more source directories (default: ~/.ssh/authorized_keys.d).
# 2. Skips empty files and files symlinked to /dev/null (masking).
# 3. Deterministically concatenates keys into a "managed block" wrapped in markers:
# # BEGIN UPDATE-AUTHORIZED-KEYS
# # END UPDATE-AUTHORIZED-KEYS
# 4. Deduplicates managed keys: if the same key (including options) is found in multiple files,
# it is included once with a comment listing all source filenames.
# 5. Preserves "manual" keys found in the target file outside the markers.
# 6. Removes manual keys that exactly match a managed key (options + key data).
# 7. Validates every proposed key individually using 'ssh-keygen -l -f'.
# 8. Optionally validates the whole file with 'authorized-keys-test' if available.
# 9. Displays a unified diff and prompts for confirmation before atomic replacement.
# 10. Supports a --dry-run mode and a --self-test mode for verifying logic.
set -o nounset
set -o errexit
set -o pipefail
CLEANUP_FILES=()
cleanup() {
rm -rf "${CLEANUP_FILES[@]}"
}
trap cleanup EXIT
# Configuration
DEFAULT_DIR="${HOME}/.ssh/authorized_keys.d"
DEFAULT_TARGET="${HOME}/.ssh/authorized_keys"
BEGIN_MARKER="# BEGIN UPDATE-AUTHORIZED-KEYS"
END_MARKER="# END UPDATE-AUTHORIZED-KEYS"
# State
SOURCE_DIRS=()
TARGET_FILE="${DEFAULT_TARGET}"
DRY_RUN=0
usage() {
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--dir DIR Primary directory for managed keys (default: ${DEFAULT_DIR})
--extra-dir DIR Additional directory to scan for keys (can be repeated)
--target FILE Target authorized_keys file (default: ${DEFAULT_TARGET})
--dry-run Show changes and validate without modifying the target
--self-test Run internal suite of tests to verify script logic
--help Show this help message
EOF
}
run_self_test() {
echo "Running self-test..."
local test_root=$(mktemp -d)
CLEANUP_FILES+=("${test_root}")
local d1="${test_root}/d1"
local d2="${test_root}/d2"
local target="${test_root}/target"
mkdir -p "${d1}" "${d2}"
local key1="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ8XoR7N7X5XoR7N7X5XoR7N7X5XoR7N7X5XoR7N7X5X key1"
local key2="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL9YpS8O8Y6YpS8O8Y6YpS8O8Y6YpS8O8Y6YpS8O8Y6Y key2"
local key_man="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM0ZqT9P9Z7ZqT9P9Z7ZqT9P9Z7ZqT9P9Z7ZqT9P9Z7Z manual"
local long_opt="environment=\"VAR=VERY_LONG_VALUE_THAT_EXCEEDS_TWENTY_CHARS\""
echo "${key1}" > "${d1}/k1"
echo "${key1}" > "${d2}/k1_dup"
echo "${key2}" > "${d2}/k2"
echo "${long_opt} ${key1}" > "${d1}/k1_long"
echo "${long_opt} ${key2}" > "${d1}/k2_long"
ln -s /dev/null "${d1}/masked"
cat <<EOF > "${target}"
${key_man}
${key1} # This should be removed as it's now managed
EOF
echo "Executing script in test mode..."
# Pipe "y" to handle the TTY check if we are not in a TTY during test
echo "y" | "$0" --dir "${d1}" --extra-dir "${d2}" --target "${target}" > /dev/null
local content=$(cat "${target}")
echo -n "Check markers... "
if [[ "${content}" == *"${BEGIN_MARKER}"* && "${content}" == *"${END_MARKER}"* ]]; then echo "OK"; else echo "FAIL"; exit 1; fi
echo -n "Check managed deduplication... "
if grep -q "Source: k1, k1_dup" "${target}"; then echo "OK"; else echo "FAIL"; exit 1; fi
echo -n "Check long option deduplication (should NOT deduplicate different keys)... "
if grep -q "k1_long" "${target}" && grep -q "k2_long" "${target}"; then echo "OK"; else echo "FAIL"; exit 1; fi
echo -n "Check manual key preservation... "
if grep -q "manual" "${target}"; then echo "OK"; else echo "FAIL"; exit 1; fi
echo -n "Check manual key filtering... "
local manual_count=$(grep -c "${key1}" "${target}")
# key1 appears twice in managed block (once plain, once with long opt)
# and it was in manual block. The manual one should be removed.
# So we expect 2 occurrences in the final file (both in managed block).
if [[ ${manual_count} -eq 2 ]]; then echo "OK"; else echo "FAIL (Found ${manual_count} occurrences, expected 2)"; exit 1; fi
echo -n "Check masking... "
if ! grep -q "masked" "${target}"; then echo "OK"; else echo "FAIL"; exit 1; fi
echo "Self-test passed successfully!"
exit 0
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--dir)
[[ -z "${2:-}" ]] && { echo "Error: --dir requires an argument" >&2; exit 1; }
SOURCE_DIRS+=("$2"); shift 2 ;;
--extra-dir)
[[ -z "${2:-}" ]] && { echo "Error: --extra-dir requires an argument" >&2; exit 1; }
SOURCE_DIRS+=("$2"); shift 2 ;;
--target)
[[ -z "${2:-}" ]] && { echo "Error: --target requires an argument" >&2; exit 1; }
TARGET_FILE="$2"; shift 2 ;;
--dry-run) DRY_RUN=1; shift ;;
--self-test) run_self_test ;;
--help) usage; exit 0 ;;
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
esac
done
if [[ ${#SOURCE_DIRS[@]} -eq 0 ]]; then
SOURCE_DIRS+=("${DEFAULT_DIR}")
fi
mkdir -p "$(dirname "${TARGET_FILE}")"
TMP_FILE=$(mktemp)
CLEANUP_FILES+=("${TMP_FILE}")
collect_keys() {
local dirs=("${@}")
for dir in "${dirs[@]}"; do
if [[ ! -d "${dir}" ]]; then continue; fi
# Use a glob to avoid parsing ls
for file in "${dir}"/*; do
[[ ! -e "${file}" ]] && continue
[[ ! -f "${file}" || ! -s "${file}" ]] && continue
if [[ -L "${file}" && "$(readlink "${file}")" == "/dev/null" ]]; then continue; fi
while read -r line; do
[[ -z "${line}" || "${line}" =~ ^[[:space:]]*# ]] && continue
# Use a specific delimiter that is unlikely to be in the key or filename
# If using tabs, ensure we only split on the first one in AWK
printf "%s\t%s\n" "$(basename "${file}")" "${line}"
done < "${file}"
done
done
}
# Use a HEREDOC for the complex AWK script to avoid shell interpolation issues
MANAGED_BLOCK=$(collect_keys "${SOURCE_DIRS[@]}" | awk -F'\t' '
{
# Splitting on the first tab manually to be robust
tab_idx = index($0, "\t")
source = substr($0, 1, tab_idx - 1)
full_line = substr($0, tab_idx + 1)
# Signature detection: all options + key type + key data
# (Excludes the comment at the end)
n = split(full_line, parts, " ")
sig = ""
for (i=1; i<=n; i++) {
sig = (sig == "" ? parts[i] : sig " " parts[i])
# A key line is [options] <type> <base64> [comment]
# We stop after the base64 part. Key types start with known prefixes.
if (parts[i] ~ /^(ssh-|ecdsa-|sk-)/ && i < n) {
sig = sig " " parts[i+1]
break
}
}
# Fallback if no key type found (should not happen with valid keys)
if (sig == "") sig = full_line
if (!(sig in keys)) {
keys[sig] = full_line
order[++count] = sig
}
sources[sig] = (sources[sig] ? sources[sig] ", " : "") source
}
END {
for (i=1; i<=count; i++) {
sig = order[i]
print "# Source: " sources[sig]
print keys[sig]
}
}')
MANUAL_KEYS=""
if [[ -f "${TARGET_FILE}" ]]; then
MANUAL_KEYS=$(awk -v begin="${BEGIN_MARKER}" -v end="${END_MARKER}" '
BEGIN { inside=0 }
$0 == begin { inside=1; next }
$0 == end { inside=0; next }
!inside { print $0 }
' "${TARGET_FILE}")
fi
MANAGED_SIGS_TMP=$(mktemp)
echo "${MANAGED_BLOCK}" | awk '/^[^#]/ {
n = split($0, parts, " ")
sig = ""
for (i=1; i<=n; i++) {
sig = (sig == "" ? parts[i] : sig " " parts[i])
if (parts[i] ~ /^(ssh-|ecdsa-|sk-)/ && i < n) {
sig = sig " " parts[i+1]
break
}
}
if (sig != "") print sig
}' > "${MANAGED_SIGS_TMP}"
FINAL_MANUAL_KEYS=$(echo "${MANUAL_KEYS}" | awk -v sigs_file="${MANAGED_SIGS_TMP}" '
BEGIN {
while ((getline line < sigs_file) > 0) {
managed[line] = 1
}
close(sigs_file)
}
{
if ($0 ~ /^[[:space:]]*$/ || $0 ~ /^[[:space:]]*#/) {
print $0
next
}
n = split($0, parts, " ")
sig = ""
for (i=1; i<=n; i++) {
sig = (sig == "" ? parts[i] : sig " " parts[i])
if (parts[i] ~ /^(ssh-|ecdsa-|sk-)/ && i < n) {
sig = sig " " parts[i+1]
break
}
}
if (!(sig in managed)) {
print $0
}
}')
rm -f "${MANAGED_SIGS_TMP}"
{
if [[ -n "${MANAGED_BLOCK}" ]]; then
echo "${BEGIN_MARKER}"
echo "${MANAGED_BLOCK}"
echo "${END_MARKER}"
fi
echo "${FINAL_MANUAL_KEYS}"
} > "${TMP_FILE}"
echo "Validating proposed changes..."
VALID=1
while read -r line; do
[[ -z "${line}" || "${line}" =~ ^[[:space:]]*# ]] && continue
if ! echo "${line}" | ssh-keygen -l -f - >/dev/null 2>&1; then
echo "ERROR: Invalid SSH key detected: ${line}" >&2
VALID=0
fi
done < "${TMP_FILE}"
if command -v authorized-keys-test >/dev/null 2>&1; then
if ! authorized-keys-test "${TMP_FILE}"; then
echo "ERROR: Proposed file failed authorized-keys-test." >&2
VALID=0
fi
fi
if [[ ${VALID} -eq 0 ]]; then
echo "Validation failed. Aborting." >&2
exit 1
fi
if [[ -f "${TARGET_FILE}" ]]; then
diff -u "${TARGET_FILE}" "${TMP_FILE}" || true
else
echo "Target file does not exist. Proposed content:"
cat "${TMP_FILE}"
fi
if [[ ${DRY_RUN} -eq 1 ]]; then
echo "Dry run complete. No changes made."
exit 0
fi
if [[ -t 0 ]]; then
echo -n "Apply these changes to ${TARGET_FILE}? [y/N] "
read -r response
elif [[ ! -t 0 ]]; then
# Read from pipe or file if provided
if ! read -r response; then
echo "Non-interactive shell detected and no input provided. Aborting."
exit 1
fi
fi
if [[ "${response}" =~ ^([yY][eE][sS]|[yY])$ ]]; then
chmod 0600 "${TMP_FILE}"
mv "${TMP_FILE}" "${TARGET_FILE}"
echo "Changes applied successfully."
else
echo "Aborted."
exit 1
fi

View File

@@ -1,6 +1,9 @@
# General aliases, should only be sourced in interactive shells # General aliases, should only be sourced in interactive shells
# Try to keep in sync with ~/.config/fish/conf.d/aliases.fish # Try to keep in sync with ~/.config/fish/conf.d/aliases.fish
# Cryptsetup alias
alias luksFormat='cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64'
# Timestamp in a machine-sortable form # Timestamp in a machine-sortable form
alias tstamp="date '+%Y%m%d-%H%M%S'" alias tstamp="date '+%Y%m%d-%H%M%S'"
@@ -10,6 +13,12 @@ alias mdcode="sed 's/^/ /'"
# Intel format plz # Intel format plz
alias objdump="command objdump -M intel" alias objdump="command objdump -M intel"
# Drop caches for swap issues
alias drop_caches="echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches"
# dump acpi temperature
alias gettemp='printf "%02.2f\n" "$(cat /sys/class/thermal/thermal_zone0/temp)e-3"'
# get git working directory # get git working directory
alias gitroot="git rev-parse --show-toplevel" alias gitroot="git rev-parse --show-toplevel"
@@ -22,40 +31,20 @@ alias ipy="ipython3 --no-banner"
# Skip the header on bc # Skip the header on bc
alias bc="command bc -q" alias bc="command bc -q"
# Get a decently readable df
alias dfh="df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs"
# Clear the GPG agent # Clear the GPG agent
alias clear-gpg-agent="echo RELOADAGENT | gpg-connect-agent" alias clear-gpg-agent="echo RELOADAGENT | gpg-connect-agent"
# Battery details
alias bat-details='upower -i $(upower -e | grep battery)'
# Nvidia refresh rate
alias nvidia-refresh-rate='nvidia-settings --display=:0 -q RefreshRate -t'
# Earthly ssh # Earthly ssh
alias earthly='earthly --ssh-auth-sock ""' alias earthly='earthly --ssh-auth-sock ""'
# ESP-IDF # to clipboard
alias activate_idf="source ~/.espressif/tools/activate_idf_v*.sh" alias toclip='xclip -selection clipboard'
if [ "$(uname)" = "Linux" ]; then
# Cryptsetup alias
alias luksFormat='cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64'
# Drop caches for swap issues
alias drop_caches="echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches"
# dump acpi temperature
alias gettemp='printf "%02.2f\n" "$(cat /sys/class/thermal/thermal_zone0/temp)e-3"'
# Get a decently readable df
alias dfh="df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs"
# Battery details
alias bat-details='upower -i $(upower -e | grep battery)'
# Nvidia refresh rate
alias nvidia-refresh-rate='nvidia-settings --display=:0 -q RefreshRate -t'
# to clipboard
alias toclip='xclip -selection clipboard'
elif [ "$(uname)" = "Darwin" ]; then
# Get a decently readable df
alias dfh="df -h"
# to clipboard
alias toclip='pbcopy'
fi

View File

@@ -1,4 +0,0 @@
# Credentials
.ssh
Passwords.kdbx
Passwords.kdbx.age

View File

@@ -1,63 +0,0 @@
#!/bin/sh
# shellcheck disable=SC1090
# common functions for use in shell scripts
find_first() {
while [ "$#" -gt 0 ]; do
if test -e "${1}" ; then
echo "${1}"
return 0
fi
shift
done
return 1
}
have_command() {
command -v "$1" >/dev/null 2>&1
}
# Helper function: Returns 0 if the directory is in PATH, 1 otherwise
path_contains() {
case ":${PATH}:" in
*:"$1":*) return 0 ;;
*) return 1 ;;
esac
}
# Prepend a directory to PATH if it's not already there
path_prepend() {
if [ -d "$1" ] && ! path_contains "$1"; then
PATH="$1:${PATH}"
fi
}
# Append a directory to PATH if it's not already there
path_append() {
if [ -d "$1" ] && ! path_contains "$1"; then
PATH="${PATH}:$1"
fi
}
source_first_existing() {
_sfe_script="$(find_first "$@")"
_sfe_status=$?
if [ "$_sfe_status" -eq 0 ]; then
. "$_sfe_script"
# Clean up our temporary variables before returning success
unset -v _sfe_script _sfe_status
return 0
fi
# Clean up our temporary variables before returning failure
unset -v _sfe_script _sfe_status
return 1
}
source_if_existing() {
if [ -f "$1" ]; then
. "$1"
fi
}

View File

@@ -1,3 +1,6 @@
# Cryptsetup alias
alias luksFormat 'cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64'
# Timestamp in a machine-sortable form # Timestamp in a machine-sortable form
alias tstamp "date '+%Y%m%d-%H%M%S'" alias tstamp "date '+%Y%m%d-%H%M%S'"
@@ -7,6 +10,12 @@ alias mdcode "sed 's/^/ /'"
# Intel format plz # Intel format plz
alias objdump "command objdump -M intel" alias objdump "command objdump -M intel"
# Drop caches for swap issues
alias drop_caches "echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches"
# dump acpi temperature
alias gettemp 'printf "%02.2f\n" (cat /sys/class/thermal/thermal_zone0/temp)e-3'
# get git working directory # get git working directory
alias gitroot "git rev-parse --show-toplevel" alias gitroot "git rev-parse --show-toplevel"
@@ -19,40 +28,23 @@ alias ipy "ipython3 --no-banner"
# Skip the header on bc # Skip the header on bc
alias bc "command bc -q" alias bc "command bc -q"
# Get a decently readable df
alias dfh "df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs"
# Clear the GPG agent # Clear the GPG agent
alias clear-gpg-agent "echo RELOADAGENT | gpg-connect-agent" alias clear-gpg-agent "echo RELOADAGENT | gpg-connect-agent"
# Battery details
alias bat-details 'upower -i (upower -e | grep battery)'
# Nvidia refresh rate
alias nvidia-refresh-rate 'nvidia-settings --display=:0 -q RefreshRate -t'
# Earthly ssh # Earthly ssh
alias earthly 'earthly --ssh-auth-sock ""' alias earthly 'earthly --ssh-auth-sock ""'
if test (uname) = "Linux" # to clipboard
# Cryptsetup alias alias toclip 'xclip -selection clipboard'
alias luksFormat 'cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64'
# Drop caches for swap issues
alias drop_caches "echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches"
# dump acpi temperature
alias gettemp 'printf "%02.2f\n" (cat /sys/class/thermal/thermal_zone0/temp)e-3'
# Get a decently readable df
alias dfh "df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs"
# Battery details
alias bat-details 'upower -i (upower -e | grep battery)'
# Nvidia refresh rate
alias nvidia-refresh-rate 'nvidia-settings --display=:0 -q RefreshRate -t'
# to clipboard
alias toclip 'xclip -selection clipboard'
else if test (uname) = "Darwin"
# Get a decently readable df
alias dfh "df -h"
# to clipboard
alias toclip 'pbcopy'
end
# On some systems, bat is batcat # On some systems, bat is batcat
if not command -v bat >/dev/null 2>&1 if not command -v bat >/dev/null 2>&1

View File

@@ -34,6 +34,4 @@ end
fish_add_path --move --path {$HOME}/bin fish_add_path --move --path {$HOME}/bin
if test (uname) = "Darwin" if test (uname) = "Darwin"
fish_add_path --move --path {$HOME}/bin/macos fish_add_path --move --path {$HOME}/bin/macos
else if test (uname) = "Linux"
fish_add_path --move --path {$HOME}/bin/linux
end end

View File

@@ -9,8 +9,9 @@ uv_venv_auto = true
[tools] [tools]
age = "latest" age = "latest"
age-plugin-yubikey = "latest"
usage = "latest" usage = "latest"
uv = "0.11.8" uv = "latest"
[hooks] [hooks]
postinstall = "mise sync python --uv" postinstall = "mise sync python --uv"

View File

@@ -39,3 +39,16 @@ disabled = true
[kubernetes] [kubernetes]
disabled = false disabled = false
detect_folders = ["k8s"] detect_folders = ["k8s"]
[custom.gemini_context]
description = "Displays the current Gemini CLI context"
when = "test -n \"$GEMINI_CLI_HOME\""
command = """
context_dir=\"${XDG_CONFIG_HOME:-$HOME/.config}/gemini\"
if [[ \"$GEMINI_CLI_HOME\" == $context_dir/* ]]; then
basename \"$GEMINI_CLI_HOME\"
fi
"""
style = "bold blue"
format = "♊[$output](blue) "
shell = ["/bin/sh", "-c"]

View File

@@ -19,17 +19,14 @@
[difftool] [difftool]
prompt = false prompt = false
[difftool "difftastic"]
cmd = difft "$LOCAL" "$REMOTE"
[alias] [alias]
st = status st = status
last = log -1 HEAD last = log -1 HEAD
# Thanks to # Thanks to
# http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/ # http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
logs = log --pretty=format:"%C(yellow)%h%Cred%d %Creset%s%Cblue [%cn]" --decorate logs = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
lg = log -p lg = log -p
ll = log --pretty=format:"%C(yellow)%h%Cred%d %Creset%s%Cblue [%cn]" --decorate --numstat ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
files = ls-files files = ls-files
ls = ls-files ls = ls-files
lol = log --graph --pretty=format:'%C(yellow)%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cblue(%cr)%Creset' --abbrev-commit --date=relative lol = log --graph --pretty=format:'%C(yellow)%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cblue(%cr)%Creset' --abbrev-commit --date=relative
@@ -95,12 +92,8 @@
process = git-lfs filter-process process = git-lfs filter-process
[include] [include]
path = ~/.gitconfig.d/aliases
path = ~/.gitconfig.d/override path = ~/.gitconfig.d/override
path = ~/.gitconfig.d/local path = ~/.gitconfig.d/local
[includeIf "gitdir/i:~/personal/"] [includeIf "gitdir:~/personal/"]
path = ~/.gitconfig.d/personal path = ~/.gitconfig.d/personal
[rerere]
enabled = true

View File

@@ -38,4 +38,3 @@ mise.local.toml
.copilot/ .copilot/
.cursor/ .cursor/
.gemini/ .gemini/
.jetskicli/

View File

@@ -45,6 +45,3 @@
hibernationfile hibernationfile
sleepimage sleepimage
swapfile swapfile
# Android and other big tools
/Users/*/.android

View File

@@ -15,7 +15,6 @@ export DEBEMAIL="david@systemoverlord.com"
export DEBFULLNAME="David Tomaschik" export DEBFULLNAME="David Tomaschik"
export LESS="-MR" export LESS="-MR"
export QUOTING_STYLE="literal" # Coreutils quotes export QUOTING_STYLE="literal" # Coreutils quotes
export HOMEBREW_NO_ENV_HINTS=1
# Fix gnome-terminal # Fix gnome-terminal
if [ "$TERM" = "xterm" ] && [ "$COLORTERM" = "gnome-terminal" ] ; then if [ "$TERM" = "xterm" ] && [ "$COLORTERM" = "gnome-terminal" ] ; then
@@ -195,8 +194,6 @@ if [ "$(uname)" = "Darwin" ] ; then
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$TMPDIR/runtime-$(id -u)}" export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$TMPDIR/runtime-$(id -u)}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}" export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export PATH="${HOME}/bin/macos:${PATH}" export PATH="${HOME}/bin/macos:${PATH}"
elif [ "$(uname)" = "Linux" ] ; then
export PATH="${HOME}/bin/linux:${PATH}"
fi fi
if test -e "$HOME/.localenv"; then if test -e "$HOME/.localenv"; then

View File

@@ -45,7 +45,7 @@ set -g window-status-current-style fg=colour235,bg=colour33,bold
set -g status-interval 60 set -g status-interval 60
set -g status-left-length 30 set -g status-left-length 30
set -g status-left '/#h: #S/ ' set -g status-left '/#h: #S/ '
set -g status-right '#{?pane_title,/#{pane_title}/ ,}#(uptime | rev | cut -d":" -f1 | rev | sed s/,//g)#[default] #[fg=colour166]%H:%M#[default]' set -g status-right '#{?pane_title,/#{pane_title}/ ,}#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=colour166]%H:%M#[default]'
# Advanced mouse mode from http://tangledhelix.com/blog/2012/07/16/tmux-and-mouse-mode/ # Advanced mouse mode from http://tangledhelix.com/blog/2012/07/16/tmux-and-mouse-mode/
# Toggle mouse on # Toggle mouse on
@@ -65,9 +65,8 @@ bind M \
display 'Mouse: OFF' display 'Mouse: OFF'
# tmux X clipboard integration # tmux X clipboard integration
if-shell 'test "$(uname)" = "Darwin"' \ bind C-c run "tmux show-buffer | xsel -i -b"
'bind C-c run "tmux show-buffer | pbcopy"; bind C-v run "tmux set-buffer -- \"$(pbpaste)\"; tmux paste-buffer"' \ bind C-v run "tmux set-buffer -- \"$(xsel -o -b)\"; tmux paste-buffer"
'bind C-c run "tmux show-buffer | xsel -i -b"; bind C-v run "tmux set-buffer -- \"$(xsel -o -b)\"; tmux paste-buffer"'
# List of plugins # List of plugins
set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tpm'

View File

@@ -59,8 +59,6 @@ DIRSTACKSIZE=16
export OS="$(uname 2>/dev/null || echo "Unknown")" export OS="$(uname 2>/dev/null || echo "Unknown")"
source ~/.commonrc.sh
# Set terminal title # Set terminal title
case $TERM in case $TERM in
# Only set the title for terminals that are likely to support it # Only set the title for terminals that are likely to support it
@@ -165,9 +163,28 @@ bindkey '^r' history-incremental-search-backward
# delete really deletes # delete really deletes
bindkey "^[[3~" delete-char bindkey "^[[3~" delete-char
source_if_existing() {
[[ -f "${1}" ]] && source "${1}"
}
path_prepend "${HOME}/.npm-packages/bin" source_first_existing() {
path_prepend "${HOME}/.local/bin" while (($#)); do
if test -e "${1}" ; then
source "${1}"
return
fi
shift
done
return 1
}
have_command() {
command -v "${1}" &>/dev/null
}
if test -d ${HOME}/.local/bin ; then
export PATH="${HOME}/.local/bin:${PATH}"
fi
# Source extras and aliases if interactive # Source extras and aliases if interactive
if [[ $- == *i* ]] ; then if [[ $- == *i* ]] ; then
@@ -214,7 +231,7 @@ if [[ $- == *i* ]] ; then
if [[ ! -f "$DUMPFILE" || ( -n "$newest_comp" && "$newest_comp" -nt "$DUMPFILE" ) ]]; then if [[ ! -f "$DUMPFILE" || ( -n "$newest_comp" && "$newest_comp" -nt "$DUMPFILE" ) ]]; then
compinit -i -d "$DUMPFILE" compinit -i -d "$DUMPFILE"
# Asynchronously compile the dump file with an atomic rename # Asynchronously compile the dump file with an atomic rename
{ zcompile "$DUMPFILE.zwc.$$.tmp" "$DUMPFILE" && mv -f "$DUMPFILE.zwc.$$.tmp" "$DUMPFILE.zwc" } &! { zcompile "$DUMPFILE.zwc.tmp" "$DUMPFILE" && mv -f "$DUMPFILE.zwc.tmp" "$DUMPFILE.zwc" } &!
else else
compinit -C -i -d "$DUMPFILE" compinit -C -i -d "$DUMPFILE"
fi fi
@@ -253,7 +270,8 @@ if [[ $- == *i* ]] ; then
if command -v direnv >/dev/null 2>&1 ; then if command -v direnv >/dev/null 2>&1 ; then
eval "$(direnv hook zsh)" eval "$(direnv hook zsh)"
fi fi
source_if_existing "${HOME}/.iterm2_shell_integration.zsh" test -e "${HOME}/.iterm2_shell_integration.zsh" && \
source "${HOME}/.iterm2_shell_integration.zsh" || true
# mise, if installed # mise, if installed
command -v mise >/dev/null 2>&1 && eval "$(mise activate zsh)" command -v mise >/dev/null 2>&1 && eval "$(mise activate zsh)"
@@ -268,11 +286,9 @@ if [ -x /usr/bin/ack-grep ] ; then
fi fi
# I want these first always # I want these first always
path_prepend "${HOME}/bin" PATH="${HOME}/bin:${PATH}"
if [[ "$(uname)" == "Darwin" ]]; then if [[ "$(uname)" == "Darwin" ]]; then
path_prepend "${HOME}/bin/macos" PATH="${HOME}/bin/macos:${PATH}"
elif [[ "$(uname)" == "Linux" ]]; then
path_prepend "${HOME}/bin/linux"
fi fi
# Load any local settings # Load any local settings

View File

@@ -18,15 +18,8 @@ alert() {
icon="error" icon="error"
fi fi
if [ "$(uname)" = "Darwin" ]; then # Send the notification with the executed command
# macOS notification notify-send --urgency=low -i "$icon" "Finished: '$@'"
local title="Finished: '$*'"
local msg="Exit code: $ret"
osascript -e "display notification \"$msg\" with title \"$title\""
else
# Send the notification with the executed command
notify-send --urgency=low -i "$icon" "Finished: '$@'"
fi
# Return the original exit code # Return the original exit code
return $ret return $ret

View File

@@ -1,12 +1,7 @@
if [ "$(uname)" = "Darwin" ]; then ANDROID_HOME=$HOME/Library/Android/sdk
ANDROID_HOME=$HOME/Library/Android/sdk
else
ANDROID_HOME=$HOME/Android/Sdk
fi
if test -d "${ANDROID_HOME}" ; then if test -d $ANDROID_HOME ; then
export ANDROID_HOME PATH=$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools
PATH="${PATH}:${ANDROID_HOME}/emulator:${ANDROID_HOME}/platform-tools"
else else
unset ANDROID_HOME unset ANDROID_HOME
fi fi

View File

@@ -6,11 +6,7 @@ if have_command nasm && have_command objdump ; then
local TMPF=`mktemp` local TMPF=`mktemp`
local bytes local bytes
local byte local byte
local format="elf" $NASM -f elf -o $TMPF $1
if [[ "$OSTYPE" == darwin* ]]; then
format="macho64"
fi
$NASM -f $format -o $TMPF $1
$OBJDUMP -M intel -d $TMPF | grep '^ ' | cut -f2 | while read -A bytes ; do $OBJDUMP -M intel -d $TMPF | grep '^ ' | cut -f2 | while read -A bytes ; do
for byte in $bytes ; do for byte in $bytes ; do
echo -n "\\\\x$byte" echo -n "\\\\x$byte"

View File

@@ -1,19 +1,26 @@
function dumpenv { function dumpenv {
if [ "$(uname)" = "Linux" ]; then tr '\0' '\n' < /proc/${1}/environ
tr '\0' '\n' < /proc/${1}/environ
elif [ "$(uname)" = "Darwin" ]; then
# macOS doesn't have /proc, use ps instead.
# Note: this may truncate if environment is very large.
ps -p ${1} -wwwe -o command= | tr ' ' '\n' | grep '='
fi
} }
_STARSHIP_PATH="$(find_first "$(command -v starship)" /sbin/starship "${HOME}/tools/starship/starship" "${HOME}/.local/bin/starship" /usr/local/bin/starship)" if test -x "/sbin/starship" ; then
if test -n "$_STARSHIP_PATH" ; then _STARSHIP_PATH="/sbin/starship"
function starship_prompt { function starship_prompt {
eval "$($_STARSHIP_PATH init zsh)" eval "$(/sbin/starship init zsh)"
}
elif test -x "${HOME}/tools/starship/starship" ; then
_STARSHIP_PATH="${HOME}/tools/starship/starship"
function starship_prompt {
eval "$($HOME/tools/starship/starship init zsh)"
} }
fi fi
if test -f ${HOME}/.zprompt ; then
if test "$(cat ${HOME}/.zprompt)" = "starship" ; then
if test -n "${_STARSHIP_PATH:-}" ; then
eval "$(${_STARSHIP_PATH} init zsh)"
fi
fi
fi
unset _STARSHIP_PATH
function hashall { function hashall {
tee >(md5sum) | tee >(sha1sum) | sha256sum tee >(md5sum) | tee >(sha1sum) | sha256sum

View File

@@ -1,20 +1,8 @@
# Find src-hilite-lesspipe.sh test -f /usr/share/source-highlight/src-hilite-lesspipe.sh && \
_SRCHILITE=""
for _p in /usr/share/source-highlight/src-hilite-lesspipe.sh /opt/homebrew/bin/src-hilite-lesspipe.sh /usr/local/bin/src-hilite-lesspipe.sh ; do
if [ -f "$_p" ] ; then
_SRCHILITE="$_p"
break
fi
done
if [ -n "$_SRCHILITE" ] ; then
function srcless { function srcless {
if [ $# -ne 1 ] ; then if [ $# -ne 1 ] ; then
echo "Usage: srcless <file>" > /dev/stderr echo "$0 <what>" > /dev/stderr
return 1 return 1
fi fi
"$_SRCHILITE" "$1" | less -R /usr/share/source-highlight/src-hilite-lesspipe.sh $1 | less -R
} }
fi
unset _SRCHILITE _p

View File

@@ -3,17 +3,6 @@
# Skelify -- move a file to my .skel and setup symlinks # Skelify -- move a file to my .skel and setup symlinks
function skelify { function skelify {
local -A opts
zparseopts -D -A opts -overlay:
local overlay_name="${opts[--overlay]}"
local base_skel_dir="${HOME}/.skel/dotfiles"
local extra_args=()
if [[ -n "${overlay_name}" ]]; then
base_skel_dir="${HOME}/.skel/dotfile_overlays/${overlay_name}"
extra_args=(--overlay "${overlay_name}")
fi
local target local target
local whichdir local whichdir
local relhome local relhome
@@ -21,19 +10,16 @@ function skelify {
local fulltarget local fulltarget
for target in $~@; do for target in $~@; do
if test -d ${target} ; then if test -d ${target} ; then
skelify "${extra_args[@]}" ${target}/* || return 1 skelify ${target}/* || return 1
elif test -f ${target} ; then elif test -f ${target} ; then
if ! whichdir=$(cd $(dirname $target) && pwd); then if ! whichdir=$(cd $(dirname $target) && pwd); then
echo Could not find directory for $target >/dev/stderr echo Could not find directory for $target >/dev/stderr
return 1 return 1
fi fi
fname=$(basename ${target}) fname=$(basename ${target})
relhome=${whichdir#${HOME}/}
fulltarget="${whichdir}/${fname}" fulltarget="${whichdir}/${fname}"
if [[ ${whichdir} == ${HOME} ]] ; then if [[ ${relhome} == ${whichdir} ]] ; then
relhome=""
elif [[ ${whichdir} == ${HOME}/* ]] ; then
relhome=${whichdir#${HOME}/}
else
echo ${whichdir} is not in home >/dev/stderr echo ${whichdir} is not in home >/dev/stderr
return 1 return 1
fi fi
@@ -46,7 +32,7 @@ function skelify {
return 1 return 1
fi fi
echo ${target} echo ${target}
local skeldir="${base_skel_dir}/${relhome}" local skeldir="${HOME}/.skel/dotfiles/${relhome}"
mkdir -p "${skeldir}" mkdir -p "${skeldir}"
mv ${target} "${skeldir}/${fname}" mv ${target} "${skeldir}/${fname}"
ln -s "${skeldir}/${fname}" "${fulltarget}" ln -s "${skeldir}/${fname}" "${fulltarget}"

View File

@@ -1,56 +0,0 @@
# utility function to "open" a file
o() {
if [[ "$OSTYPE" == "darwin"* ]]; then
open "$@"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
xdg-open "$@"
else
echo "Unknown OS"
fi
}
# Copy from stdin to the system clipboard
syscopy() {
if command -v pbcopy >/dev/null 2>&1; then
# macOS
pbcopy "$@"
elif command -v wl-copy >/dev/null 2>&1; then
# Linux Wayland
wl-copy "$@"
elif command -v xclip >/dev/null 2>&1; then
# Linux X11
xclip -selection clipboard "$@"
elif command -v xsel >/dev/null 2>&1; then
# Linux X11 (alternative)
xsel --clipboard --input "$@"
elif command -v clip.exe >/dev/null 2>&1; then
# Windows WSL
clip.exe "$@"
else
echo "Error: No clipboard utility found. Please install pbcopy, wl-copy, xclip, or xsel." >&2
return 1
fi
}
# Paste from the system clipboard to stdout
syspaste() {
if command -v pbpaste >/dev/null 2>&1; then
# macOS
pbpaste "$@"
elif command -v wl-paste >/dev/null 2>&1; then
# Linux Wayland
wl-paste "$@"
elif command -v xclip >/dev/null 2>&1; then
# Linux X11
xclip -selection clipboard -o "$@"
elif command -v xsel >/dev/null 2>&1; then
# Linux X11 (alternative)
xsel --clipboard --output "$@"
elif command -v powershell.exe >/dev/null 2>&1; then
# Windows WSL
powershell.exe -noprofile -command Get-Clipboard "$@"
else
echo "Error: No clipboard utility found. Please install pbpaste, wl-paste, xclip, or xsel." >&2
return 1
fi
}

View File

@@ -7,65 +7,14 @@ set -o errexit
set -o shwordsplit 2>/dev/null || true # Make zsh behave like bash set -o shwordsplit 2>/dev/null || true # Make zsh behave like bash
HOME=${HOME:-$(cd ~ && pwd)} HOME=${HOME:-$(cd ~ && pwd)}
LOCAL_BIN="${HOME}/.local/bin"
STARSHIP_INSTALL_HASH="52c64f14a558034ebeb1907ea9364e802b32474576fd3e68265f73bc33cc8fbb"
# 1. Get the raw script path (handles Bash vs Zsh)
TARGET="${BASH_SOURCE[0]}"
# 2. Loop to resolve symlinks completely
while [ -L "$TARGET" ]; do
DIR=$(cd -P "$(dirname -- "$TARGET")" &>/dev/null && pwd)
TARGET=$(readlink "$TARGET")
# If $TARGET is a relative symlink, resolve it relative to the symlink's directory
[[ $TARGET != /* ]] && TARGET="$DIR/$TARGET"
done
# 3. Get the final absolute directory
SCRIPT_DIR="$(cd -P "$(dirname -- "$TARGET")" &>/dev/null && pwd)"
have_command() { have_command() {
command -v "${1}" >/dev/null 2>&1 command -v "${1}" >/dev/null 2>&1
} }
raw_sha256sum() {
local file="${1}"
if [[ -z "${file}" ]]; then
echo "Error: No file specified" >&2
return 1
fi
if [[ ! -f "${file}" ]]; then
echo "Error: File not found: ${file}" >&2
return 1
fi
if have_command sha256sum ; then
sha256sum "${file}" | awk '{print $1}'
elif have_command shasum ; then
shasum -a 256 "${file}" | awk '{print $1}'
else
echo "Error: Neither sha256sum nor shasum is available" >&2
return 1
fi
}
sudo_group() {
if [[ "$(id -u)" -eq 0 ]] ; then
return 0
fi
have_command sudo && ( id -Gn | grep -q '\bsudo\b' )
}
maybe_sudo() {
if [[ "$(id -u)" -eq 0 ]] ; then
"$@"
return
fi
if ! have_command sudo ; then
return 1
fi
sudo "$@"
}
link_directory_contents() { link_directory_contents() {
local SRCDIR="${1}" local SRCDIR="${1}"
@@ -94,7 +43,7 @@ ssh_key_already_installed() {
fi fi
# Extract the key data (field 2) from the key file, ignoring comments # Extract the key data (field 2) from the key file, ignoring comments
local key_data local key_data
key_data=$(awk '/^(ssh|ecdsa|sk)-/ {print $2}' "$1") key_data=$(awk '/^ssh-/ {print $2}' "$1")
if [[ -z "${key_data}" ]]; then if [[ -z "${key_data}" ]]; then
# Not a valid key file # Not a valid key file
return 1 return 1
@@ -141,7 +90,7 @@ install_known_hosts() {
verbose 'Installing known hosts...' >&2 verbose 'Installing known hosts...' >&2
local skel_hosts="${BASEDIR}/keys/known_hosts" local skel_hosts="${BASEDIR}/keys/known_hosts"
local user_hosts="${HOME}/.ssh/known_hosts" local user_hosts="${HOME}/.ssh/known_hosts"
local merge_script="${BASEDIR}/skeltools/merge_known_hosts" local merge_script="${BASEDIR}/skeltools/merge_authorized_keys"
if [[ ! -f "${skel_hosts}" ]]; then if [[ ! -f "${skel_hosts}" ]]; then
return 0 return 0
@@ -227,60 +176,6 @@ install_dotfiles() {
fi fi
} }
install_starship() {
if have_command starship ; then return 0 ; fi
if have_command brew ; then
verbose "Attempting to install Starship via Homebrew..."
if brew install starship ; then
return 0
fi
echo "brew install starship failed, trying other methods..." >&2
fi
if have_command apt-get && sudo_group ; then
if maybe_sudo apt-get install -qy starship ; then
return 0
fi
echo "apt-get install starship failed, installing locally" >&2
fi
local tmpd
tmpd="$(mktemp -d tmp.starship.XXXXXX)" || return 1
trap '[[ -n "${tmpd}" && -d "${tmpd}" ]] && rm -rf "${tmpd}"' EXIT
local install_path="${tmpd}/install.sh"
if have_command curl ; then
curl -sSL --show-error -o "${install_path}" https://starship.rs/install.sh
elif have_command wget ; then
wget -q -O "${install_path}" --https-only https://starship.rs/install.sh
else
echo "No curl or wget available!!" >&2
rm -rf "${tmpd}"
trap - EXIT
return 1
fi
local dl_hash
dl_hash="$(raw_sha256sum "${install_path}")"
if [[ "$dl_hash" != "${STARSHIP_INSTALL_HASH}" ]] ; then
echo "Hash check failed!!" >&2
echo "Expected: ${STARSHIP_INSTALL_HASH}, got ${dl_hash} on ${install_path}" >&2
rm -rf "${tmpd}"
trap - EXIT
return 1
fi
if sudo_group ; then
if maybe_sudo sh "${install_path}" ; then
rm -rf "${tmpd}"
trap - EXIT
return 0
fi
echo "root installation failed, falling back to user-local" >&2
fi
sh "${install_path}" -b "${LOCAL_BIN}"
rm -rf "${tmpd}"
trap - EXIT
}
install_main() { install_main() {
if [[ -d "${BASEDIR}/.git" ]] && have_command git ; then if [[ -d "${BASEDIR}/.git" ]] && have_command git ; then
if [[ -z "$(git -C "${BASEDIR}" status --porcelain)" ]]; then if [[ -z "$(git -C "${BASEDIR}" status --porcelain)" ]]; then
@@ -290,8 +185,6 @@ install_main() {
fi fi
fi fi
[[ "$MINIMAL" = 1 ]] || { [[ "$MINIMAL" = 1 ]] || {
mkdir -p "${LOCAL_BIN}"
install_starship
# Install vim-plug if not already present # Install vim-plug if not already present
local VIM_PLUG_URL="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" local VIM_PLUG_URL="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
@@ -306,22 +199,22 @@ install_main() {
else else
echo "Error: curl not found. Cannot install vim-plug." >&2 echo "Error: curl not found. Cannot install vim-plug." >&2
fi fi
fi fi
# Install TPM (Tmux Plugin Manager) if not already present # Install TPM (Tmux Plugin Manager) if not already present
local TPM_DIR="${HOME}/.tmux/plugins/tpm" local TPM_DIR="${HOME}/.tmux/plugins/tpm"
local TPM_REPO="https://github.com/tmux-plugins/tpm" local TPM_REPO="https://github.com/tmux-plugins/tpm"
if [[ ! -d "${TPM_DIR}" ]]; then if [[ ! -d "${TPM_DIR}" ]]; then
verbose "Installing TPM (Tmux Plugin Manager)..." verbose "Installing TPM (Tmux Plugin Manager)..."
if have_command git; then if have_command git; then
git clone --depth 1 "${TPM_REPO}" "${TPM_DIR}" git clone --depth 1 "${TPM_REPO}" "${TPM_DIR}"
else else
echo "Error: git not found. Cannot install TPM." >&2 echo "Error: git not found. Cannot install TPM." >&2
fi fi
fi fi
# try to update dotfile overlays # try to update dotfile overlays
if [[ -d "${BASEDIR}/dotfile_overlays" ]] ; then if [[ -d "${BASEDIR}/dotfile_overlays" ]] ; then
for dotfiledir in "${BASEDIR}/dotfile_overlays/"* ; do for dotfiledir in "${BASEDIR}/dotfile_overlays/"* ; do
if [[ -d "${dotfiledir}/.git" ]] ; then if [[ -d "${dotfiledir}/.git" ]] ; then
@@ -350,7 +243,7 @@ read_saved_prefs
# Defaults if not passed in or saved. # Defaults if not passed in or saved.
# TODO: use flags instead of environment variables. # TODO: use flags instead of environment variables.
: ${BASEDIR:=${SCRIPT_DIR}} : ${BASEDIR:=$HOME/.skel}
: ${MINIMAL:=0} : ${MINIMAL:=0}
: ${INSTALL_KEYS:=1} : ${INSTALL_KEYS:=1}
: ${TRUST_ALL_KEYS:=0} : ${TRUST_ALL_KEYS:=0}