-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathv2-refactor.sh
More file actions
executable file
·91 lines (77 loc) · 1.9 KB
/
v2-refactor.sh
File metadata and controls
executable file
·91 lines (77 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# helper for refactoring to v2
ignores=(
CHANGELOG.md
v2-refactor.sh
tests/bats/tmp
common/lib/shell-helpers.sh
)
funcs=(
docker/deactivate_machine@docker/deactivate-machine
docker/safe_name@docker/get/safe-name
find/dockerfiles@docker/find/dockerfiles
get/dockerfile-tag@docker/get/dockerfile-tag
get/docker-name@docker/get/repotag
io/@p/
is/dirty@git/is/dirty
find/cmd@get/cmd
find/gid_from_name@get/gid_from_name
find/gid_from_path@get/gid_from_path
find/dockerfile-tag@get/dockerfile-tag
prompt\ \"@prompt/user
)
prompt/user(){
local input=
local prompt="${1:-value}"
local default="$2"
[ -z "$default" ] || prompt+=" [$default]"
# convert escape sequences in prompt to ansi codes
prompt="$(echo -e -n "$prompt : ")"
while [ -z "$input" ]; do
if [ -t 0 ]; then
# user input
read -p "$prompt" input </dev/tty
else
# piped input
read input
fi
[[ -n "$default" && -z "$input" ]] && input="$default"
[ -z "$input" ] && p/warn "invalid input"
done
echo "$input"
}
prompt/confirm() {
while true; do
case $(prompt/user "${@:-Continue?} [y/n]") in
[yY]) return 0 ;;
[nN]) return 1 ;;
*) p/warn "invalid input"
esac
done
}
p/notice(){
p/blockquote "\e[33m" "➜ " "$@" >&2
}
p/blockquote(){
local escape="$1" ; shift
local prefix="$1" ; shift
local indent="$(printf '%*s' ${#prefix})"
while [ $# -ne 0 ]; do
printf "$escape$prefix%b\n\e[0m" "$1"
prefix="$indent"
shift
done
}
for fn in "${funcs[@]}"; do
IFS="@" read -r fn replace <<< "$fn"
flags=
for ignore in "${ignores[@]}"; do
flags+=" --ignore $ignore"
done
p/notice "working with $fn [use $replace as replacement]"
ag $flags "$fn"
while prompt/confirm "re-print $fn matches (y) or continue (n)" ; do
p/notice "working with $fn [use $replace as replacement]"
ag $flags "$fn"
done
done