mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-07 22:50:39 +00:00
* fix(ci): replace broad permissions with specific scopes in workflows
Replace read-all/write-all with minimum required permission scopes
across all GitHub Actions workflows to follow the principle of least
privilege (SonarCloud rule githubactions:S8234).
* fix(shell): use [[ instead of [ for conditional tests
Replace single brackets with double brackets in bash conditional
expressions across 14 files (28 changes). All scripts use bash
shebangs so [[ is safe everywhere (SonarCloud rule shelldre:S7688).
* fix(shell): add explicit return statements to functions
Add return 0 as the last statement in ~46 shell functions across
17 files that previously relied on implicit return codes
(SonarCloud rule shelldre:S7682).
* fix(shell): assign positional parameters to local variables
Replace direct $1/$2/$3 usage with named local variables in _log(),
msg(), msg_err(), msg_done(), msg_run(), msg_ok(), and array_diff()
(SonarCloud rule shelldre:S7679).
* fix(python): replace dict() constructor with literal
Use {} instead of dict() for empty dictionary initialization
(SonarCloud rule python:S7498).
* fix(shell): fix husky shebang and tolerate npm outdated exit code
* docs(shell): add function docstring comments
* fix(shell): fix heredoc indentation in x-sonarcloud
* feat(python): add ruff linter and formatter configuration
* fix(ci): align megalinter config with biome, ruff, and shfmt settings
* fix(ci): disable black and yaml-prettier in megalinter config
* chore(ci): update ruff-pre-commit to v0.15.0 and fix hook name
* fix(scripts): check for .git dir before skipping clone in install-fonts
* fix(shell): address code review issues in scripts and shared.sh
- Guard wezterm show-keys failure in create-wezterm-keymaps.sh
- Stop masking git failures with return 0 in install-cheat-purebashbible.sh
- Add missing shared.sh source in install-xcode-cli-tools.sh
- Replace exit 1 with return 1 in sourced shared.sh
* fix(scripts): address code review and security findings
- Guard wezterm show-keys failure in create-wezterm-keymaps.sh
- Stop masking git failures with return 0 in install-cheat-purebashbible.sh
- Add missing shared.sh source in install-xcode-cli-tools.sh
- Replace exit 1 with return 1 in sourced shared.sh
- Remove shell=True subprocess calls in x-git-largest-files.py
* style(shell): apply shfmt formatting and add args to pre-commit hook
* fix(python): suppress bandit false positives in x-git-largest-files
* fix(python): add nosemgrep suppression for check_output call
* feat(format): add prettier for YAML formatting
Install prettier, add .prettierrc.json config (200-char width, 2-space
indent, LF endings), .prettierignore, yarn scripts (lint:prettier,
fix:prettier, format:yaml), and pre-commit hook scoped to YAML files.
* style(yaml): apply prettier formatting
* fix(scripts): address remaining code review findings
- Python: use list comprehension to filter empty strings instead of
slicing off the last element
- create-wezterm-keymaps: write to temp file and mv for atomic updates
- install-xcode-cli-tools: fix shellcheck source directive path
* fix(python): sort imports alphabetically in x-git-largest-files
* fix(lint): disable PYTHON_ISORT in MegaLinter, ruff handles it
* chore(git): add __pycache__ to gitignore
* fix(python): rename ambiguous variable l to line (E741)
* style: remove trailing whitespace and blank lines
* style(fzf): apply shfmt formatting
* style(shell): apply shfmt formatting
* docs(plans): add design documents
* style(docs): add language specifier to fenced code block
* feat(lint): add markdown-table-formatter to dev tooling
Add markdown-table-formatter as a dev dependency with yarn scripts
(lint:md-table, fix:md-table) and a local pre-commit hook to
automatically format markdown tables on commit.
111 lines
2.8 KiB
Bash
Executable File
111 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
# @description Update pure-bash-bible cheatsheets
|
|
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
|
|
# shellcheck source=shared.sh
|
|
source "${DOTFILES}/config/shared.sh"
|
|
|
|
PBB_REQUIRED_TOOLS=(git cheat)
|
|
PBB_GIT="https://github.com/dylanaraps/pure-bash-bible.git"
|
|
PBB_SOURCE="source: $PBB_GIT"
|
|
PBB_SYNTAX="syntax: bash"
|
|
PBB_TAGS="tags: [bash]"
|
|
PBB_TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/cheat/pbb"
|
|
|
|
# Verify required tools are installed
|
|
check_required_tools()
|
|
{
|
|
for t in "${PBB_REQUIRED_TOOLS[@]}"; do
|
|
if ! x-have "$t"; then
|
|
echo "(!) $t is missing, can't continue..."
|
|
exit 1
|
|
fi
|
|
done
|
|
return 0
|
|
}
|
|
|
|
# Clone or update the pure-bash-bible repository
|
|
clone_or_update_repo()
|
|
{
|
|
if [[ ! -d "$PBB_TEMP_DIR/.git" ]]; then
|
|
msg_run "Starting to clone $PBB_GIT"
|
|
git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR"
|
|
msg_yay "Cloned $PBB_GIT"
|
|
else
|
|
msg_run "Starting to update $PBB_GIT"
|
|
git -C "$PBB_TEMP_DIR" reset --hard origin/master
|
|
git -C "$PBB_TEMP_DIR" pull -q
|
|
msg_yay "Updated $PBB_GIT"
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# Get the cheat destination directory for pure-bash-bible
|
|
prepare_cheat_dest()
|
|
{
|
|
local cheat_dest
|
|
cheat_dest="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')"
|
|
|
|
if [[ ! -d "$cheat_dest" ]]; then
|
|
mkdir -p "$cheat_dest"
|
|
fi
|
|
|
|
echo "$cheat_dest"
|
|
return 0
|
|
}
|
|
|
|
# Processes chapter files from the pure-bash-bible repository and generates or updates corresponding cheat sheets.
|
|
#
|
|
# For each chapter file, creates or updates a cheat sheet in the appropriate destination directory, removes chapter end markers, and ensures required metadata is present.
|
|
#
|
|
# Globals:
|
|
# * PBB_TEMP_DIR: Directory containing the cloned pure-bash-bible repository.
|
|
# * PBB_SYNTAX, PBB_TAGS, PBB_SOURCE: Metadata strings for cheat sheets.
|
|
#
|
|
# Outputs:
|
|
# * Writes or updates cheat sheet files in the determined cheat sheet directory.
|
|
#
|
|
# Example:
|
|
#
|
|
# ```bash
|
|
# process_chapters
|
|
# ```
|
|
process_chapters()
|
|
{
|
|
local cheat_dest
|
|
cheat_dest=$(prepare_cheat_dest)
|
|
|
|
mapfile -t PBB_CHAPTERS < <(ls -1v "$PBB_TEMP_DIR"/manuscript/chapter*)
|
|
|
|
for f in "${PBB_CHAPTERS[@]}"; do
|
|
local header cheat_file
|
|
header=$(grep -e '^[#] ' "$f" | head -1 | awk '{print tolower($2)}')
|
|
cheat_file="$cheat_dest/$header"
|
|
|
|
if ! replaceable "$f" "$cheat_file"; then
|
|
cp "$f" "$cheat_file" && msg_run "Updated: $cheat_file"
|
|
fi
|
|
|
|
LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$cheat_file"
|
|
rm "$cheat_file.bak"
|
|
|
|
if [[ '---' != "$(head -1 < "$cheat_file")" ]]; then
|
|
local metadata
|
|
metadata="$PBB_SYNTAX\n$PBB_TAGS\n$PBB_SOURCE\n"
|
|
printf '%s\n%b%s\n%s' "---" "$metadata" "---" "$(cat "$cheat_file")" > "$cheat_file"
|
|
fi
|
|
done
|
|
return 0
|
|
}
|
|
|
|
# Install pure-bash-bible cheatsheets
|
|
main()
|
|
{
|
|
check_required_tools
|
|
clone_or_update_repo
|
|
process_chapters
|
|
return 0
|
|
}
|
|
|
|
main "$@"
|