-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathanalyze-last-executed-command.sh
More file actions
121 lines (98 loc) · 3.5 KB
/
analyze-last-executed-command.sh
File metadata and controls
121 lines (98 loc) · 3.5 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
## analyze last executed command with possible prefixes
## post executor
# export PROMPT_COMMAND='starship_precmd'
function _last_command_check_anchor(){
## variables
last_command=`history | tail -n 1 | head -n 1 | awk '{$1=""; print $0}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
url=$(echo "$last_command" | grep -oE 'https?://[^ )]+' ); url="${url%%)}"
possible_ticket=`echo "$last_command" | awk '{print $1}'`
if [[ $debug != 0 ]]; then
echo "--last_command -->"$last_command
echo "-- url-->"$url
echo "--possible_ticket-->"$possible_ticket
fi
## https://
if [[ -n "$url" ]]; then
if [[ $debug != 0 ]]; then
echo "open url: $url"
fi
open_url "$url"
return 0
fi
## JIRAPREFIX-
if [[ "$last_command" =~ ^[[:space:]]*#*[[:space:]]*JIRAPREFIX ]]; then
possible_ticket=$(echo $last_command | awk -F 'JIRAPREFIX' '{print $2}')
if [[ $debug != 0 ]]; then
echo "- JIRAPREFIX: $possible_ticket"
fi
jira ${possible_ticket#-}
return 0
fi
if [[ "$last_command" =~ ^[[:space:]]*-[[:space:]]*JIRAPREFIX ]]; then
possible_ticket=$(echo $last_command | awk -F 'JIRAPREFIX' '{print $2}')
if [[ $debug != 0 ]]; then
echo "- JIRAPREFIX: $possible_ticket"
fi
jira ${possible_ticket#-}
return 0
fi
if [[ "$last_command" =~ ^[[:space:]]*\*[[:space:]]*JIRAPREFIX ]]; then
possible_ticket=$(echo $last_command | awk -F 'JIRAPREFIX' '{print $2}')
if [[ $debug != 0 ]]; then
echo "* JIRAPREFIX: $possible_ticket"
fi
jira ${possible_ticket#-}
return 0
fi
if [[ "$last_command" =~ ^[[:space:]]*JIRAPREFIX ]]; then
possible_ticket=$(echo $last_command | awk -F 'JIRAPREFIX' '{print $2}')
if [[ $debug != 0 ]]; then
echo " JIRAPREFIX: $possible_ticket"
fi
jira ${possible_ticket#-}
return 0
fi
if [[ $possible_ticket =~ JIRAPREFIX* ]]; then
jira ${possible_ticket#JIRAPREFIX-}
if [[ $debug != 0 ]]; then
echo "JIRAPREFIX: $possible_ticket"
fi
return 0
fi
## INC
if [[ $possible_ticket == INC* ]]; then
echo "command for INC......"
return 0
fi
## REQ
if [[ $possible_ticket == REQ* ]]; then
echo "command for REQ......"
return 0
fi
## no options - just run it
if echo "$last_command" | grep -q -e "^##" -e "^\*" -e "^>" ; then
[[ "$DEBUG" == "1" ]] && echo "last command is possible anchor: $last_command"
last_command=`echo "$last_command" | awk '{$1=""; print $0}'`
if [[ $debug != 0 ]]; then
echo "will be executed: $last_command"
fi
$last_command
return 0
fi
if echo "$last_command" | grep -q -e "^ *-" ; then
cleared_command=`echo "$last_command" | awk '{$1=""; print $0}' | sed -e 's/^[[:space:]]*//' `
[[ "$DEBUG" == "1" ]] && echo "last command debug: $cleared_command"
[[ $debug != 0 ]]; && echo "will be cleared and executed: $cleared_command"
fi
$cleared_command
return 0
fi
if [[ $debug != 0 ]]; then
echo "no options for execution"
fi
return 1
}
function activate-last-command-analyzer(){
export PROMPT_COMMAND='_last_command_check_anchor'
}
alias analyzer-for-last-command=activate-last-command-analyzer