-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtip
executable file
·77 lines (65 loc) · 1.32 KB
/
tip
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
#!/bin/bash
ROOT_DIR=$(dirname "$0")
DATA_DIR="${ROOT_DIR}/data/tip"
function after_my() {
xdg-open http://139.199.4.119/book/
}
# function after_bash() {
# xdg-open "https://learnxinyminutes.com/docs/bash/"
# }
function usage() {
echo 'Usage:
$ tip bash | top | ps | du | systemctl | ulimit | egrep | grep | tail | watch | date
jmap | jstack | jstat | keytool | sbt
curl | svn | ssh | git | mysql | dot | xclip | iconv | rg
docker | docker-compose
realize | dep | npm | n
go | go_nil
cargo | rustup
consul | nginx
buffalo
centos
semantic_version | uml
my'
echo "all tip list from $DATA_DIR"
(
cd "$DATA_DIR"
i=0
for x in $(exa -rs created); do
printf "\t%-16s" "${x:0:-3}"
let i=i+1
if [ $((i % 5)) -eq 0 ]; then
echo ""
fi
done
)
echo ""
}
###################################
_fn_exists() {
declare -f -F $1 > /dev/null
return $?
}
_try_fn() {
_fn_exists "$1" && eval "$1"
}
task="$1"
if [ -z "$task" ]; then
usage "$DATA_DIR"
else
f="$DATA_DIR/$task.md"
if [ -e "$f" ]; then
printf ">read %s\n...\n" "$f"
_try_fn "before_$1"
command -v mdcat >/dev/null 2>&1
if [ "$?" = "0" ];then
mdcat "$f"
else
cat "$f"
fi
printf "\n\n"
_try_fn "after_$1"
else
usage
fi
fi