diff --git a/bootstrap.sh b/bootstrap.sh index d0c6daa..99264c2 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -4,6 +4,7 @@ declare -A configs=( ["$PWD/config/.bashrc"]="$HOME/.bashrc" ["$PWD/config/.inputrc"]="$HOME/.inputrc" ["$PWD/config/.gitconfig"]="$HOME/.gitconfig" + ["$PWD/config/.tmux.conf"]="$HOME/.tmux.conf" ["$PWD/config/nvim"]="$HOME/.config/nvim" ["$PWD/config/alacritty"]="$HOME/.config/alacritty" ["$PWD/config/rofi"]="$HOME/.config/rofi" @@ -18,12 +19,15 @@ declare -A configs=( ["$PWD/config/picom.conf"]="$HOME/.config/picom.conf" ) +bashCompletionsDir="$HOME/.config/bash-completions" + usage() { echo "usage: (./)bootstrap.sh [-S][-R]" echo echo " -S installs all this shit" echo " -R removes all this shit" + echo " -I downloads bash completions" } if [ $# -eq 0 ] ; then @@ -59,4 +63,27 @@ do rm -rf ${configs[$config]} done +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 fi diff --git a/config/.bashrc b/config/.bashrc index 252e07b..8621895 100644 --- a/config/.bashrc +++ b/config/.bashrc @@ -1,48 +1,6 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return -gitCompletionPath="~/.config/gitcompletion.bash" - -# Install git completion if needed -if [[ ! -f ~/.config/git-completion.bash ]] ; then - curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash > ~/.config/git-completion.bash -fi -source ~/.config/git-completion.bash - -# _ _ ___ _ ____ _____ ____ -# / \ | | |_ _| / \ / ___|| ____/ ___| -# / _ \ | | | | / _ \ \___ \| _| \___ \ -# / ___ \| |___ | | / ___ \ ___) | |___ ___) | -# /_/ \_\_____|___/_/ \_\____/|_____|____/ -# - -alias sudo='sudo ' - -alias ls='ls --color=auto' -alias lah='ls -lah' -alias la='ls -a' - -alias ed='$EDITOR' -alias c='clear' - -alias t='tmux' - -alias pacman='pacman --color always' -alias yay='yay --color always' - -# Git aliases -alias g='git' -alias ga='git add' -alias gc='git commit' -alias gp='git push' -alias gl='git log' -alias gs='git status' -alias gd='git diff' -alias gb='git branch' -alias gt='git tag' -alias gch='git checkout' - - # _____ _ ___ _____ ____ ___ _ _ __ __ _____ _ _ _____ # | ____| \ | \ \ / /_ _| _ \ / _ \| \ | | \/ | ____| \ | |_ _| # | _| | \| |\ \ / / | || |_) | | | | \| | |\/| | _| | \| | | | @@ -66,6 +24,20 @@ PYTHON_BIN="$HOME/.local/bin" export PATH="$PATH:$MY_BIN:$PYTHON_BIN:$RUSTBIN:$GOBIN" + +completionsDir="$HOME/.config/bash-completions" +# Source bash completions inside bash-completions directory +if [[ -d "$completionsDir" ]] ; then + completions=($completionsDir/*) + for cmp in ${completions[@]} + do + source "$cmp" + done +fi + +# Install aliases +source $DOTFILES/config/bash/aliases.bash + # Find arch package by binary source /usr/share/doc/pkgfile/command-not-found.bash diff --git a/config/bash/aliases.bash b/config/bash/aliases.bash new file mode 100644 index 0000000..fc643c1 --- /dev/null +++ b/config/bash/aliases.bash @@ -0,0 +1,34 @@ +#! /bin/bash + +declare -A aliases=( + ["sudo"]="sudo " + + ["ls"]="ls --color=auto" + ["l"]="ls" + ["lah"]="ls -lah" + ["la"]="ls -a" + ["ll"]="ls -l" + ["ed"]="$EDITOR" + ["c"]="clear" + ["t"]="tmux" + ["pacman"]="pacman --color auto" + ["yay"]="yay --color auto" + + # Git + ["g"]="git" + ["ga"]="git add" + ["gc"]="git commit" + ["gp"]="git push" + ["gl"]="git log" + ["gs"]="git status" + ["gd"]="git diff" + ["gt"]="git tag" + ["gch"]="git checkout" +) + +for alias in ${!aliases[@]} +do + cmd=${aliases[$alias]} + alias "$alias"="$cmd" + complete -F _complete_alias "$alias" +done