dotfiles/espanso/.config/espanso/match/code-snippets.yml
2025-05-12 20:29:08 -06:00

102 lines
2.2 KiB
YAML

matches:
# Python imports block
- trigger: ":py-imports"
replace: |
import os
import sys
import argparse
import logging
# Python entry point
- trigger: ":py-main"
replace: |
if __name__ == "__main__":
main()
# Python logging setup
- trigger: ":py-logger"
replace: |
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler()]
)
logger = logging.getLogger(__name__)
# Bash color template
- trigger: ":bash-colors"
replace: |
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Bash shebang + options
- trigger: ":bash-head"
replace: |
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Bash usage function
- trigger: ":bash-usage"
replace: |
usage() {
echo "Usage: $0 [options]"
echo " -h Show help"
exit 1
}
while getopts ":h" opt; do
case ${opt} in
h ) usage ;;
\? ) usage ;;
esac
done
- trigger: ":py-args"
replace: |
import argparse
parser = argparse.ArgumentParser(description="Script description here.")
parser.add_argument("input", help="Input file")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose mode")
args = parser.parse_args()
- trigger: ":py-timer"
replace: |
import time
start = time.time()
# your code here
print(f"Elapsed time: {time.time() - start:.2f}s")
- trigger: ":py-path"
replace: |
from pathlib import Path
base_path = Path(__file__).resolve().parent
data_path = base_path / "data" / "file.csv"
- trigger: ":bash-log"
replace: |
log() {
echo -e "\\033[1;34m[INFO]\\033[0m $1"
}
- trigger: ":bash-check"
replace: |
if [ ! -f "$1" ]; then
echo "File not found: $1"
exit 1
fi
- trigger: ":bash-trap"
replace: |
cleanup() {
echo "Cleaning up..."
# Add cleanup commands here
}
trap cleanup EXIT