1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00

*: rewrite some files to nuxsh.

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2017-07-16 18:39:13 +02:00
parent eef3628269
commit 59b79ea88e
7 changed files with 396 additions and 145 deletions

31
inc/nux/check.inc.sh Normal file
View file

@ -0,0 +1,31 @@
## nux.check.function:: <name>
##
function nux.check.function {
nux.log trace "Checking if $1 is function."
declare -f "$1" &>/dev/null && return 0
return 1
}
function nux.check.nuxenv.file {
path=$(realpath -Lms "$1")
[[ "$path" =~ "^$NUX_ENV_DIR" ]]
}
function nux.check.optional {
local function="$1"; shift;
if nux.check.function "$function" ; then
$function "$@"
fi
}
function nux.check.exec {
local binary=$1;
test -n "$(which "$binary")"
}
## nux.check.file.exists:: <name>
##
function nux.check.file.exists {
test -e "$1" -o -h "$1";
}

42
inc/nux/color.nuxsh.sh Normal file
View file

@ -0,0 +1,42 @@
if [ -t 1 ] {
readonly nc_bold=`tput setaf 0`
readonly nc_bg_bold=`tput setab 0`
readonly nc_black=`tput setab 0`
readonly nc_bg_black=`tput setab 0`
readonly nc_cyan=`tput setaf 6`
readonly nc_bg_cyan=`tput setab 6`
readonly nc_magenta=`tput setaf 5`
readonly nc_bg_magenta=`tput setab 5`
readonly nc_red=`tput setaf 1`
readonly nc_bg_red=`tput setab 1`
readonly nc_white=`tput setaf 7`
readonly nc_bg_white=`tput setab 7`
readonly nc_green=`tput setaf 2`
readonly nc_bg_green=`tput setab 2`
readonly nc_yellow=`tput setaf 3`
readonly nc_bg_yellow=`tput setab 3`
readonly nc_blue=`tput setaf 4`
readonly nc_bg_blue=`tput setab 4`
readonly nc_end=`tput sgr0`
readonly NC_Bold=`tput bold`
readonly NC_No=`tput sgr0` # No Color
readonly NC_Black='\033[0;30m'
readonly NC_Green='\033[0;32m'
readonly NC_Red=$nc_bold$nc_red
readonly NC_BrownOrange='\033[0;33m'
readonly NC_Blue='\033[0;34m'
readonly NC_Purple='\033[0;35m'
readonly NC_Cyan='\033[0;36m'
readonly NC_LightGray='\033[0;37m'
readonly NC_DarkGray='\033[1;30m'
readonly NC_LightRed='\033[1;31m'
readonly NC_LightGreen='\033[1;32m'
readonly NC_Yellow=$nc_yellow
readonly NC_LightBlue='\033[1;34m'
readonly NC_LightPurple='\033[1;35m'
readonly NC_LightCyan='\033[1;36m'
readonly NC_White=$nc_white
readonly NC_error=$NC_Red
}

21
inc/nux/help.nuxsh.sh Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env nuxsh
@namespace nux.help. {
function :shelldoc {
sed -r \
-e "s/^## ?(.*)/${NC_White}\1${NC_No}/gI" \
-e "s/^# ?(.*)/${NC_Bold}\1${NC_No}/gI" \
-e "s/^([ a-z0-9.-_]*)::/${NC_Bold}\1${NC_No}/gI" \
-e "s/\*\*([^*]*)\*\*/${NC_Bold}\1${NC_No}/gI" \
-e "s/\*([^*]*)\*/${NC_White}\1${NC_No}/gI" \
--
}
function :comment source {
if nux.check.file.exists "$source" ; then
grep -E "^\#\#( |$)" "$source" \
| cut -d\# -f3- \
| cut -d" " -f2- \
| nux.help.shelldoc
fi
}
}

52
inc/nux/log.inc.sh Normal file
View file

@ -0,0 +1,52 @@
## ##Logging
# Color for message levels
NC_LOG_color_info=$NC_LightGray
NC_LOG_color_error=$NC_LightRed
NC_LOG_color_warning=$NC_Yellow
NC_LOG_color_debug=$NC_White
NC_LOG_current=3
NC_LOG_id_none=0
NC_LOG_id_error=1
NC_LOG_id_warning=2
NC_LOG_id_info=3
NC_LOG_id_debug=4
NC_LOG_id_trace=5
##
## NUX Script environment provides basic logging capabilities.
##
## Currently there are 5 log levels supported (in order of detail):
## error
## warning
## info
## debug
## trace
##
## nux.log:: <level> <message>
## Outputs log message to *STDERR*. LOG messages are filtered out based on
## level. Use *nux.log.level* to specify which messages should be displayed.
##
##
function nux.log {
local level=$1
local message=$2
local color=NC_LOG_color_$level
local level_num=NC_LOG_id_$level
shift;
if [ ${!level_num} -le $NC_LOG_current ]; then
echo -e "${!color}[$level]$NC_No $*$NC_No" >&2
fi
}
## nux.log.level:: <level>
## Sets maximum level of details to be logged.
##
function nux.log.level {
local level=$1
local level_id=NC_LOG_id_$level
NC_LOG_current=${!level_id}
}