Skip to content

Commit

Permalink
add secrets plugin
Browse files Browse the repository at this point in the history
- check its README.md to further details
  • Loading branch information
andersonbosa committed Aug 13, 2023
1 parent d39725d commit a55e2d4
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ logs/

# editor configs
.vscode
.idea
.idea
File renamed without changes.
File renamed without changes.
52 changes: 19 additions & 33 deletions moshell.sh/lib/cli.sh → moshell.sh/core/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@

## Utility functions

# usage:
# _moshell::log error "lorem ipsum"
function _moshell::log {
# if promptsubst is set, a message with `` or $()
# will be run even if quoted due to `print -P`
setopt localoptions nopromptsubst

# $1 = info|warn|error|debug
# $2 = text
# $3 = (optional) name of the logger

local logtype="$1"
local logname="" # TODO: inpired in OhMyZSH

# Choose coloring based on log type
case "$logtype" in
prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;;
debug) print -P "%F{white}$logname%f: $2" ;;
info) print -P "%F{green}$logname%f: $2" ;;
warn) print -P "%S%F{yellow}$logname%f%s: $2" ;;
error) print -P "%S%F{red}$logname%f%s: $2" ;;
esac >&2
}

function _moshell::confirm {
# If question supplied, ask it before reading the answer
# NOTE: uses the logname of the caller function
Expand Down Expand Up @@ -54,16 +30,24 @@ Available commands:
help Print this help message
edit Edit moshell configurations
reload Reload the configuration
update Update Moshell.sh
update TODO: Update Moshell.sh
version Show the version
EOF
}

function _moshell::edit {
local msg="Openning in your prefered editor: $EDITOR... "
_moshell::log info $msg
sleep 1
$EDITOR $_MOSHEL_DIR_BASE
return 0
}

function _moshell::reload {
# TODO: source moshell index
echo "[INFO] Recharged Settings"
_moshell::log info $msg
source "$_MOSHEL_DIR_BASE/moshell.sh"
return 0
}

function _moshell::version {
Expand All @@ -74,17 +58,19 @@ function _moshell::version {
# 1) try tag-like version
# 2) try branch name
# 3) try name-rev (tag~<rev> or branch~<rev>)
local version
version=$(command git describe --tags HEAD 2>/dev/null) ||
version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) ||
version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) ||
version="<detached>"
local remote_version
remote_version=$(command git describe --tags HEAD 2>/dev/null) ||
remote_version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) ||
remote_version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) ||
remote_version="<detached>"

# Get short hash for the current HEAD
local commit=$(command git rev-parse --short HEAD 2>/dev/null)

local local_version=$(cat $_MOSHEL_DIR_BASE/version)

# Show version and commit hash
printf "%s (%s)\n" "$version" "$commit"
printf "[%s] %s (%s)\n" "$local_version" "$remote_version" "$commit"
)
}

Expand Down
10 changes: 10 additions & 0 deletions moshell.sh/core/flags.sh
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

7 changes: 5 additions & 2 deletions moshell.sh/lib/index.sh → moshell.sh/core/index.sh
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."
52 changes: 52 additions & 0 deletions moshell.sh/core/logger.sh
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"
16 changes: 15 additions & 1 deletion moshell.sh/custom/andersonbosa/generators.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function poc_init_python() {
function create_poc_python() {
create_venv

pysource
Expand All @@ -11,3 +11,17 @@ function poc_init_python() {
git add .
git commit -m 'init python project'
}

function create_makefile_python() {
cat <<EOF >./Makefile
setup-env:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requeriments.txt
run:
python main.py
EOF
}
4 changes: 3 additions & 1 deletion moshell.sh/custom/index.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
moshell::custom::index() {
_moshell::custom::index() {
echo '# This is a index file to import (and export to shell) all files wanted. For better organization it was separeted by username.'
}

Expand All @@ -11,3 +11,5 @@ source "$BASE_PATH/andersonbosa/generators.sh"
source "$BASE_PATH/andersonbosa/randoms.sh"
source "$BASE_PATH/andersonbosa/termbin.sh"
source "$BASE_PATH/andersonbosa/workrounds.sh"

_moshell::log success "Loaded customizations."
4 changes: 0 additions & 4 deletions moshell.sh/lib/flags.sh

This file was deleted.

13 changes: 8 additions & 5 deletions moshell.sh/moshell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-

export _MOSHEL_DIR_BASE="$(dirname "$(realpath "$0")")"
export _MOSHEL_DIR_LIB="$_MOSHEL_DIR_BASE/lib"
export _MOSHEL_DIR_CORE="$_MOSHEL_DIR_BASE/core"
export _MOSHEL_DIR_PLUGINS="$_MOSHEL_DIR_BASE/plugins"
export _MOSHEL_DIR_CUSTOM="$_MOSHEL_DIR_BASE/custom"
export _MOSHEL_DIR_LOGS_FILE="$_MOSHEL_DIR_BASE/logs/$(date +%s).log"

# =============================================================================

Expand All @@ -22,17 +22,20 @@ export _MOSHEL_DIR_LOGS_FILE="$_MOSHEL_DIR_BASE/logs/$(date +%s).log"
# source $script_file 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE"

# # Verbose if flag is diff 0
# [[ "$_MOSHELL_DEBUG" == "1" ]] && echo "[DEBUG] loaded: $script_file"
# [[ "$_MOSHELL_LOGGING" == "1" ]] && echo "[DEBUG] loaded: $script_file"
# fi
# done
# }
#
# moshell::import_libs $_MOSHEL_DIR_LIB 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE"
# moshell::import_libs $_MOSHEL_DIR_CORE 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE"
# moshell::import_libs $_MOSHEL_DIR_CUSTOM 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE"
#

# =============================================================================

# To infinity and beyond!
source $_MOSHEL_DIR_LIB/index.sh
source $_MOSHEL_DIR_CORE/index.sh
source $_MOSHEL_DIR_PLUGINS/index.sh
source $_MOSHEL_DIR_CUSTOM/index.sh

_moshell::log success "Moshell.sh initialized with success!"
3 changes: 3 additions & 0 deletions moshell.sh/plugins/howtos/_index.sh
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
Loading

0 comments on commit a55e2d4

Please sign in to comment.