Skip to content

Commit 5cb1796

Browse files
committed
MOD: script.sh
1 parent 27098fa commit 5cb1796

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

template/script.sh

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@ function IO:progress() {
232232
)
233233
}
234234

235+
function IO:countdown(){
236+
local seconds=${1:-5}
237+
local message=${2:-Countdown :}
238+
239+
if ((piped)); then
240+
IO:print "$message $seconds seconds"
241+
else
242+
for (( i = 0; i < "$seconds"; i++ )); do
243+
IO:progress "${txtInfo}$message $((seconds - i)) seconds${txtReset}"
244+
sleep 1
245+
done
246+
IO:print " "
247+
fi
248+
}
249+
235250
### interactive
236251
function IO:confirm() {
237252
((force)) && return 0
@@ -351,6 +366,20 @@ function Str:digest() {
351366
fi
352367
}
353368

369+
# Gha: function should only be run inside of a Github Action
370+
371+
function Gha:finish(){
372+
[[ -z "${RUNNER_OS:-}" ]] && IO:die "This should only run inside a Github Action, don't run it on your machine"
373+
git config user.name "Bashew Runner"
374+
git config user.email "actions@users.noreply.github.com"
375+
timestamp=$(date -u)
376+
message="$timestamp < $script_basename $script_version"
377+
git add -A
378+
git commit -m "${message}" || exit 0
379+
git pull --rebase
380+
git push
381+
exit 0
382+
}
354383

355384
trap "IO:die \"ERROR \$? after \$SECONDS seconds \n\
356385
\${error_prefix} last command : '\$BASH_COMMAND' \" \
@@ -838,16 +867,16 @@ function Os:beep(){
838867
}
839868

840869
function Script:meta() {
841-
local git_repo_remote=""
842-
local git_repo_root=""
843-
local os_kernel=""
844-
local os_machine=""
845-
local os_name=""
846-
local os_version=""
847-
local script_hash="?"
848-
local script_lines="?"
849-
local shell_brand=""
850-
local shell_version=""
870+
git_repo_remote=""
871+
git_repo_root=""
872+
os_kernel=""
873+
os_machine=""
874+
os_name=""
875+
os_version=""
876+
script_hash="?"
877+
script_lines="?"
878+
shell_brand=""
879+
shell_version=""
851880

852881
script_prefix=$(basename "${BASH_SOURCE[0]}" .sh)
853882
script_basename=$(basename "${BASH_SOURCE[0]}")
@@ -961,14 +990,22 @@ function Os:tempfile(){
961990

962991
function Os:import_env() {
963992
local env_files
964-
env_files=(
965-
"$script_install_folder/.env"
966-
"$script_install_folder/.$script_prefix.env"
967-
"$script_install_folder/$script_prefix.env"
968-
"./.env"
969-
"./.$script_prefix.env"
970-
"./$script_prefix.env"
971-
)
993+
if [[ $(pwd) == "$script_install_folder" ]] ; then
994+
env_files=(
995+
"$script_install_folder/.env"
996+
"$script_install_folder/.$script_prefix.env"
997+
"$script_install_folder/$script_prefix.env"
998+
)
999+
else
1000+
env_files=(
1001+
"$script_install_folder/.env"
1002+
"$script_install_folder/.$script_prefix.env"
1003+
"$script_install_folder/$script_prefix.env"
1004+
"./.env"
1005+
"./.$script_prefix.env"
1006+
"./$script_prefix.env"
1007+
)
1008+
fi
9721009

9731010
for env_file in "${env_files[@]}"; do
9741011
if [[ -f "$env_file" ]]; then

0 commit comments

Comments
 (0)