-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.sh
70 lines (66 loc) · 1.44 KB
/
lib.sh
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
#!/bin/bash
# returns:
# 0: yes
# 1: no
# 2: default
# *: exit
#
#
# examples:
#
# `test -f ~/.vimrc && test -f ~/.tmux.conf`
# option "~/.vimrc of ~/.tmux.conf already exists" "continue [Y,n]"
# `hash tmuxp 2>/dev/null`
# option "tmuxp not installed" "continue [y,N]"
option () {
if [ $? != 0 ]; then
echo $1
echo -n "$2 "
read -n 1 op
if [ "$op" != "" ]; then echo; fi
case $op in
"y") return 0 ;;
"Y") return 0 ;;
"n") return 1 ;;
"N") return 1 ;;
"") return 2; ;;
*) echo "invalid option"; exit 1 ;;
esac
fi
return 0
}
# Exit by default
#
# examples:
#
# `test -f ~/.vimrc && test -f ~/.tmux.conf`
# option "~/.vimrc of ~/.tmux.conf already exists"
# `hash tmuxp 2>/dev/null`
# option "tmuxp not installed"
option_stop () {
option $? "$1" "continue [y,N]"
if [ $? != 0 ]; then exit; fi
}
# Continue by default
#
# examples:
#
# `test -f ~/.vimrc && test -f ~/.tmux.conf`
# option "~/.vimrc of ~/.tmux.conf already exists"
# `hash tmuxp 2>/dev/null`
# option "tmuxp not installed"
option_skip () {
option "$1" "skip [Y,n]"
if [ $? == 1 ]; then exit; fi
}
# Stop if test fail
#
# examples:
#
# `test -f ~/.vimrc && test -f ~/.tmux.conf`
# option "~/.vimrc of ~/.tmux.conf already exists"
# `hash tmuxp 2>/dev/null`
# option "tmuxp not installed"
stop_if_fail () {
if [ $? != 0 ]; then echo $1; exit 1; fi
}