#
#################################################################################
type -P which > /dev/null || which() { type -P "$1" 2>&1; }
+
which nproc > /dev/null || nproc() {
case "$OSTYPE" in
darwin*) sysctl -n hw.ncpu ;;
fi
}
+which realpath > /dev/null || realpath() {
+ case "$OSTYPE" in
+ darwin*) [ -h "$1" ] && readlink "$1" || echo "$1";;
+ *) readlink -f "$1" ;;
+ esac
+ # perl -MFile::Spec -MCwd -e 'print File::Spec->rel2abs( Cwd::abs_path($ARGV[0]) )."\n" if -e $ARGV[0]' "$1"
+}
+
+# NB 11.03.19 which realpath > /dev/null || realpath() {
+# NB 11.03.19 if which perl 1>/dev/null; then
+# NB 11.03.19 perl -MFile::Spec -MCwd -e 'print File::Spec->rel2abs( Cwd::abs_path($ARGV[0]) )."\n" if -e $ARGV[0]' "$1"
+# NB 11.03.19 else
+# NB 11.03.19 case "$OSTYPE" in
+# NB 11.03.19 darwin*) readlink "$1" ;;
+# NB 11.03.19 *) readlink -f "$1" ;;
+# NB 11.03.19 esac
+# NB 11.03.19 fi
+# NB 11.03.19 }
+
which seq > /dev/null || seq() {
local begin=1
local end
awk -v begin=$begin -v end=$end -v step=$step 'BEGIN{for(i=begin;i<=end;i=i+step) {print i}}'
}
+nb_repos2() {
+ (
+ # Always !
+ echo "$NB_ROOT"
+
+ # Conf file
+ local conf="/etc/nb/repos.conf"
+ [ -s "$conf" ] || conf="$NB_ROOT/etc/repos.conf"
+
+ # Realpath
+ eval ls -d1 $(grep -v '^ *\(#\|$\)' "$conf") 2>/dev/null | while read dir; do
+
+ # Accept directories or files (ex: use to tag a directory: .nb-install)
+ [ -f "$dir" ] && dir=$(dirname "$dir")
+
+ dir=$(realpath2 "$dir")
+ echo "$dir"
+
+ done
+
+ # no doubles
+ # strong if awk failed
+ ) | awk \!'x[$0]++' || echo "$NB_ROOT"
+}
nb_repos() {
[ -z "$FUNCNAME" ] && local FUNCNAME='nb_repos' # for busybox
(
[ -s "$conf" ] || conf="$NB_ROOT/etc/repos.conf"
# Realpath
- #ls -d1 $(grep -v '^ *\(#\|$\)' "$conf") 2>/dev/null
-# NB 22.02.19 local IFS="
-# NB 22.02.19 "
-# NB 22.02.19 for dir in $(eval ls -d1 $(grep -v '^ *\(#\|$\)' "$conf") 2>/dev/null); do
eval ls -d1 $(grep -v '^ *\(#\|$\)' "$conf") 2>/dev/null | while read dir; do
# Accept directories or files (ex: use to tag a directory: .nb-install)
[ -z "$env_value" ] || echo "$env_value"
}
-if ! which realpath >/dev/null; then
-realpath() {
- if which perl 1>/dev/null; then
- perl -MFile::Spec -MCwd -e 'print File::Spec->rel2abs( Cwd::abs_path($ARGV[0]) )."\n" if -e $ARGV[0]' "$1"
- else
- case "$OSTYPE" in
- darwin*) readlink "$1" ;;
- *) readlink -f "$1" ;;
- esac
- fi
-}
-fi
-
ascii() {
if [ ! -t 0 ]; then