Skip to content

Commit

Permalink
bash-completion: ignore hidden files
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus Wallgren committed Dec 3, 2016
1 parent 7b1fa74 commit 6323faa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions notes.bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _notes_complete_notes() {
local items=($(compgen -f "$notes_dir/$1" | sort ))
IFS="$OLD_IFS"
for item in "${items[@]}"; do
[[ $item =~ /\.[^/]*$ ]] && continue
[[ -d $item ]] && item="$item/"
local filename=${item#$notes_dir/}
COMPREPLY+=("${filename%.md}")
Expand Down
8 changes: 8 additions & 0 deletions test/test-bash-completion.bats
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ teardown() {
assert_equal "${COMPREPLY[0]}" 'my note'
assert_equal 1 "${#COMPREPLY[@]}"
}

@test "Should ignore hidden files" {
touch "$NOTES_DIRECTORY/note1.md"
touch "$NOTES_DIRECTORY/.hiddennote.md"
_notes_complete_notes ""
assert_equal "${COMPREPLY[0]}" 'note1'
assert_equal 1 "${#COMPREPLY[@]}"
}

0 comments on commit 6323faa

Please sign in to comment.