-
Notifications
You must be signed in to change notification settings - Fork 0
/
re.sh
executable file
·73 lines (60 loc) · 1.6 KB
/
re.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
71
72
73
#!/bin/bash
function re_select_output_line()
{
echo -e "=> \c"
local select_number
read select_number
select_output_line "$select_number"
local select_output_line_ret="$?"
if [[ $select_output_line_ret -ge 0 && $select_output_line_ret -lt ${#output_line_array[@]} ]]; then
echo -e "${output_line_array[$select_number]}\c" | xclip -selection clipboard
elif [[ $select_output_line_ret -eq ${#output_line_array[@]} ]]; then
choose_to_display_or_not
if [[ $? -eq 0 ]]; then
display_output_line_array
else
return 1
fi
re_select_output_line
else
echo 're: please check your input'
fi
}
function main() {
local cmd_para_num="$#"
output_line_array=()
if [ $cmd_para_num -eq 0 ]; then
return 0
else
local i=0
local line
while read line; do
line=${line// /%#}
match_line $@ "$line"
if [ $? -eq 0 ]; then
line=${line//%#/ }
is_existed_in_array "$line"
if [[ "$?" -ne 0 ]]; then
output_line_array[$i]=$line
let i++
fi
fi
done < ~/.bash_history
reverse_output_array
if test ! $? -eq 0; then
return 0
fi
fi
if [[ ${#output_line_array[@]} -eq 0 ]]; then
echo 're: found no history'
return 0
fi
choose_to_display_or_not
if [[ $? -eq 0 ]]; then
display_output_line_array
else
return 1
fi
re_select_output_line
}
main $@