Skip to content

Commit 1e07ed5

Browse files
committed
Move setup specific func to hook-setup
* Del testvar, lef behind.
1 parent d7be899 commit 1e07ed5

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

hook-setup

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
11
#! /usr/bin/env sh
2+
3+
# Remove trailing and squeeze multiple '/'
4+
normalize() {
5+
printf '%s' "$1" | tr -s '/' | sed 's^/$^^'
6+
}
7+
8+
# Build relative path from arg1 to arg2
9+
# Return arg2, if has not equal parts
10+
# Require absolute paths as args & confused with '.' & '..'!
11+
relpath () (
12+
_from="$(normalize "$1")"
13+
_to="$(normalize "$2")"
14+
[ ! x"${_from#/}" = x"${_from}" ] && [ ! x"${_to#/}" = x"${_to}" ] || { printf 'relpath: %s\n' 'Absolute paths is required!' "arg1='${_from}'" "arg2='${_to}'" >&2; return 1; }
15+
[ x"$(printf '%s ' "${_from}" "${_to}" | grep -E '\./' 2>/dev/null)" = x ] || { printf 'relpath: %s\n' "Use of '.'/'..' in absolute path is confusing..." "arg1='${_from}'" "arg2='${_to}'" >&2; return 1; }
16+
_from="${_from#/}"
17+
_depth=$(printf '%s' "${_from}" | tr "/\n" "\n/" | wc -l) # depth to root
18+
# Eat equal parts
19+
_OIFS="${IFS}"
20+
IFS="/"
21+
set -- ${_to}
22+
IFS="${_OIFS}"
23+
while shift; do # First shift remove emty elem
24+
[ x"${_from#"$1"}" = x"${_from}" ] && break
25+
_from="${_from#"$1"/}"
26+
_to="${_to#/"$1"}"
27+
done
28+
_steps=$(printf '%s' "${_from}" | tr "/\n" "\n/" | wc -l) # depth remain
29+
[ ${_depth} -eq ${_steps} ] && printf '%s' "${_to}" && return 0 # no equal parts found
30+
_ret=
31+
for i in $(seq 1 ${_steps}); do
32+
_ret="../${_ret}"
33+
done
34+
printf '%s' "${_ret}${_to#/}"
35+
)
36+
237
gitbin="$(which git)" || { printf '%s\n' 'Well, this is discouraging...' "Can't find git bin\! Is it installed?"; exit 1; }
338
hooks_dest="${1:-$(cd "$(dirname -- "${self}")/.."; "${gitbin}" rev-parse --show-toplevel 2>/dev/null || pwd)/.git}/hooks"
439
hooks_dest="$(normalize "${hooks_dest}")"
@@ -178,7 +213,6 @@ clear
178213
pheader
179214
phooks
180215
while :; do
181-
_test2=$g_iHooksPage
182216
pstatus "Please, enter number to operate on hook, 'n'/'p' for next/previous page or 'q' to exit setup" ""
183217
pstatus
184218
read ui

hook-wrapper

-34
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,6 @@ afind () {
5050
done; printf '%s\n' ' '" dummy '{}' +
5151
}
5252

53-
# Remove trailing and squeeze multiple '/'
54-
normalize() {
55-
printf '%s' "$1" | tr -s '/' | sed 's^/$^^'
56-
}
57-
58-
# Build relative path from arg1 to arg2
59-
# Return arg2, if has not equal parts
60-
# Require absolute paths as args & confused with '.' & '..'!
61-
relpath () (
62-
_from="$(normalize "$1")"
63-
_to="$(normalize "$2")"
64-
[ ! x"${_from#/}" = x"${_from}" ] && [ ! x"${_to#/}" = x"${_to}" ] || { printf 'relpath: %s\n' 'Absolute paths is required!' "arg1='${_from}'" "arg2='${_to}'" >&2; return 1; }
65-
[ x"$(printf '%s ' "${_from}" "${_to}" | grep -E '\./' 2>/dev/null)" = x ] || { printf 'relpath: %s\n' "Use of '.'/'..' in absolute path is confusing..." "arg1='${_from}'" "arg2='${_to}'" >&2; return 1; }
66-
_from="${_from#/}"
67-
_depth=$(printf '%s' "${_from}" | tr "/\n" "\n/" | wc -l) # depth to root
68-
# Eat equal parts
69-
_OIFS="${IFS}"
70-
IFS="/"
71-
set -- ${_to}
72-
IFS="${_OIFS}"
73-
while shift; do # First shift remove emty elem
74-
[ x"${_from#"$1"}" = x"${_from}" ] && break
75-
_from="${_from#"$1"/}"
76-
_to="${_to#/"$1"}"
77-
done
78-
_steps=$(printf '%s' "${_from}" | tr "/\n" "\n/" | wc -l) # depth remain
79-
[ ${_depth} -eq ${_steps} ] && printf '%s' "${_to}" && return 0 # no equal parts found
80-
_ret=
81-
for i in $(seq 1 ${_steps}); do
82-
_ret="../${_ret}"
83-
done
84-
printf '%s' "${_ret}${_to#/}"
85-
)
86-
8753
setup() {
8854
. "$(dirname -- "${self}")/hook-setup"
8955
}

0 commit comments

Comments
 (0)