From 523bec769f8e44da28beac935b1b79be22049a20 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Wed, 21 Feb 2024 14:21:29 +0200 Subject: [PATCH] feat(config): add tldr to cheat as a submodule --- .gitmodules | 3 ++ add-submodules.sh | 2 + config/cheat/cheatsheets/tldr | 1 + config/cheat/conf.yml | 2 +- scripts/install-cheat-tldr.sh | 78 ----------------------------------- 5 files changed, 7 insertions(+), 79 deletions(-) create mode 160000 config/cheat/cheatsheets/tldr delete mode 100755 scripts/install-cheat-tldr.sh diff --git a/.gitmodules b/.gitmodules index 21898a1..de9c0e9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/add-submodules.sh b/add-submodules.sh index 61be931..c43d143 100755 --- a/add-submodules.sh +++ b/add-submodules.sh @@ -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 \ diff --git a/config/cheat/cheatsheets/tldr b/config/cheat/cheatsheets/tldr new file mode 160000 index 0000000..2c475fa --- /dev/null +++ b/config/cheat/cheatsheets/tldr @@ -0,0 +1 @@ +Subproject commit 2c475fa62d87b1f24d402cf395a4d5d4c12f8efe diff --git a/config/cheat/conf.yml b/config/cheat/conf.yml index e799204..4bfeb8a 100644 --- a/config/cheat/conf.yml +++ b/config/cheat/conf.yml @@ -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 diff --git a/scripts/install-cheat-tldr.sh b/scripts/install-cheat-tldr.sh deleted file mode 100755 index edbdd66..0000000 --- a/scripts/install-cheat-tldr.sh +++ /dev/null @@ -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