Skip to content

Commit

Permalink
Improve bash tab completion (#26)
Browse files Browse the repository at this point in the history
* Update bash completion to remove older caches

* Update completions to support XDG-spec, and suppress 'rm' errors when no files were found

* Updated bash completions for smarter deletion, now only deletes files with the right names
  • Loading branch information
BWindey authored Oct 7, 2024
1 parent f4bb3b6 commit fa1da9e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions completions/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
# $3 = word before word being completed

_commandtrein(){
# Use a cache that will update every week
file="$HOME/.cache/commandtrein/$(date +'%m-%Y').txt"
# Use a cache that will update every week
cache_dir="${XDG_CACHE_DIR:-$HOME/.cache}/commandtrein"
file="${cache_dir}/$(date +'%m-%Y').txt"

if ! [ -f "$file" ]; then
mkdir -p "$HOME/.cache/commandtrein/"
# Assumes that the binary is called commandtrein
mkdir -p "${cache_dir}"
# Remove older caches
find "${cache_dir}" \
-maxdepth 1 \
-type f \
-name "[0-9][0-9]-2[0-9][0-9][0-9].txt" \
-delete
# Assumes that the binary is called commandtrein
commandtrein search > "$file"
fi
mapfile -t COMPREPLY < <(grep "$2" "$file")
Expand Down

0 comments on commit fa1da9e

Please sign in to comment.