Skip to content

Commit

Permalink
feat(bash-completion): prevent space after profile completion .
Browse files Browse the repository at this point in the history
When tab completing a profile, an unwanted space is added after the
period `.`, necessitating hitting backspace before further completions
can be accessed.

The implementation here was based on the following resources:

* https://stackoverflow.com/a/66151065
  - Add spaces to the end of some Bash autocomplete options,
    but not to others?
* https://stackoverflow.com/a/19271994
  - How can I check the last character in a string in bash?

An alternative to checking for the last character is using regex:

* https://stackoverflow.com/a/21425089
  - How to check if the last string character equals '*' in Bash?
  • Loading branch information
myii committed Sep 29, 2024
1 parent 4181d9e commit cc68b18
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/completion/bash-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ function _resticprofile() {
;;
esac
fi

if [[ ! "${COMPREPLY[*]}" == *. ]]; then
# Add space if the last character is not a '.'
compopt +o nospace
fi
}

# Registering the completion
complete -F _resticprofile resticprofile
complete -F _resticprofile -o nospace resticprofile

#
# __resticprofile_get_other_completions
Expand Down

0 comments on commit cc68b18

Please sign in to comment.