feat(tmux-projectinator): Add cache file

This commit is contained in:
Tanguy Herbron 2024-01-13 15:59:14 +01:00
parent 0ede957833
commit be5f66f574

View File

@ -5,6 +5,7 @@ set -o emacs
bind '"\e": "\C-W\c-d"'
OPEN_MODE="new_pane"
CACHE_FILE=~/.cache/project_list
debug () {
if [ "$VERBOSE" = true ]; then
@ -50,6 +51,12 @@ open_new_pane () {
tmux display-popup -C
}
update_project_list_cache() {
PROJECT_LIST_UPDATE=$(find ~/* -name .git -type d -not -path "~/.*" -prune 2>/dev/null | sed 's/\/.git/\n/g' | sed "s/$(echo $HOME | sed 's/\//\\\//g')//" | cut -d'/' -f2-)
echo $PROJECT_LIST_UPDATE > $CACHE_FILE
}
while getopts "lv" option; do
debug "Reading option $option"
case $option in
@ -68,15 +75,28 @@ CUSTOM_SESSIONS[Projects]=Halia
spinner &
spinner_pid=$!
PROJECT_LIST=$(find ~/* -name .git -type d -not -path "~/.*" -prune 2>/dev/null)
if [ ! -f "$CACHE_FILE" ]; then
debug "Start synchronous project list cache update"
update_project_list_cache
else
debug "Start asynchronous project list cache update"
update_project_list_cache &
fi
PROJECT_LIST=$(cat $CACHE_FILE)
kill $spinner_pid
SELECTED=$(echo $PROJECT_LIST | sed 's/\/.git/\n/g' | sed "s/$(echo $HOME | sed 's/\//\\\//g')//" | cut -d'/' -f2- | fzf)
SELECTED=$(echo $PROJECT_LIST | tr ' ' '\n' | fzf)
debug "Selected $SELECTED"
PROJECT_PATH=$(echo $PROJECT_LIST | sed 's/\/.git/\n/g' | grep "${SELECTED}$")
# Quit if nothing has been selected
if [ ! $SELECTED ]; then
exit 0
fi
PROJECT_PATH=$(realpath ~/${SELECTED})
PROJECT_ROOT=$(echo $SELECTED | cut -d '/' -f1)
PROJECT_NAME=$(echo $SELECTED | rev | cut -d '/' -f1 | rev)