From fead5234aec876a5c108c95e38b5b769eb20458b Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Wed, 17 Nov 2021 19:16:51 +0300 Subject: [PATCH] Create __install_bash_completions function --- bootstrap.sh | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 99264c2..abb04b0 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,5 +1,12 @@ #!/bin/bash +# complete_alias is a script that allows to use completion in aliases +declare -A bashCompletions=( + ["complete_alias"]="https://raw.githubusercontent.com/cykerway/complete-alias/master/complete_alias" + ["tmux"]="https://raw.githubusercontent.com/Bash-it/bash-it/master/completion/available/tmux.completion.bash" + ["git"]="https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" +) + declare -A configs=( ["$PWD/config/.bashrc"]="$HOME/.bashrc" ["$PWD/config/.inputrc"]="$HOME/.inputrc" @@ -21,6 +28,23 @@ declare -A configs=( bashCompletionsDir="$HOME/.config/bash-completions" +__install_bash_completions() { + if [[ ! -d "$bashCompletionsDir" ]] ; then + mkdir "$bashCompletionsDir" + fi + + for cmp in "${!bashCompletions[@]}" + do + source=${bashCompletions[$cmp]} + dest="$bashCompletionsDir/$cmp.bash" + + if [[ ! -f "$dest" ]] ; then + echo "Downloading $cmp completion" + curl "$source" -o "$dest" &> /dev/null + fi + done +} + usage() { echo "usage: (./)bootstrap.sh [-S][-R]" @@ -52,6 +76,10 @@ git clone --depth 1 https://github.com/wbthomason/packer.nvim \ # Install vim plugins nvim -c "PackerInstall" +if [[ ! -d "$bashCompletionsDir" ]] ; then + __install_bash_completions +fi + fi # Remove all configs @@ -67,23 +95,8 @@ rm -rf "$bashCompletionsDir" fi -# complete_alias is a script that allows to use completion in aliases -declare -A bashCompletions=( - ["complete_alias"]="https://raw.githubusercontent.com/cykerway/complete-alias/master/complete_alias" - ["tmux"]="https://raw.githubusercontent.com/Bash-it/bash-it/master/completion/available/tmux.completion.bash" - ["git"]="https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" -) # Install bash completions defined in hashmap above if [ "$1" = "-I" ] ; then -for cmp in "${!bashCompletions[@]}" -do - source=${bashCompletions[$cmp]} - dest="$bashCompletionsDir/$cmp.bash" - - if [[ ! -f "$dest" ]] ; then - echo "Downloading $cmp completion" - curl "$source" -o "$dest" &> /dev/null - fi -done + __install_bash_completions fi