From 2e8f827135db7d8d4d662972821663c39f127cb0 Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Tue, 28 Oct 2025 21:36:59 +0530 Subject: [PATCH] refactor(templates): Better template file organization - .prettierignore & .dockerignore: generate from the repository's .gitignore file - .dockerignore: Ignore .git, *.md, Dockerfile by default - Remove unnecessary exports for each template - .gitignore: Better comments and organization --- common/.config/templates/.gitignore | 63 +++++++------ common/.config/templates/.prettierignore | 109 ----------------------- common/.config/templates/pre-commit | 9 +- common/.profile | 6 +- linux/.config/shell/aliases_linux.sh | 97 ++++++++++++++------ 5 files changed, 104 insertions(+), 180 deletions(-) delete mode 100644 common/.config/templates/.prettierignore diff --git a/common/.config/templates/.gitignore b/common/.config/templates/.gitignore index 8c85cb6..f5c1a53 100644 --- a/common/.config/templates/.gitignore +++ b/common/.config/templates/.gitignore @@ -1,30 +1,18 @@ -# ---- KDE Neon ---- -# KDE directory preferences +# ----- OS Artifacts ---- +# Linux +.Trash-* .directory # temporary files which can be created if a process still has a handle open of a deleted file .fuse_hidden* -# Linux trash folder which might appear on any partition or disk -.Trash-* - # .nfs files are created when an open file is removed but is still being accessed .nfs* -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# ---- macOS ---- -# General +# macOS .DS_Store .AppleDouble .LSOverride - -# Icon must end with two \r Icon # Thumbnails @@ -46,6 +34,19 @@ Network Trash Folder Temporary Items .apdisk +# Other Files to ignore +**app_stat_v2.db +.ssh/*.pub +**/Package Control.cache +**Cache +*.db +*.qmlc +*.qml +*.jsc +**/contents/images +**/contents/fonts +*kpluginindex.json + # ---- IDE ---- # Vim Artifacts **.swp @@ -68,14 +69,25 @@ resharper-host/ tasks/ # ---- Programming Languages ---- -# Ignore all downloaded node modules +# Javascript **/node_modules/* dist dist-ssr *.local -# Ignore all minified js files *.min.js +# Rust +target/ + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +**/built/ + # Log files logs *.log @@ -84,18 +96,3 @@ yarn-debug.log* yarn-error.log* pnpm-debug.log* lerna-debug.log* - -# Other Files to ignore -**app_stat_v2.db -.ssh/*.pub -**/Package Control.cache -**Cache -*.db -*.qmlc -*.qml -*.jsc -**/contents/images -**/contents/fonts -*kpluginindex.json - -**/built/ diff --git a/common/.config/templates/.prettierignore b/common/.config/templates/.prettierignore deleted file mode 100644 index b13b9d4..0000000 --- a/common/.config/templates/.prettierignore +++ /dev/null @@ -1,109 +0,0 @@ -build -coverage - -# ---- KDE Neon ---- -# KDE directory preferences -.directory - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# ---- macOS ---- -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# ---- IDE ---- -# Vim Artifacts -**.swp -lazy-lock.json -.luarc.json - -# VS Code Artifacts -/.vscode/ -**state.vscdb -**state.vscdb.backup -.vscode/extensions/** # Ignore all Files under .vscode/extensions/ -!.vscode/extensions/**/*.json # Only json files inside the .vscode/extensions/ folder - -# Intellij IDE Artifacts -.idea/ -*.imi -*.jar -*.tar -resharper-host/ -tasks/ - -# ---- Programming Languages ---- -# Ignore all downloaded node modules -**/node_modules/* -dist -dist-ssr -*.local -# Ignore all minified js files -*.min.js - -# Log files -..logs/ -*.log - -# Other Files to ignore -**app_stat_v2.db -.ssh/*.pub -**/Package Control.cache -**Cache -*.db -*.qmlc -*.qml -*.jsc -**/contents/images -**/contents/fonts -*kpluginindex.json - -*backup -*undo -*sessions -*.bak -nvim_switch/ -*kitty/*.py -.prettierignore -package-lock.json -.prettierrc - -**/built/ diff --git a/common/.config/templates/pre-commit b/common/.config/templates/pre-commit index 69e9e1f..ef48626 100755 --- a/common/.config/templates/pre-commit +++ b/common/.config/templates/pre-commit @@ -1,14 +1,7 @@ #!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". # Check if Gitleaks is installed -if ! command -v gitleaks > /dev/null 2>&1; then +if ! command -v gitleaks >/dev/null 2>&1; then echo "Gitleaks is not installed. Skipping leak check." echo "Please install Gitleaks for enhanced security." exit 0 diff --git a/common/.profile b/common/.profile index 7e77423..3b2028b 100644 --- a/common/.profile +++ b/common/.profile @@ -79,11 +79,7 @@ export FZF_DEFAULT_COMMAND='rg --files --hidden' export FZF_DEFAULT_OPTS='--layout=reverse --cycle' export DOCKER_CONFIG="${XDG_CONFIG_HOME}/docker" -[ ! -f "${XDG_CONFIG_HOME}/templates/.gitignore" ] || export GITIGNORE_TEMPLATE="${XDG_CONFIG_HOME}/templates/.gitignore" -[ ! -f "${XDG_CONFIG_HOME}/templates/.prettierrc" ] || export PRETTIER_TEMPLATE="${XDG_CONFIG_HOME}/templates/.prettierrc" -[ ! -f "${XDG_CONFIG_HOME}/templates/.prettierignore" ] || export PRETTIER_IGNORE_TEMPLATE="${XDG_CONFIG_HOME}/templates/.prettierignore" -[ ! -f "${XDG_CONFIG_HOME}/templates/pre-commit" ] || export GIT_PRECOMMIT_TEMPLATE="${XDG_CONFIG_HOME}/templates/pre-commit" -[ ! -f "${XDG_CONFIG_HOME}/templates/.eslintrc.json" ] || export ESLINT_TEMPLATE="${XDG_CONFIG_HOME}/templates/.eslintrc.json" +[ ! -d "${XDG_CONFIG_HOME}/templates" ] || export TEMPLATE_DIR="${XDG_CONFIG_HOME}/templates" # Python export PYTHON_HISTORY="${XDG_STATE_HOME}/shell/python_history" # will be picked up by Python 3.13+ diff --git a/linux/.config/shell/aliases_linux.sh b/linux/.config/shell/aliases_linux.sh index e971787..272a409 100644 --- a/linux/.config/shell/aliases_linux.sh +++ b/linux/.config/shell/aliases_linux.sh @@ -10,10 +10,78 @@ alias lsa="ls -lAFhZ" alias printpath="echo $PATH | tr : '\n'" # Templates -[ ! -f "$GITIGNORE_TEMPLATE" ] || alias cp_gi='cp ${GITIGNORE_TEMPLATE} .' -[ ! -f "$PRETTIER_TEMPLATE" ] || alias cp_prc='cp ${PRETTIER_TEMPLATE} .' -[ ! -f "$PRETTIER_IGNORE_TEMPLATE" ] || alias cp_prigr='cp ${PRETTIER_IGNORE_TEMPLATE} .' -[ ! -f "$ESLINT_TEMPLATE" ] || alias cp_eslint='cp ${ESLINT_TEMPLATE} .' +[ ! -f "${TEMPLATE_DIR}/.gitignore" ] || alias cp_git_ignore='cp ${TEMPLATE_DIR}/.gitignore . && echo ".gitignore added"' +[ ! -f "${TEMPLATE_DIR}/.prettierrc" ] || alias cp_prettier_rc='cp ${TEMPLATE_DIR}/.prettierrc . && echo ".prettierrc added"' +[ ! -f "${TEMPLATE_DIR}/.eslintrc.json" ] || alias cp_eslint='cp ${TEMPLATE_DIR}/.eslintrc.json . && echo ".eslintrc.json added"' +cp_docker_ignore() { + local git_ignore_file + + if [ -f .gitignore ]; then + git_ignore_file=.gitignore + elif [ -f "${TEMPLATE_DIR}/.gitignore" ]; then + git_ignore_file="${TEMPLATE_DIR}/.gitignore" + else + return 1 + fi + + cp "$git_ignore_file" .dockerignore + cat <>.dockerignore + +# ---- Docker specific ---- +git/ +*.md +Dockerfile +EOF + + echo ".dockerignore added" +} + +cp_prettier_ignore() { + local git_ignore_file + + if [ -f .gitignore ]; then + git_ignore_file=.gitignore + elif [ -f "${TEMPLATE_DIR}/.gitignore" ]; then + git_ignore_file="${TEMPLATE_DIR}/.gitignore" + else + return 1 + fi + + cp "$git_ignore_file" .prettierignore + cat <>.prettierignore + +# ---- Prettier specific ---- +*backup +*undo +*sessions +.prettierignore +package-lock.json +.prettierrc +EOF + echo ".prettierignore added" +} + +cp_git_precommit() { + local template_file="${TEMPLATE_DIR}/pre-commit" + if [ ! -f "$template_file" ]; then + return 1 + fi + + if [ ! -d ".git" ]; then + echo "Not a git repository" + return 1 + fi + + local hooks_dir + hooks_dir="$(pwd)/.git/hooks" + + if [ -f "$hooks_dir/$(basename "$template_file")" ]; then + echo "pre-commit hook already exist" + return 1 + fi + + cp "$template_file" "$hooks_dir" && printf "Pre-commit hook template copied to %s\n" "$hooks_dir" +} # Coding command -v tldr >/dev/null && alias tldr="tldr --platform=linux" @@ -33,27 +101,6 @@ git_push_all_changes() { git add . && git commit -am "${1}" && git push } -cp_git_precommit() { - if [ ! -f "$GIT_PRECOMMIT_TEMPLATE" ]; then - echo "Git Pre-commit template does not exist" - return 1 - fi - - hooks_dir="$(pwd)/.git/hooks" - - if [ ! -d "$hooks_dir" ]; then - echo "Git repository not found under $(pwd)" - return 2 - fi - - if [ -f "$hooks_dir/$(basename "$GIT_PRECOMMIT_TEMPLATE")" ]; then - echo "pre-commit hook already exist. Skipping..." - return 0 - fi - - cp "$GIT_PRECOMMIT_TEMPLATE" "$hooks_dir" && printf "Pre-commit hook template copied to %s\n" "$hooks_dir" -} - # Directories and Directory listings dir_size() { if [ "$1" = "" ]; then