summaryrefslogtreecommitdiffstats
path: root/setup
diff options
context:
space:
mode:
authorMichal Minář <mic.liamg@gmail.com>2018-01-15 18:55:25 +0100
committerMichal Minář <mic.liamg@gmail.com>2018-01-15 18:55:25 +0100
commita32436c3974643580b6f6374569ccb450ca4ae65 (patch)
treea489e205285b1df67fb76fa267d2dd8c9e6c45b1 /setup
parenta160a7246a707a4a7f164ed09bbae2626a9a51b1 (diff)
downloadrcs-a32436c3974643580b6f6374569ccb450ca4ae65.zip
rcs-a32436c3974643580b6f6374569ccb450ca4ae65.tar.gz
rcs-a32436c3974643580b6f6374569ccb450ca4ae65.tar.xz
(n)vim: support both editors
Signed-off-by: Michal Minář <mic.liamg@gmail.com>
Diffstat (limited to 'setup')
-rwxr-xr-xsetup113
1 files changed, 66 insertions, 47 deletions
diff --git a/setup b/setup
index 1f2b5b5..6da69e7 100755
--- a/setup
+++ b/setup
@@ -9,6 +9,10 @@ readonly ignore=( 'make-links' 'setup' '.gitignore' '.gitmodules' )
readonly directory_leaves=( '.config/systemd/user' '.tmuxinator' )
readonly nvim_plug_init_path="${HOME}/.local/share/nvim/site/autoload/plug.vim"
+declare -A additional_links=(
+ [.vimrc]=.config/nvim/init.vim
+)
+
function abspath {
# convert relative path to absolute one
# http://www.linuxquestions.org/questions/programming-9/bash-script-return-full-path-and-filename-680368/page3.html#post4309783
@@ -26,11 +30,11 @@ function abspath {
fi
}
-src="$(dirname "$0")"
-if [[ "${src}" == '.' ]]; then
- src="$(pwd)"
+repo="$(dirname "$0")"
+if [[ "${repo}" == '.' ]]; then
+ repo="$(pwd)"
else
- src="$(abspath "${src}")"
+ repo="$(abspath "${repo}")"
fi
no_confirm=0
@@ -73,65 +77,80 @@ function make_regexp() {
readonly re_ignore="$(make_regexp "${ignore[@]}")"
readonly re_leaves="$(make_regexp "${directory_leaves[@]}")"
+function make_link() {
+ local dstpath pth elem elems prompt rc
+ local src="$1" # path to the file in this repository to link
+ local dst="$2" # destination file path relative to the home directory
+ local dir="$(dirname "${src}")"
+ local dstpath="${HOME}/${dst}"
+
+ if [[ "${dir}" != '.' ]]; then
+ IFS=/ read -a elems <<<"${dir}"
+ pth="${HOME}"
+ for elem in "${elems[@]}"; do
+ pth="${pth}/${elem}"
+ if [[ "${pth#${HOME}/}" =~ ${re_leaves} ]]; then
+ return
+ fi
+ if [[ -L "${pth}" || ( -e "${pth}" && ! -d "${pth}" ) ]]; then
+ prompt="\"${pth}\" is not a directory. Do you want to make"
+ prompt+=" it a directory? [(y)es/(N)o/(i)gnore/(q)uit] "
+ confirm_remove "${prompt}" "${pth}" && rc=$? || rc=$?
+ case "${rc}" in
+ 1) return 2; ;;
+ 2) return; ;;
+ esac
+ fi
+ if [[ ! -e "${pth}" ]]; then
+ mkdir -vp "${pth}"
+ fi
+ done
+ fi
+
+ if [[ -e "${dstpath}" && ! -L "${dstpath}" ]]; then
+ prompt="File \"${dstpath}\" exists do you want to remove it?"
+ prompt+=" [(y)es/(N)o/(q)uit] "
+ confirm_remove "${prompt}" "${dstpath}" && rc=$? || rc=$?
+ case "${rc}" in
+ 1) return 2; ;;
+ 2) return; ;;
+ esac
+ elif [[ -e "${dstpath}" && -L "${dstpath}" && "$(readlink "${dstpath}")" == "${repo}/${src}" ]]; then
+ return
+ fi
+
+ ln -vsf "${repo}/${src}" "${dstpath}"
+}
+
function make_links() {
- local cname dir dstpath l pth elem elems prompt rc
+ local cname dir
while IFS=$'\n' read -u 3 -r l; do
cname="$(basename "${l}")"
dir="$(dirname "${l}")"
- dstpath="${HOME}/${l}"
[[ "${dir}" =~ ${re_leaves} ]] && continue
- if [[ "${dir}" != '.' ]]; then
- IFS=/ read -a elems <<<"${dir}"
- pth="${HOME}"
- for elem in "${elems[@]}"; do
- pth="${pth}/${elem}"
- if [[ "${pth#${HOME}/}" =~ ${re_leaves} ]]; then
- continue
- fi
- if [[ -L "${pth}" || ( -e "${pth}" && ! -d "${pth}" ) ]]; then
- prompt="\"${pth}\" is not a directory. Do you want to make"
- prompt+=" it a directory? [(y)es/(N)o/(i)gnore/(q)uit] "
- confirm_remove "${prompt}" "${pth}" && rc=$? || rc=$?
- case "${rc}" in
- 1) break 2; ;;
- 2) continue 2; ;;
- esac
- fi
- if [[ ! -e "${pth}" ]]; then
- mkdir -vp "${pth}"
- fi
- done
- fi
-
- if [[ -e "${dstpath}" && ! -L "${dstpath}" ]]; then
- prompt="File \"${dstpath}\" exists do you want to remove it?"
- prompt+=" [(y)es/(N)o/(q)uit] "
- confirm_remove "${prompt}" "${dstpath}" && rc=$? || rc=$?
- case "${rc}" in
- 1) break; ;;
- 2) continue; ;;
- esac
- elif [[ -e "${dstpath}" && -L "${dstpath}" && "$(readlink "${dstpath}")" == "${src}/${l}" ]]; then
- continue
- fi
-
- ln -vsf "${src}/${l}" "${dstpath}"
+ make_link "${l}" "${l}" && rc=$? || rc=$?
+ [[ "${rc}" == 2 ]] && return
done 3< <(git ls-files | egrep -v "${re_ignore}"; printf '%s\n' "${directory_leaves[@]}")
+
+ for dst in "${!additional_links[@]}"; do
+ make_link "${additional_links[$dst]}" "${dst}"
+ done
}
+# see https://github.com/junegunn/vim-plug#neovim
+curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
+ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
+mkdir -p ~/.vim/autoload ||:
+ln -sf ~/.local/share/nvim/site/autoload/plug.vim ~/.vim/autoload/
+
function setup_neovim() {
if ! which nvim >/dev/null 2>&1; then
echo "neovim is not installed!"
return 1
fi
- if ! [[ -e "${nvim_plug_init_path}" ]]; then
- curl -fLo "${nvim_plug_init_path}" --create-dirs \
- https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- fi
-
nvim '+PlugInstall' '+qall'
}