-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
390 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ logs/ | |
|
||
# editor configs | ||
.vscode | ||
.idea | ||
.idea |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# -*- coding: utf-8 -*- | ||
|
||
# Glossary | ||
# 0=no | ||
# 1=yes | ||
|
||
export _MOSHELL_LOGGING=1 # log to file | ||
export _MOSHELL_VERBOSE=0 # log to shell | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
moshell::lib::index() { | ||
_moshell::core::index() { | ||
echo '# This is a index file to import (and export to shell) all files required by Moshell.sh.' | ||
} | ||
|
||
BASE_PATH="$(dirname "$(realpath "$0")")" | ||
|
||
# NOTE: The order matters | ||
source "$BASE_PATH/flags.sh" | ||
source "$BASE_PATH/cli.sh" | ||
source "$BASE_PATH/banner.sh" | ||
source "$BASE_PATH/logger.sh" | ||
source "$BASE_PATH/cli.sh" | ||
|
||
_moshell::log success "Loaded core." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
|
||
# Log messages with different colors based on log level and save to a log file | ||
# Usage: _moshell::log_and_save log_level message | ||
function _moshell::log { | ||
local logtype="$1" | ||
local message="$2" | ||
|
||
local log_colors | ||
local word_colors="\e[30m" # Black text color | ||
local log_reset="\e[0m" | ||
|
||
# Transform to lowercase | ||
logtype=$(echo "$logtype" | tr '[:upper:]' '[:lower:]') | ||
|
||
case "$logtype" in | ||
prompt) log_colors="\e[45m" ;; # Magenta background | ||
success) log_colors="\e[42m" ;; # Green background | ||
info) log_colors="\e[44m" ;; # Blue background | ||
debug) log_colors="\e[47m" ;; # White background | ||
warn) log_colors="\e[43m" ;; # Yellow background | ||
error) log_colors="\e[41m" ;; # Red background | ||
*) | ||
# Default to red background for unknown log levels | ||
logtype="info" | ||
log_colors="\e[41m" | ||
;; | ||
esac | ||
|
||
# Transform to uppercase | ||
logtype=$(echo "$logtype" | tr '[:lower:]' '[:upper:]') | ||
|
||
# Log to the terminal with colors | ||
if [[ "$_MOSHELL_VERBOSE" == 1 ]]; then | ||
printf "${log_colors}${word_colors}[%s]${log_reset}:%s\n" "$logtype" "$message" >&2 | ||
fi | ||
|
||
if [[ "$_MOSHELL_LOGGING" == 1 ]]; then | ||
# Save to log file | ||
local logfile="$(date +%F)_moshell.sh.log" | ||
local logpath="$_MOSHEL_DIR_BASE/logs/$logfile" | ||
echo "[$(date --iso-8601=ns)] [$logtype] $message" >>"$logpath" | ||
fi | ||
} | ||
|
||
# # Usage examples: | ||
# _moshell::log prompt "This is a prompt message" | ||
# _moshell::log success "This is a success message" | ||
# _moshell::log info "This is an info message" | ||
# _moshell::log debug "This is a debug message" | ||
# _moshell::log warn "This is a warning message" | ||
# _moshell::log error "This is an error message" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_HOWTOS_CURRENT_PATH="$(dirname "$(realpath "$0")")" | ||
|
||
source $_HOWTOS_CURRENT_PATH/all.sh |
Oops, something went wrong.