/
tasker-core
114 lines (95 loc) · 3.44 KB
/
tasker-core
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
#!/usr/bin/env bash
_TC_SELF_DIR=$(cd -P -- "${BASH_SOURCE%/*}" && pwd -P)
source "$_TC_SELF_DIR/commands/index"
if [[ $TERM != "" ]] && [[ $TERM != "dumb" ]]; then
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
bgBlack=$(tput setab 0)
bgRed=$(tput setab 1)
bgGreen=$(tput setab 2)
bgYellow=$(tput setab 3)
bgBlue=$(tput setab 4)
bgMagenta=$(tput setab 5)
bgCyan=$(tput setab 6)
bgWhite=$(tput setab 7)
rc=$(tput sgr0) # Reset Color
fi
LOGO="
████████╗ █████╗ ███████╗██╗ ██╗███████╗██████╗
╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗
██║ ███████║███████╗█████╔╝ █████╗ ██████╔╝
██║ ██╔══██║╚════██║██╔═██╗ ██╔══╝ ██╔══██╗
██║ ██║ ██║███████║██║ ██╗███████╗██║ ██║
╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝"
VERSION="1.3"
PATH="./node_modules/.bin:./vendor/bin:./bin:$PATH"
TASKER_FILE="${TASKER_FILE:-$0}"
function _logo { # Display LOGO if there is enough space in terminal window
if [[ "$(tput cols)" -ge "$(echo $LOGO | _longestLineLength)" ]]; then
echo "${LOGO}"
fi
}
function _listAutoCompleteFunctions { # Display list of public functions for autocomplete
_listFunctions $0 "^function ([a-zA-Z][a-zA-Z0-9\-\_]+)\ \{ \# (.+)" --names
}
function _listPublicFunctions { # Display list of public functions definded in current file
_listFunctions $0 "^function ([a-zA-Z][a-zA-Z0-9\-\_]+)\ \{ \# (.+)" $1
}
function _listAllFunctions { # Display list of all functions definded in current file
_listFunctions $0 "^function ([a-zA-Z0-9\-\_]+)\ \{ \# (.+)" $1
}
function _listPrivateFunctions { # Display list of private functions definded in current file
_listFunctions $0 "^function (_[a-zA-Z0-9\-\_]+)\ \{ \# (.+)" $1
}
function _error { # Display error message
if [ -n "$(type -t cowsay)" ]; then
cowsay "$1"
echo ""
else
echo ""
echo "${red}$1${rc}"
echo ""
fi
}
function _help { # Display help message
_logo
echo ""
echo "${green}Tasker ${rc}version ${yellow}${VERSION}${rc} - Bash alias runner"
echo ""
echo "${yellow}Usage:${rc}"
echo " $TASKER_FILE command [arguments]"
echo ""
echo "${yellow}Available commands:${rc}"
_listPublicFunctions --color
echo ""
}
function _bootstrap {
if [[ $1 ]]; then
if [ -n "$(type -t $1)" ]; then
eval "${@:1}"
else
_error "Command \"$1\" is not defined."
fi
else
_help
fi
}
function _callStack {
local i=0
local frames=${#BASH_LINENO[@]}
for ((i = frames - 4; i >= 0; i--)); do
echo " File" \"${BASH_SOURCE[i + 1]}\", line ${BASH_LINENO[i]}, in ${FUNCNAME[i + 1]}
local code=`head -n "${BASH_LINENO[i]}" "${BASH_SOURCE[i + 1]}" | tail -n 1`
echo " ${code}"
done
}
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
trap '_callStack; exit 1' ERR
trap 'kill %- 2> /dev/null || exit 0' SIGINT