From 80adf828d041fd30c2bfb584b2a1b12c53ad1a5a Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Fri, 2 Dec 2022 00:29:52 +0100 Subject: bash --- bash/10-vim-plugins.bash | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 bash/10-vim-plugins.bash (limited to 'bash/10-vim-plugins.bash') diff --git a/bash/10-vim-plugins.bash b/bash/10-vim-plugins.bash new file mode 100644 index 0000000..53c927d --- /dev/null +++ b/bash/10-vim-plugins.bash @@ -0,0 +1,77 @@ +function vim-add() { + source ~/.files + + local NAME=$(basename "$1") + + [ -d "$DOTFILEBASE/.vim/bundle-active" ] || mkdir "$DOTFILEBASE/.vim/bundle-active" + [ -d "$DOTFILEBASE/.vim/bundle/$NAME" ] || return 1 # no such plugin + [ -L "$DOTFILEBASE/.vim/bundle-active/$NAME" ] && return 2 # Already exists + + local OLD_PWD=$(pwd) + cd "$DOTFILEBASE/.vim/bundle-active/" + + ln -s "../bundle/$NAME" + + cd "$OLD_PWD" +} + +function vim-remove { + source ~/.files + + local NAME=$(basename "$1") + + [ -L "$DOTFILEBASE/.vim/bundle-active/$NAME" ] || exit 1 + rm "$DOTFILEBASE/.vim/bundle-active/$NAME" +} + +# 1: git clone url +function vim-install { + source ~/.files + + test $# -eq 1 || exit 1 + + echo "Installing $1" + + ( + cd "$DOTFILEBASE/.vim/bundle" || exit 1 + git submodule add "$1" || exit 2 + git commit -m "Added vim plugin module $1" + ) +} + +function _vim_plugins { + source ~/.files + local cur prev opts plugin + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="" + + for plugin in $DOTFILEBASE/.vim/bundle/*/; do + opts+=" $(basename $plugin)" + done + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} + +function _vim_plugins_active { + source ~/.files + local cur prev opts plugin + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="" + + for plugin in $DOTFILEBASE/.vim/bundle-active/*/; do + opts+=" $(basename $plugin)" + done + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} + +complete -F _vim_plugins vim-add +complete -F _vim_plugins_active vim-remove -- cgit v1.2.3