Initial commit

This commit is contained in:
2024-02-21 13:18:38 +02:00
commit 4e88a1b42f
7 changed files with 218 additions and 0 deletions

21
.github/LICENSE.md vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Ismo Vuorinen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

36
.github/README.md vendored Normal file
View File

@@ -0,0 +1,36 @@
# ivuorinen/cheatsheet-tldr
This repository is a collection of [cheat/cheat](https://github.com/cheat/cheat)
compatible cheatsheets derived from [tldr](https://github.com/tldr-pages/tldr) pages.
## Installation
Add the cheatsheets to your `cheat` installation by cloning this repository to
`~/.cheat/cheatsheets/tldr`:
```sh
git clone https://github.com/ivuorinen/cheatsheet-tldr.git ~/.cheat/cheatsheets/tldr
```
Configure your `cheat.yaml` to include the cheatsheets:
```yaml
- name: tldr
path: ~/.cheat/cheatsheets/tldr
tags: [tldr]
readonly: true
```
## Usage
Use `cheat` as you normally would, but include the `tldr` tag to filter the
cheatsheets:
```sh
cheat --tags tldr
```
## License
Files under `.github/` are licensed under the [MIT License](LICENSE.md).
TLDR pages licensed under [CC-BY-4.0](https://github.com/tldr-pages/tldr/blob/main/LICENSE.md).

4
.github/renovate.json vendored Normal file
View File

@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>ivuorinen/.github:renovate-config"]
}

72
.github/run.sh vendored Executable file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Create cheat/cheat compatible versions of the english tldr pages
# Copyright (c) 2024 Ismo Vuorinen <https://github.com/ivuorinen>
# Script licensed under the MIT License
# https://github.com/ivuorinen/cheatsheet-tldr/blob/main/.github/LICENSE.md
# TLDR pages licensed under CC-BY-4.0
# https://github.com/tldr-pages/tldr/blob/main/LICENSE.md
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Running: $DIR/run.sh"
echo "Working directory: $DIR"
source "$DIR/shared.sh"
TLDR_GIT="https://github.com/tldr-pages/tldr.git"
TLDR_SOURCE="source: $TLDR_GIT"
TLDR_SYNTAX="syntax: markdown"
TLDR_TEMP_DIR="$(realpath "$DIR"/..)/__tldr-temp"
TLDR_CHEAT_DEST="$(realpath "$DIR"/../)"
if [ -d "$TLDR_TEMP_DIR" ]; then
rm -rf "$TLDR_TEMP_DIR"
fi
echo "TLDR_TEMP_DIR: $TLDR_TEMP_DIR"
echo "TLDR_CHEAT_DEST: $TLDR_CHEAT_DEST"
git clone \
--depth 1 \
--single-branch \
-q "$TLDR_GIT" "$TLDR_TEMP_DIR" || exit 1
rm -rf "$TLDR_TEMP_DIR/pages.*"
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: [tldr, $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 replaceable 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
replaceable "$FILE" "$TLDR_FILE"
override=$?
if [ "$override" -ne 0 ]; then
cp "$FILE" "$TLDR_FILE" && echo "Updated: $TLDR_FILE"
fi
done
done
rm -rf "$TLDR_TEMP_DIR"

50
.github/shared.sh vendored Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# return sha256sum for file
# $1 - filename (string)
function get_sha256sum()
{
sha256sum "$1" | head -c 64
}
# Replaceable file
#
# $1 - filename (string)
# $2 - filename (string)
#
# Returns 1 when replaceable, 0 when not replaceable.
function replaceable()
{
FILE1="$1"
FILE2="$2"
[[ ! -r "$FILE1" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "File 1 ($FILE1) does not exist"
return 0
}
[[ ! -r "$FILE2" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "File 2 ($FILE2) does not exist, replaceable"
return 1
}
FILE1_HASH=$(get_sha256sum "$FILE1")
FILE2_HASH=$(get_sha256sum "$FILE2")
[[ $FILE1_HASH = "" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "Could not get hash for file 1 ($FILE1)"
return 0
}
[[ $FILE2_HASH = "" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "Could not get hash for file 2 ($FILE2), replaceable"
return 1
}
[[ "$FILE1_HASH" == "$FILE2_HASH" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_ok "Files match, not replaceable: $FILE1"
return 0
}
[[ $VERBOSE -eq 1 ]] && msg_warn "Files do not match ($FILE1_HASH != $FILE2_HASH), replaceable"
return 1
}

34
.github/workflows/cheatsheets.yaml vendored Normal file
View File

@@ -0,0 +1,34 @@
---
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup git config
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Build
run: |
echo "Building cheatsheets"
bash .github/run.sh
echo "Done"
- name: Commit and push changes
run: |
git add .
git commit -m "Update cheatsheets"
git push

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
__tldr-temp