feat(config): add tldr to cheat as a submodule

This commit is contained in:
2024-02-21 14:21:29 +02:00
parent dee215a29e
commit 523bec769f
5 changed files with 7 additions and 79 deletions

3
.gitmodules vendored
View File

@@ -55,3 +55,6 @@
[submodule "tmux/tmux-current-pane-hostname"]
path = config/tmux/plugins/tmux-current-pane-hostname
url = https://github.com/soyuka/tmux-current-pane-hostname.git
[submodule "cheat-tldr"]
path = config/cheat/cheatsheets/tldr
url = https://github.com/ivuorinen/cheatsheet-tldr.git

View File

@@ -13,6 +13,8 @@ git submodule add --name dotbot-pip \
# other repos
git submodule add --name cheat-community \
-f https://github.com/cheat/cheatsheets.git config/cheat/cheatsheets/community
git submodule add --name cheat-tldr \
-f https://github.com/ivuorinen/cheatsheet-tldr.git config/cheat/cheatsheets/tldr
# tmux plugin manager and plugins
git submodule add --name tmux/tmux-continuum \

View File

@@ -72,7 +72,7 @@ cheatpaths:
tags: [pure-bash-bible]
readonly: true
- name: tldr
path: ~/.dotfiles/config/cheat/cheatsheets/tldr
path: ~/.dotfiles/config/cheat/cheatsheets/tldr/tldr
tags: [tldr]
readonly: true
# While it requires no configuration here, it's also worth noting that

View File

@@ -1,78 +0,0 @@
#!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
TLDR_REQUIRED_TOOLS=(git cheat)
for t in ${TLDR_REQUIRED_TOOLS[@]}; do
! x-have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
done
TLDR_GIT="https://github.com/tldr-pages/tldr.git"
TLDR_SOURCE="source: $TLDR_GIT"
TLDR_SYNTAX="syntax: markdown"
TLDR_TEMP_PREFIX=$(basename "$0")
TLDR_TEMP_DIR="$XDG_CACHE_HOME/cheat/tldr"
# If there's no .git, clone the folder
if [ ! -d "$TLDR_TEMP_DIR/.git" ]; then
msg_run "Starting to clone $TLDR_GIT"
git clone --depth 1 --single-branch -q "$TLDR_GIT" "$TLDR_TEMP_DIR" \
&& msg_done "Cloned $TLDR_GIT"
else
# Update the repo
msg_run "Starting to update $TLDR_GIT"
git -C "$TLDR_TEMP_DIR" reset --hard origin/main
git -C "$TLDR_TEMP_DIR" pull -q --depth 2 \
&& msg_done "Updated $TLDR_GIT"
fi
msg_run "Removing non-english translation files"
rm -rf "$TLDR_TEMP_DIR/pages.*"
# Fetch the destination directory from cheat defined directories.
TLDR_CHEAT_DEST="$(cheat -d | grep tldr | head -1 | awk '{print $2}')"
[ "$TLDR_CHEAT_DEST" = "" ] \
&& msg_err "cheat doesn't know about the destination" \
&& exit 1
if [ ! -d "$TLDR_CHEAT_DEST" ]; then
mkdir -p "$TLDR_CHEAT_DEST"
fi
for d in "$TLDR_TEMP_DIR"/pages/*; do
DIRNAME=$(basename "$d")
# echo "-> $DIRNAME ($d)"
SECTION_DIR="${TLDR_CHEAT_DEST}/$DIRNAME"
[ "$DIRNAME" = "common" ] && SECTION_DIR="${TLDR_CHEAT_DEST}"
TLDR_TAGS="tags: [$DIRNAME]"
if [ ! -d "$SECTION_DIR" ]; then
mkdir -p "$SECTION_DIR"
fi
for FILE in $d/*.md; do
BASENAME=$(basename "$FILE" .md)
FILENAME="${BASENAME%%.*}"
# echo "-> $FILE = $FILENAME"
TLDR_FILE="$SECTION_DIR/${BASENAME}"
# echo "-> dest: $TLDR_FILE"
# Update the original file for making the replacable value comparable
if [ -f "$FILE" ] && [ '---' != "$(head -1 < "$FILE")" ]; then
echo -e "---\n$TLDR_SYNTAX\n$TLDR_TAGS\n$TLDR_SOURCE\n---\n$(cat "$FILE")" > "$FILE"
fi
replacable "$FILE" "$TLDR_FILE"
override=$?
if [ "$override" -ne 0 ]; then
cp "$FILE" "$TLDR_FILE" && msg_run "Updated: $TLDR_FILE"
fi
done
done