-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.saintHelpers
70 lines (61 loc) · 1.73 KB
/
.saintHelpers
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
# depends on .saint
# Saint Helper Functions
# TODO: Create a reload for docker custom containers update
# TODO: No messages or just important messages mode to activate or disable
saint_msg() {
msg=$1
echo -e "🤖 ${msg}"
}
saint_empty() {
emptyCommand=$1
saint_msg "${RED}$emptyCommand${NC} :: Command is empty. Try '${projectCommand} ${GREEN}help${NC}'"
};
saint_invalid_command () {
parentCommand=$1
invalidCommand=$2
saint_msg "'${RED}$invalidCommand${NC}' :: Not a valid command in '$parentCommand'."
};
# Function to check if an alias exists
saint_has_alias() {
local aliasName=$1
if alias "$aliasName" &>/dev/null; then
return 0
else
return 1
fi
}
# Maybe this is unecessary, I'm still testing. Idk, you tell me.
# Function to run the command and return to the original directory if it fails
saint_run_command() {
local orig_dir=$(pwd)
local command="$1"
shift
local args="$@"
eval "$command $args"
if [ $? -ne 0 ]; then
saint_msg "${RED}Command failed${NC} :: $command $args"
cd "$orig_dir"
return 1
fi
cd "$orig_dir"
}
# Function to handle read command for both Bash and Zsh
saint_read() {
local var_name="$1"
local prompt="$2"
local input
if [ -n "$BASH_VERSION" ]; then
# For Bash
read -p "$prompt" input
elif [ -n "$ZSH_VERSION" ]; then
# For Zsh
read -r "$var_name?$prompt"
return
fi
eval "$var_name='$input'"
}
source "${PROJECT_PATH}/features/helpers/saint_cd_helpers/.saintCdHelpers"
source "${PROJECT_PATH}/features/helpers/saint_docker_helpers/.saintDockerHelpers"
source "${PROJECT_PATH}/features/helpers/saint_git_helpers/.saintGitHelpers"
source "${PROJECT_PATH}/features/helpers/saint_select_option/.saintSelectOption"