mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-15 02:53:34 +00:00
Feat: Pure Bash Bible and TLDR in cheat
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,3 +5,5 @@ Brewfile.lock.json
|
|||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
config/fzf
|
config/fzf
|
||||||
|
config/cheat/cheatsheets/pure-bash-bible/*
|
||||||
|
config/cheat/cheatsheets/tldr/*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
||||||
editor: $EDITOR
|
# editor: $EDITOR
|
||||||
|
|
||||||
# Should 'cheat' always colorize output?
|
# Should 'cheat' always colorize output?
|
||||||
colorize: true
|
colorize: true
|
||||||
@@ -8,7 +8,7 @@ colorize: true
|
|||||||
# Which 'chroma' colorscheme should be applied to the output?
|
# Which 'chroma' colorscheme should be applied to the output?
|
||||||
# Options are available here:
|
# Options are available here:
|
||||||
# https://github.com/alecthomas/chroma/tree/master/styles
|
# https://github.com/alecthomas/chroma/tree/master/styles
|
||||||
style: catppuccin-mocha
|
style: "catppuccin"
|
||||||
|
|
||||||
# Which 'chroma' "formatter" should be applied?
|
# Which 'chroma' "formatter" should be applied?
|
||||||
# One of: "terminal", "terminal256", "terminal16m"
|
# One of: "terminal", "terminal256", "terminal16m"
|
||||||
@@ -63,14 +63,22 @@ cheatpaths:
|
|||||||
# 'readonly': shall user-created ('cheat -e') cheatsheets be saved here?
|
# 'readonly': shall user-created ('cheat -e') cheatsheets be saved here?
|
||||||
- name: community
|
- name: community
|
||||||
path: ~/.config/cheat/cheatsheets/community
|
path: ~/.config/cheat/cheatsheets/community
|
||||||
tags: [community]
|
tags: [ community ]
|
||||||
readonly: true
|
readonly: true
|
||||||
# If you have personalized cheatsheets, list them last. They will take
|
# If you have personalized cheatsheets, list them last. They will take
|
||||||
# precedence over the more global cheatsheets.
|
# precedence over the more global cheatsheets.
|
||||||
- name: personal
|
- name: personal
|
||||||
path: ~/.config/cheat/cheatsheets/personal
|
path: ~/.dotfiles/config/cheat/cheatsheets/personal
|
||||||
tags: [personal]
|
tags: [ personal ]
|
||||||
readonly: false
|
readonly: false
|
||||||
|
- name: pure-bash-bible
|
||||||
|
path: ~/.dotfiles/config/cheat/cheatsheets/pure-bash-bible
|
||||||
|
tags: [ pure-bash-bible ]
|
||||||
|
readonly: true
|
||||||
|
- name: tldr
|
||||||
|
path: ~/.dotfiles/config/cheat/cheatsheets/tldr
|
||||||
|
tags: [ tldr ]
|
||||||
|
readonly: true
|
||||||
|
|
||||||
# While it requires no configuration here, it's also worth noting that
|
# While it requires no configuration here, it's also worth noting that
|
||||||
# cheat will automatically append directories named '.cheat' within the
|
# cheat will automatically append directories named '.cheat' within the
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
~/.cache/git:
|
~/.cache/git:
|
||||||
~/.config:
|
~/.config:
|
||||||
~/.config/cheat/cheatsheets/personal:
|
~/.config/cheat/cheatsheets/personal:
|
||||||
|
~/.config/cheat/cheatsheets/pure-bash-bible:
|
||||||
|
~/.config/cheat/cheatsheets/tldr:
|
||||||
~/.local:
|
~/.local:
|
||||||
~/.local/run:
|
~/.local/run:
|
||||||
~/.local/share:
|
~/.local/share:
|
||||||
|
|||||||
54
scripts/install-cheat-purebashbible.sh
Executable file
54
scripts/install-cheat-purebashbible.sh
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
|
||||||
|
# shellcheck source=shared.sh
|
||||||
|
source "$HOME/.dotfiles/scripts/shared.sh"
|
||||||
|
|
||||||
|
PBB_REQUIRED_TOOLS=(basename git mkdir cheat ls grep head awk cp echo rm)
|
||||||
|
for t in ${PBB_REQUIRED_TOOLS[@]}; do
|
||||||
|
! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
|
||||||
|
done
|
||||||
|
|
||||||
|
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_PREFIX=$(basename "$0")
|
||||||
|
PBB_TEMP_DIR="/tmp/pbb-$(rnd)"
|
||||||
|
|
||||||
|
# If there's no .git, clone the folder
|
||||||
|
if [ ! -d "$PBB_TEMP_DIR/.git" ]; then
|
||||||
|
git clone "$PBB_GIT" "$PBB_TEMP_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PBB_CHAPTERS=$(ls -1v "$PBB_TEMP_DIR"/manuscript/chapter*)
|
||||||
|
CHEAT_DEST="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')"
|
||||||
|
|
||||||
|
if [ ! -d "$CHEAT_DEST" ]; then
|
||||||
|
mkdir -p "$CHEAT_DEST"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for f in ${PBB_CHAPTERS[@]}; do
|
||||||
|
# get all headers, take the first one, strip the # and return the first word in lowercase
|
||||||
|
HEADER=$(grep -e '^[#] ' "$f" | head -1 | awk '{print tolower($2)}')
|
||||||
|
CHEAT_FILE="$CHEAT_DEST/${HEADER}"
|
||||||
|
echo "(*) $CHEAT_FILE"
|
||||||
|
|
||||||
|
if [ ! -f "$CHEAT_FILE" ]; then
|
||||||
|
cp "$f" "$CHEAT_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$CHEAT_FILE"
|
||||||
|
rm "$CHEAT_FILE.bak"
|
||||||
|
|
||||||
|
# add tags if the file doesn't have them
|
||||||
|
if [ '---' != "$(head -1 < "$CHEAT_FILE")" ]; then
|
||||||
|
T="$PBB_SYNTAX\n$PBB_TAGS\n$PBB_SOURCE\n"
|
||||||
|
echo -e "---\n$T---\n$(cat "$CHEAT_FILE")" > "$CHEAT_FILE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
if [ -d "$PBB_TEMP_DIR" ]; then
|
||||||
|
rm -rf "$PBB_TEMP_DIR"
|
||||||
|
fi
|
||||||
73
scripts/install-cheat-tldr.sh
Executable file
73
scripts/install-cheat-tldr.sh
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
|
||||||
|
# shellcheck source=shared.sh
|
||||||
|
source "$HOME/.dotfiles/scripts/shared.sh"
|
||||||
|
|
||||||
|
TLDR_REQUIRED_TOOLS=(basename git mkdir cheat ls grep head awk cp echo rm)
|
||||||
|
for t in ${TLDR_REQUIRED_TOOLS[@]}; do
|
||||||
|
! 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_TAGS="tags: [bash]"
|
||||||
|
|
||||||
|
TLDR_TEMP_PREFIX=$(basename "$0")
|
||||||
|
TLDR_TEMP_DIR="/tmp/cheat-tldr-$(rnd)"
|
||||||
|
|
||||||
|
# If there's no .git, clone the folder
|
||||||
|
if [ ! -d "$TLDR_TEMP_DIR/.git" ]; then
|
||||||
|
git clone "$TLDR_GIT" "$TLDR_TEMP_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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)"
|
||||||
|
|
||||||
|
case "$DIRNAME" in
|
||||||
|
*common)
|
||||||
|
SECTION_DIR="${TLDR_CHEAT_DEST}"
|
||||||
|
TLDR_TAGS="tags: [common]"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
SECTION_DIR="${TLDR_CHEAT_DEST}/$DIRNAME"
|
||||||
|
TLDR_TAGS="tags: [$DIRNAME]"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
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/${FILENAME}"
|
||||||
|
# echo "-> dest: $TLDR_FILE"
|
||||||
|
|
||||||
|
if [ ! -f "$TLDR_FILE" ]; then
|
||||||
|
cp "$FILE" "$TLDR_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$TLDR_FILE" ] && [ '---' != "$(head -1 < "$TLDR_FILE")" ]; then
|
||||||
|
echo -e "---\n$TLDR_SYNTAX\n$TLDR_TAGS\n$TLDR_SOURCE\n---\n$(cat "$TLDR_FILE")" > "$TLDR_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
if [ -d "$TLDR_TEMP_DIR" ]; then
|
||||||
|
rm -rf "$TLDR_TEMP_DIR"
|
||||||
|
fi
|
||||||
@@ -224,3 +224,9 @@ function path_prepend
|
|||||||
path_remove "$1"
|
path_remove "$1"
|
||||||
PATH="$1${PATH:+":$PATH"}"
|
PATH="$1${PATH:+":$PATH"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Creates a random string
|
||||||
|
rnd()
|
||||||
|
{
|
||||||
|
echo $RANDOM | md5sum | head -c 20
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user