From ca2b325dff8eb322f373907b06de4f9b490aeb06 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Sat, 30 Dec 2023 23:06:23 +0100 Subject: [PATCH] feat: Print README if present on directory change --- debian.sh | 1 + home/.zshrc | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/debian.sh b/debian.sh index b64dfde..40a9876 100755 --- a/debian.sh +++ b/debian.sh @@ -140,6 +140,7 @@ install_cli_tools() { just --completions zsh > "${ZSH_COMPLETIONS_DIR}/_just" sudo apt install --yes \ + bat \ direnv \ dnsutils \ fd-find \ diff --git a/home/.zshrc b/home/.zshrc index a108347..cd3b7e1 100644 --- a/home/.zshrc +++ b/home/.zshrc @@ -27,6 +27,31 @@ plugins=( export ZSH_COLORIZE_STYLE="dracula" +# ===================================================================================== +# Hooks +# ===================================================================================== + +function print_readme() { + local line_length=10 + + for readme in README.md README.rst README.txt README; do + if [[ -f "$readme" ]]; then + if command -v batcat >/dev/null 2>&1; then + batcat --line-range=:"$line_length" "$readme" + elif command -v bat >/dev/null 2>&1; then + bat --line-range=:"$line_length" "$readme" + else + head -n "$line_length" "$readme" + fi + break + fi + done +} + +autoload -U add-zsh-hook +# Print README on directory change +add-zsh-hook chpwd print_readme + # ===================================================================================== # Custom functions # =====================================================================================