Skip to content

Instantly share code, notes, and snippets.

@onjin
Created April 7, 2026 21:14
Show Gist options
  • Select an option

  • Save onjin/feb14d6be4c9139baea9d3d24825221d to your computer and use it in GitHub Desktop.

Select an option

Save onjin/feb14d6be4c9139baea9d3d24825221d to your computer and use it in GitHub Desktop.
Dead simple file templates store
#!/usr/bin/env bash
# Directory where your snippets are stored
SNIPPET_DIR="$HOME/snippets"
# Ensure fzf is installed
if ! command -v fzf &>/dev/null; then
echo "fzf is required but not installed."
exit 1
fi
# Use fzf to select a snippet, allowing Ctrl-E to edit the selected file
snippet=$(find "$SNIPPET_DIR" -type f |
fzf --prompt="Select snippet: " \
--preview "bat --style=plain --color=always {}" \
--bind "ctrl-e:execute($EDITOR {} > /dev/tty && echo {} && kill -SIGSTOP $$)")
[[ -z $snippet ]] && exit 1
# Ask for target path
default_name=$(basename $snippet)
read -rp "Enter target path and name [${default_name}]: " target_path
[[ -z $target_path ]] && target_path=${default_name}
# Copy snippet
cp "$snippet" "$target_path"
# Open in editor
nvim "$target_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment