From 10c7e768a526933fabf03f74f47e8b3d91dcad32 Mon Sep 17 00:00:00 2001 From: thek4n Date: Wed, 20 Nov 2024 20:37:27 +0300 Subject: [PATCH] feature t script --- home/user/.config/git/ignore | 1 + home/user/.config/tmux/mappings.conf | 2 +- home/user/.config/zsh/aliases | 2 +- home/user/.local/bin/t | 39 ++++++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/home/user/.config/git/ignore b/home/user/.config/git/ignore index 8df68c9..f09e5e2 100644 --- a/home/user/.config/git/ignore +++ b/home/user/.config/git/ignore @@ -15,6 +15,7 @@ __pycache__/ *.spec .env +*.env *.log *.bak *~ diff --git a/home/user/.config/tmux/mappings.conf b/home/user/.config/tmux/mappings.conf index 9c34287..ec8b8fc 100644 --- a/home/user/.config/tmux/mappings.conf +++ b/home/user/.config/tmux/mappings.conf @@ -39,7 +39,7 @@ bind-key Y { display-popup -E -w 90% -h 80% "nvim /tmp/tmux-buffer" } -bind t display-popup -E -h 70% -w 60% +bind t display-popup -E -h 70% -w 60% -d "${HOME}" diff --git a/home/user/.config/zsh/aliases b/home/user/.config/zsh/aliases index aeefb16..7895109 100644 --- a/home/user/.config/zsh/aliases +++ b/home/user/.config/zsh/aliases @@ -32,7 +32,7 @@ GREP_OPTIONS=( ) alias grep='grep $GREP_OPTIONS' -alias g='grep --dereference-recursive' +alias g='grep --dereference-recursive --line-number' alias _='sudo' alias root='sudo --login TMOUT=450' diff --git a/home/user/.local/bin/t b/home/user/.local/bin/t index 2a69626..69204d0 100755 --- a/home/user/.local/bin/t +++ b/home/user/.local/bin/t @@ -5,10 +5,40 @@ set -o errexit set -o nounset +readonly ENV_FILE=".t.env" readonly EXIT_SUCCESS=0 - readonly NOTES_DIR_BASE="${HOME}/.t" -readonly NOTES_DIR="${NOTES_DIR_BASE}/${t:-default}" +readonly DEFAULT_NAMESPACE="def" + + +find_file_up_fs() ( + file_to_find="${1}" + + while [ ! "$(pwd)" = "/" ] + do + if [ -f "${file_to_find}" ]; then + realpath "${file_to_find}" + break + fi + cd .. + done +) + +load_env_if_found() { + env_file="$(find_file_up_fs "./${ENV_FILE}")" + + if [ -n "${env_file}" ]; then + . "${env_file}" + fi +} + +if [ -z "${t+x}" ]; then + load_env_if_found +fi + + +readonly t="${t:-${DEFAULT_NAMESPACE}}" +readonly NOTES_DIR="${NOTES_DIR_BASE}/${t}" TAB="$(printf -- '\t')" readonly TAB @@ -58,6 +88,11 @@ get_notes_with_indexes() { SAVEIFS="${IFS}" IFS=';' + + if ${_TO_SHOW:-false}; then + printf -- '\033[1m# %s\033[0m\n\n' "${t}" + fi + index=1 for note in $(IFS="${IFS}" get_notes_sorted_by_access_time) do