diff --git a/.bash_completion b/.bash_completion index 12460c3..fe593da 100644 --- a/.bash_completion +++ b/.bash_completion @@ -1,8 +1,11 @@ # ~/.bash_completion - Custom bash auto completions -# Enable bash completion for dotfiles manager (if installed) -[[ -x "$HOME/bin/dotfiles" ]] && source <($HOME/bin/dotfiles bash-completion) +shopt -s nullglob -# Include host-specific bash_completion -[[ -f ~/.bash_completion.local ]] && source ~/.bash_completion.local +# Include all files from ~/.bash_completion.d/ +if [[ -d ~/.bash_completion.d ]]; then + for f in ~/.bash_completion.d/*; do + [[ -f "$f" ]] && . "$f" + done +fi diff --git a/.bash_completion.d/10-dotfiles.sh b/.bash_completion.d/10-dotfiles.sh new file mode 100644 index 0000000..d60b66a --- /dev/null +++ b/.bash_completion.d/10-dotfiles.sh @@ -0,0 +1,3 @@ +# Enable bash completion for dotfiles manager (if installed) +[[ -x "$HOME/bin/dotfiles" ]] && source <($HOME/bin/dotfiles bash-completion) + diff --git a/bin/dotfiles b/bin/dotfiles index 4bca5fb..c5dfe17 100755 --- a/bin/dotfiles +++ b/bin/dotfiles @@ -2,7 +2,7 @@ ## ## binaryDiv's dotfiles management script -## Version 0.4.1 +## Version 0.4.2 ## usage() { @@ -74,11 +74,27 @@ case "$cmd" in echo "! Warning: $bin_dir is not in your PATH." fi - # Activate bash completion - if [[ ! -e "$homedir/.bash_completion" ]]; then - echo "* Installing user-defined bash completion" - "$0" link -q .bash_completion && - echo " Restart bash or run 'source $homedir/.bash_completion' to activate it now" + show_bash_restart_info= + + # Enable user-defined bash completion per directory + bashcompletion_filename=.bash_completion + if [[ ! -e "$homedir/$bashcompletion_filename" ]]; then + echo "* Installing user-defined bash completion (~/.bash_completion.d/)" + "$0" link -q "$bashcompletion_filename" && + show_bash_restart_info=1 + fi + mkdir -p "$homedir/.bash_completion.d" + + # Activate dotfiles bash completion + bashcompletion_dotfiles_filename=.bash_completion.d/10-dotfiles.sh + if [[ ! -e "$homedir/$bashcompletion_dotfiles_filename" ]]; then + echo "* Installing bash completion for dotfiles script" + "$0" link -q "$bashcompletion_dotfiles_filename" && + show_bash_restart_info=1 + fi + + if [[ -n $show_bash_restart_info ]]; then + echo " Restart bash or run 'source $homedir/.bash_completion' to activate it now" fi echo "* Configuring git settings"