summaryrefslogtreecommitdiffstats
path: root/setup
diff options
context:
space:
mode:
authorMichal Minář <mic.liamg@gmail.com>2017-07-18 21:36:30 +0200
committerMichal Minář <mic.liamg@gmail.com>2017-07-18 21:36:30 +0200
commit626039c48780bf19b9608d1b2206511a884072c1 (patch)
treecf3e36d67ccd1b6fbaf78a0b95209176d8e65d72 /setup
parent87198a40c90818c13be0a6cb735efa7503e65359 (diff)
downloadrcs-626039c48780bf19b9608d1b2206511a884072c1.zip
rcs-626039c48780bf19b9608d1b2206511a884072c1.tar.gz
rcs-626039c48780bf19b9608d1b2206511a884072c1.tar.xz
Cosmetic changes in setup script
Signed-off-by: Michal Minář <mic.liamg@gmail.com>
Diffstat (limited to 'setup')
-rwxr-xr-xsetup87
1 files changed, 44 insertions, 43 deletions
diff --git a/setup b/setup
index 2a0103b..1f2b5b5 100755
--- a/setup
+++ b/setup
@@ -12,27 +12,25 @@ readonly nvim_plug_init_path="${HOME}/.local/share/nvim/site/autoload/plug.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
- if [[ -d "$1" ]]
- then
+ if [[ -d "$1" ]]; then
pushd "$1" >/dev/null
- pwd
+ pwd
popd >/dev/null
- elif [[ -e $1 ]]
- then
- pushd $(dirname $1) >/dev/null
- echo $(pwd)/$(basename $1)
+ elif [[ -e "$1" ]]; then
+ pushd "$(dirname "$1")" >/dev/null
+ echo "$(pwd)/$(basename "$1")"
popd >/dev/null
else
- echo $1 does not exist! >&2
+ printf '%s does not exist!\n' "$1" >&2
return 127
fi
}
-src=`dirname $0`
-if [[ "$src" == '.' ]]; then
- src=`pwd`
+src="$(dirname "$0")"
+if [[ "${src}" == '.' ]]; then
+ src="$(pwd)"
else
- src=`abspath "$src"`
+ src="$(abspath "${src}")"
fi
no_confirm=0
@@ -49,19 +47,19 @@ function confirm_remove() {
local path="$2"
local answer
- if [[ "$no_confirm" == 1 ]]; then
+ if [[ "${no_confirm}" == 1 ]]; then
answer=y
else
- read -p "$prompt" answer
+ read -p "${prompt}" answer
fi
- if [[ "$answer" =~ ^[[:space:]]*[yY][[:space:]]*$ ]]; then
- rm -rvf "$path"
- elif [[ "$answer" =~ ^[[:space:]]*[qQ][[:space:]]*$ ]]; then
+ if [[ "${answer}" =~ ^[[:space:]]*[yY][[:space:]]*$ ]]; then
+ rm -rvf "${path}"
+ elif [[ "${answer}" =~ ^[[:space:]]*[qQ][[:space:]]*$ ]]; then
return 1
- elif [[ "$answer" =~ ^[[:space:]]*[iI][[:space:]]*$ ]]; then
+ elif [[ "${answer}" =~ ^[[:space:]]*[iI][[:space:]]*$ ]]; then
: # ignore
else
- if ! [[ "$answer" =~ ^[[:space:]]*[nN][[:space:]]*$ ]]; then
+ if ! [[ "${answer}" =~ ^[[:space:]]*[nN][[:space:]]*$ ]]; then
echo "Assuming no."
fi
return 2
@@ -72,54 +70,55 @@ function make_regexp() {
IFS='|'
echo "^($*)$"
}
-readonly re_ignore=`make_regexp "${ignore[@]}"`
-readonly re_leaves=`make_regexp "${directory_leaves[@]}"`
+readonly re_ignore="$(make_regexp "${ignore[@]}")"
+readonly re_leaves="$(make_regexp "${directory_leaves[@]}")"
function make_links() {
+ local cname dir dstpath l pth elem elems prompt rc
while IFS=$'\n' read -u 3 -r l; do
- cname=`basename "$l"`
- dir=`dirname "$l"`
- dstpath="$HOME/$l"
+ cname="$(basename "${l}")"
+ dir="$(dirname "${l}")"
+ dstpath="${HOME}/${l}"
- [[ "$dir" =~ $re_leaves ]] && continue
+ [[ "${dir}" =~ ${re_leaves} ]] && continue
- if [[ "$dir" != '.' ]]; then
- IFS=/ read -a elems <<<"$dir"
- pth="$HOME"
+ if [[ "${dir}" != '.' ]]; then
+ IFS=/ read -a elems <<<"${dir}"
+ pth="${HOME}"
for elem in "${elems[@]}"; do
- pth="$pth/$elem"
- if [[ "${pth#$HOME/}" =~ $re_leaves ]]; then
+ 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"
+ 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
+ confirm_remove "${prompt}" "${pth}" && rc=$? || rc=$?
+ case "${rc}" in
1) break 2; ;;
2) continue 2; ;;
esac
fi
- if [[ ! -e "$pth" ]]; then
- mkdir -vp "$pth"
+ 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?"
+ 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
+ confirm_remove "${prompt}" "${dstpath}" && rc=$? || rc=$?
+ case "${rc}" in
1) break; ;;
2) continue; ;;
esac
- elif [[ -e "$dstpath" && -L "$dstpath" && `readlink "$dstpath"` == "$src/$l" ]]; then
+ elif [[ -e "${dstpath}" && -L "${dstpath}" && "$(readlink "${dstpath}")" == "${src}/${l}" ]]; then
continue
fi
- ln -vsf "$src/$l" "$dstpath"
- done 3< <(git ls-files | egrep -v "$re_ignore"; printf '%s\n' "${directory_leaves[@]}")
+ ln -vsf "${src}/${l}" "${dstpath}"
+ done 3< <(git ls-files | egrep -v "${re_ignore}"; printf '%s\n' "${directory_leaves[@]}")
}
function setup_neovim() {
@@ -138,3 +137,5 @@ function setup_neovim() {
make_links
setup_neovim
+
+# vim: set sw=4 ts=4 et tw=98: