#!/bin/zsh # # Tim K.'s personal .zshrc # With changes from 5 December 2023 # # Copyright (C) Tim K 2019-2023 # Licensed under 0BSD License # is_decimal() { modified_value=`printf '%s' "$1" | tr -d '[:digit:]' | \ tr -d '+' | tr -d '-' | tr -d '.'` test -z "$modified_value" return $? } cli_message() { color_code="$1" title="$2" format="$3" shift 3 # make sure color code is a valid decimal number if ! is_decimal "$color_code" then cli_error "Invalid color code - $color_code" fi printf '\033[%dm\033[1m%s\033[0m ' $color_code "$title" printf "${format}" $@ printf '\n' return 0 } cli_warn() { cli_message 33 "Warning!" $@ return $? } cli_error() { cli_message 31 "Error!" $@ return $? } cli_success() { cli_message 32 "Success!" $@ return $? } coloring() { cli_warn "This command is no longer available due to compatibility issues" return 1 } not_one_of() { compared="$1" shift for comparison in $@ do test "$compared" = "$comparison" && return 1 done return 0 } deduct_macos_version() { # handle both Mac with sw_vers and non-Mac platforms sw_vers_out=`sw_vers -productVersion 2>/dev/null` test -z "$sw_vers_out" && sw_vers_out='0.0' major=`printf '%s' "$sw_vers_out" | cut -d. -f1` minor=`printf '%s' "$sw_vers_out" | cut -d. -f2` output="$major$minor" # nobody is interested in macOS 11+ point releases, cause they # don't bring any change to the SDKs test $major -gt 10 && output=$major # in the cases below, act like a boolean-returning command if test "$1" = "-is-legacy" then test $major -lt 11 return $? elif test "$1" = "-is-monterey-or-newer" then test $major -gt 11 return $? fi case "$1" in -major) output=$major ;; -minor) output=$minor ;; -M) ;; *) output="$major.$minor" ;; esac printf '%s\n' "$output" return 0 } cddev() { cd "$TenFen_Development_Prefix" if test ! -z "$1" then for subd in * . do dirv="$subd/$1" test -d "$dirv" && cd "$dirv" done fi return 0 } gen_dev_prefix_dirs() { # the new development prefix I usually use is neutrally called # "Sources" echo "$HOME/Sources" # on other platforms, it is usually also just $HOME/dev and that's # it test `uname` != 'Darwin' && echo "$HOME/dev" && return 0 major=`deduct_macos_version -major` combined=`deduct_macos_version -M` # current macOS versioned prefix is important echo "$HOME/dev$combined" # handle dev prefixes from possible past macOS versons for possible_major in `seq $major -1 11 2>/dev/null` do echo "$HOME/dev$possible_major" done for possible_doubles in `seq 1016 -1 1010` \ `seq 109 -1 100` \ PB do echo "$HOME/dev$possible_doubles" done # and, of course, the generic one echo "$HOME/dev" return 0 } finderInPWD() { cli_warn "This command ($0) is deprecated and will be removed soon." killall Finder; open -a Finder . return $? } @() { cli_warn "This command ($0) is deprecated and will be removed soon." test -z "$1" && cd .. && return 0 test ! -d "$1" && mkdir -vp "$1" cd "$1" return $? } detect_build_flair() { flag="$1" test -z "$flag" && flag='-A' arch_flair="`uname -m`" arch_flair_alt=unknown arch_machine=unknown arch_os=unknown # detect the OS first case "`uname`" in # macOS - darwinXX, where XX is the major kernel version Darwin) { if test -f "/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder" then # Mac computers arch_machine=apple else # OpenDarwin on PCs, Power Macs or compatibles arch_machine=pc fi arch_os=darwin`uname -r | cut -d. -f1` } ;; # FreeBSD - freebsdXX, where XX is the major OS version FreeBSD) arch_os=freebsd`freebsd-version | cut -d- -f1 | cut -d. -f1` ;; # OpenBSD - openbsdX.X, where X.X is the specific OS release version (major + minor) OpenBSD) arch_os=openbsd`uname -r` ;; # NetBSD - just the OS name, version info omitted NetBSD) arch_os=netbsd ;; # Solaris (SunOS) - solarisX.XX, where X.XX is a SunOS backwards compatibility version flair SunOS) arch_os=solaris`uname -r`;; # Linux - linux-gnu, since we are probably using a contemporary Linux distribution with glibc Linux) arch_os=linux-gnu ;; *) cli_warn 'Your OS (%s) is not covered by %s, the build flair ($BUILD_FLAIR) will be inaccurate.' \ "`uname`" ;; esac # now the architecture case "$arch_flair" in # Apple and *BSDs call it arm64, which is correct, Linux and GNU call it differently arm64|aarch64|armv[89]*) arch_flair=aarch64 && arch_flair_alt=arm64 ;; # armhf is ARMv7 (hard-float ARM) armhf|armv7*) arch_flair=arm && arch_flair_alt=armhf ;; # armel seems (??) to be pointing to ARMv6 and older armel|armv[456]*) arch_flair=arm && arch_flair_alt=armel ;; # Intel/AMD x86_64 CPUs - different OSes call them differently, GNU calls them x86_64 x86_64|amd64) arch_flair=x86_64 && arch_flair_alt=amd64 ;; # Intel i386 - 586 is Pentium, 686+ are the last 32-bit Intel CPUs (Core Solo/Duo) i[34567]86|ia32) arch_flair=i386 && arch_flair_alt=i586 ;; # 64-bit IBM POWER CPUs running in little-endian mode - GNU prefers the full name ppc64le|powerpc64le) arch_flair=powerpc64le && arch_flair_alt=ppc64le ;; # 64-bit IBM POWER CPUs in big-endian mode ppc64*|powerpc64*) arch_flair=powerpc64be && arch_flair_alt=ppc64 ;; # 32-bit Apple PowerPC and IBM POWER CPUs Power*|ppc*|powerpc*) arch_flair=powerpc && arch_flair_alt=ppc ;; *) cli_warn 'Your CPU architecture (%s) is not supported, the build flair ($BUILD_FLAIR) will be %s' \ "`uname -m`" inaccurate. ;; esac if test "`printf '%s' "$arch_os" | cut -d- -f1`" = "linux" then if test -f /etc/mageia-release then arch_machine=mageia elif test -f /etc/mandrakelinux-release || test -f /etc/mandriva-release then arch_machine=mandriva elif test -f /etc/SuSE-release then arch_machine=suse elif test -f /etc/redhat-release then arch_machine=redhat elif test -f /etc/debian_version then arch_machine=debian test "`lsb_release -i`" = "Ubuntu" && arch_os=ubuntu fi fi # use pc as $arch_machine on non-Mac Intel-based computers if test "$arch_flair" = "x86_64" || test "$arch_flair" = "i386" then test "$arch_machine" = "unknown" && arch_machine=pc fi case "$flag" in -A) printf '%s-%s-%s\n' "$arch_flair" "$arch_machine" "$arch_os" ;; -a|--alt*) printf '%s-%s-%s\n' "$arch_flair_alt" "$arch_machine" "$arch_os" ;; -p|--cpu) printf '%s\n' "$arch_flair" ;; --cpu-alt*) printf '%s\n' "$arch_flair_alt" ;; -M|--machine) printf '%s\n' "$arch_machine" ;; -i|-I|--os|--platform) printf '%s\n' "$arch_os" ;; -?|-h*|--help|*) cli_warn 'Usage: %s [-Aa] [-p] [-M] [-i]' "$0" && return 1 ;; esac return 0 } detect_tcl_path() { # on macOS, the last Apple-patched version of Tcl is used preferred_version='8.5.9-apple' # on other platforms, there is really no preferefence test `uname` != 'Darwin' && preferred_version=system # base directory where all Tcl versions are stored tcl_base_prefix="$TenFen_Prefix/Tcl" # a selected version file might be present in the $tcl_base_prefix and, unless overriden # later by the environment variables processed, will be perceived as a preferred version test -f "$tcl_base_prefix/.version" && preferred_version=`cat "$tcl_base_prefix/.version"` # there might be a preferred version specified explicitly though, which is what we # must respect test ! -z "$TenFen_Tcl_Version" && preferred_version="$TenFen_Tcl_Version" # if the system-provided version is requested, then probably it is available in $PATH al- # ready, so we don't have much to do in this case test "$preferred_version" = "system" && return 1 # binary directory where the preferred Tcl version is probably stored if it is exists tcl_preferred_bindir="$tcl_base_prefix/$preferred_version/bin" if test ! -z "$preferred_version" && test "$preferred_version" != "system" && \ test -d "$tcl_preferred_bindir" then # found it!! printf '%s' "$tcl_preferred_bindir" return 0 fi # display a warning that the preferred version was not found cli_warn '%s (%s) %s %s %s' \ 'Preferred Tcl version' "$preferred_version" 'does not appear to be' \ 'installed on this system. Will be using whatever version of Tcl' \ 'is present (be it a system-provided copy or a different custom build)' for directory in `find "$tcl_base_prefix" -type d -depth 1` do tcl_detected_bindir="$directory/bin" if test -d "$tcl_detected_bindir" then # will be using the version that we've found printf '%s' "$tcl_detected_bindir" return 0 fi done # found nothing, it seems return 1 } deduct_path_for_prefix() { # make sure potential $TenFen_Prefix value is specified test -z "$1" && return 1 # prog builds that have version prefixes and have to be handled differently skipped_catgs=( Python{2,3} cURL Perl Git OpenSSL QEMU zsh ) # custom prog builds for subdir in "$1"/* do subdir_bn=`basename "$subdir"` if not_one_of "$subdir_bn" Ruby $skipped_catgs then # Rubies are being treated differently test ! -f "$subdir/.disabled" && test -d "$subdir/bin" && PATH="$subdir/bin:$PATH" export PATH fi done # import the correct Ruby version if test "$TenFen_Ruby_Version" != "system" then ruby_dir="$1/Ruby/$TenFen_Ruby_Version/bin" if test ! -d "$ruby_dir" then cli_warn 'Ruby version %s is unavailable, using system default.' $TenFen_Ruby_Version export TenFen_Ruby_Version=system else export PATH="$1/Ruby/$TenFen_Ruby_Version/bin:$PATH" fi fi # import the correct Tcl version to $PATH as well tcl_bindir=`detect_tcl_path` test $? = 0 && export PATH="$tcl_bindir:$PATH" # now handle the rest of the versioned gang for catg in $skipped_catgs do dir="$1/$catg" version_file="$dir/.version" # if we don't have this software installed, skip it test ! -d "$dir" && continue # if version is selected, use it, otherwise, detect it automatically if test -f "$version_file" then export PATH="$dir/`cat "$version_file"`/bin:$PATH" else # use autodetected prefix automaticaly then used_pfx=`find "$dir" -type d -depth 2 -name bin | head -1` export PATH="$used_pfx:$PATH" fi done return 0 } # manages "$HOME/.tfpath.cache" ($PATH cache) verify_path_prefix_integrity() { action=verify if test ! -z "$1" then case "$1" in --update-cache|-U) action=update ;; --calculate-estimate|-E) action=estimate ;; --reload-proposed-path|-P) action=reload ;; --dump-cached-path) action=dump ;; --help|-h|-?|*) { # show help and quit cli_warn "Usage: $0 [-U|-E|-P|--dump-cached-path|-h]" return 1 } esac fi primary_prefix="$TenFen_Prefix" # allow using 32-bit Intel software on capable Mac OS X 10.5 and 10.6 # installations by scanning the multiarch prefix as well multiarch_prefix='' $TenFen_MacOSX_MultiArch && multiarch_prefix="$TenFen_Prefix/i386" prefix_related=true if test "$action" = "reload" then # include all the software in $TenFen_Prefix to $PATH deduct_path_for_prefix "$primary_prefix" deduct_path_for_prefix "$multiarch_prefix" elif test "$action" = "estimate" then # get a fingerprint count estimate on how much software do we have # installed in the primary prefix total_count=`find "$primary_prefix" -type d -depth 2 | \ wc -l | tr -d '[:space:]'` if test ! -z "$multiarch_prefix" then # have to count in 32-bit software as well multiarch_count=`find "$multiarch_prefix" -type d -depth 2 | wc -l | tr -d '[:space:]'` total_count=`expr $multiarch_count + $total_count` fi printf '%d' "$total_count" # clean up unset total_count unset multiarch_count else prefix_related=false fi # clean up temporary prefix vars since they can all be later poked with in the # shell unset primary_prefix unset multiarch_prefix # if it was prefix related, finish up $prefix_related && return 0 cache_path="$HOME/.tfpath.cache" # otherwise, it's the cache ops themselves if test "$action" = "update" then # calculate updated estimate for the cache total_count=`verify_path_prefix_integrity -E` # write it printf '%d\n%s\n%s\n%s\n' $total_count "$PATH" \ "$TenFen_Ruby_Version" \ "$TenFen_Tcl_Version" > "$cache_path" elif test "$action" = "verify" then # if no cache is present, means we need to create it later on test ! -f "$cache_path" && return 1 # legacy cache format (where scripting languages' versions are # not documented) should be avoided and ignored test "`cat "$cache_path" | wc -l | tr -d '[:space:]'`" != 4 && \ return 4 # obtain cached estimate and make sure it's the same as now cache_count=`cat "$cache_path" | head -1` test "$cache_count" = "`verify_path_prefix_integrity -E`" # if not, it is already a reason to rebuild the value of $PATH test $? != 0 && return 2 # make sure the requested Ruby and Tcl builds' versions were # not changed cache_version=`cat "$cache_path" | tail -2` cache_ruby_version=`printf '%s' "$cache_version" | head -1` cache_tcl_version=`printf '%s' "$cache_version" | tail -1` # if at least one of them does not match, this is a reason to # regenerate $PATH (test "$cache_ruby_version" = "$TenFen_Ruby_Version" && \ test "$cache_tcl_version" = "$TenFen_Tcl_Version") || \ return 3 return $? elif test "$action" = "dump" then # if no cache is present, will pass in the one that we have already # (but that is weird in this case) if test ! -f "$cache_path" then cli_warn "No \$PATH cache available at \"$cache_path\", will use PATH=\"$PATH\" for now" cli_warn "You can regenerate cache using this command:" cli_warn '\t%s --update-cache' verify_path_prefix_integrity printf '%s' "$PATH" return 1 fi # otherwise, use cached $PATH cat "$cache_path" | head -2 | tail -1 return $? else cli_error "Unknown action - $action" return 1 fi return 0 } deduct_path_without_extension() { target_file="$1" test -z "$target_file" && return 1 # split path into dirname and basename to avoid tampering with dot-containing # folder names target_dirname=`dirname "$target_file"` target_basename=`basename "$target_file"` # if file has an existing file extension -> remove it if printf '%s' "$target_basename" | grep '.' > /dev/null 2>&1 then target_basename=`printf '%s' "$target_basename" | rev | cut -d. -f2- | rev` fi # form updated path target_file="$target_dirname/$target_basename" printf '%s' "$target_file" return 0 } # detect path to a proper GNU nano installation (preferrably the custom-built one) detect_nano() { result="$TenFen_Prefix/GNUnano/bin/nano" if test ! -f "$result" then # some systems actually have properly working modern GNU nano # builds case `uname` in Linux) result=/usr/bin/nano ;; *BSD) result=/usr/local/bin/nano ;; # on Macs, it is acceptable to use a 32-bit Intel version of GNU nano # in this case Darwin) $TenFen_MacOSX_MultiArch && result="$TenFen_Prefix/i386/GNUnano/bin/nano" ;; esac # considering the $EDITOR path might have changed, its validity # has to be checked again test ! -f "$result" && cli_warn "No appropriate version of GNU nano could be detected on your system, please install it" return 1 fi printf '%s' "$result" return 0 } markdown2html() { source_file="$1" test -z "$source_file" && cli_error "Input markdown file not specified" && \ return 1 if ! not_one_of "$source_file" --help -h -\? then cli_warn "Usage: $0 /path/to/markdown/file.md []" return 0 elif ! command -v pandoc > /dev/null 2>&1 then cli_error "pandoc is not installed" return 1 fi output_file="$2" test -z "$output_file" && output_file="`deduct_path_without_extension "$source_file"`.html" echo "$source_file -> $output_file" if ! pandoc --from=markdown --to=html --output="$output_file" "$source_file" then cli_warn "pandoc exited with error code $?, conversion failed" return 1 fi cli_success "pandoc exited successfully, conversion complete" return 0 } alias md2html=markdown2html img2fdd() { source_file="$1" target_file="$2" # 1.44 MB floppy size constant fixed_size=1474560 if test -z "$1" || ! not_one_of "$1" --help -h -\? then cli_warn "Usage: $0 []" return 1 fi # deduct target path if it wasn't specified explicitly test -z "$target_file" && target_file="`deduct_path_without_extension "$source_file"`.fdd" # generate temporary file paths to be used later zeroes_file="$TenFen_Temp_Prefix/img2fdd.zeroes.$RANDOM.fdd" untruncated_file="$TenFen_Temp_Prefix/img2fdd.untruncated.$RANDOM.fdd" # first, generate the zeroes dd if=/dev/zero of="$zeroes_file" bs=$fixed_size count=1 || return $? # then combine source with the zeroes and truncate it to $fixed_size cat "$source_file" "$zeroes_file" > "$untruncated_file" dd if="$untruncated_file" of="$target_file" bs=$fixed_size count=1 exit_code=$? # clean up and exit rm -f "$untruncated_file" "$zeroes_file" return $exit_code } alias mkfdd=img2fdd toolchain_select() { action=help case "$1" in --select|--set|-s) action=select ;; --list|-l) action=list ;; --help|-h|-?|*) action=help ;; esac if test "$action" = "help" then # show help and exit cli_warn "Usage: $0 --select TOOLCHAIN" cli_warn " $0 --list" return 1 fi # make sure $TenFen_Toolchains_Prefix is a valid directory test ! -d "$TenFen_Toolchains_Prefix" && \ cli_error '\033[1m%s\033[0m is unavailable, cannot do anything, sorry' "$TenFen_Toolchains_Prefix" && \ return 1 if test "$action" = "list" then echo "Available toolchains:" for full_bn in "$TenFen_Toolchains_Prefix"/* do bn=`basename "$full_bn"` test "$bn" != "bin" && echo "$bn" done return 0 fi picked_tc="$2" # convert alias to the appropriate full name if used case "$picked_tc" in elf32) picked_tc="i386-elf-gnu42" ;; elf64) picked_tc="x86_64-elf-gnu42" ;; linux64_42) picked_tc="x86_64-manbo-linux-gnu42" ;; linux64) picked_tc="x86_64-mageia-linux-gnu95" ;; freebsd*) picked_tc="x86_64-freebsd9-gnu42" ;; *) ;; esac # we can't continue if no toolchain name was provided test -z "$picked_tc" && cli_error "Toolchain name missing, cannot change anything, sorry" && \ return 2 # check if the specified toolchain is installed and has a /bin directory bindir_tc="$TenFen_Toolchains_Prefix/$picked_tc/bin" test ! -d "$bindir_tc" && cli_error '\033[1m%s\033[0m unavailable, cannot change anything, sorry' "$bindir_tc" && \ return 3 # remove previous toolchain symlinks to avoid conflict bindir="$TenFen_Toolchains_Prefix/bin" test -d "$bindir" && rm -rf "$bindir" mkdir -vp "$bindir/bin" for full_bn in "$bindir_tc"/* do bn=`basename "$full_bn"` ln -vs "$full_bn" "$bindir/$bn" || { cli_error 'Symlinking \033[1m%s\033[0m failed' "$full_bn" return 4 } done cli_success 'Your current toolchain is now set to \033[1m%s\033[0m' "$picked_tc" return 0 } # convenient aliases for toolchain_select virtual command alias toolchain-select=toolchain_select alias tc=toolchain_select # convenient aliases for hex2num custom external command alias hex2dec='hex2num -d' alias dec2hex='hex2num -x' alias hex2bin='hex2num -b' alias bin2hex='hex2num -x' alias dec2bin='hex2num -b' alias bin2dec='hex2num -d' alias cdhell='cd ~/Documents/bureacracy' alias .=source # add alias to nano for editing space-indented files alias enano='nano -E -T 4' TenFen_Legacy_Shell=false TenFen_CPU_Architecture=`uname -m` # this variable is set on macOS 11.0+ in order to extend the regular # prompt by including additional situation-dependent information such # as git branch information, etc TenFen_Use_Advanced_Prompt=false # on most UNIX systems, $TEMP is in /tmp TenFen_Temp_Prefix=/tmp # this variable is set on macOS 10.5/10.6 when running on Core 2 # Duo Macs - the OS can run both 32-bit and 64-bit Intel binaries TenFen_MacOSX_MultiArch=false if test `uname` = 'Darwin' then # C compilers must be clang-based by default on Mac CXX=clang++ CC=clang if deduct_macos_version -is-legacy then # in this case, it really depends, we have: # - clang for 10.9+ (Mavericks and up) # - llvm-gcc for 10.6-10.8 (Snep, Lion, Mountain Lion) # - gcc for 10.5- (Leopard and older, also Snep if we # are using legacy Xcode versions) macos_vmin=`deduct_macos_version -minor` if test $macos_vmin -lt 9 then # legacy Mac versions have old zsh, which doesn't know about seq, Unicode # or anything modern like that if test `deduct_macos_version -minor` -lt 8 then TenFen_Legacy_Shell=true fi # on Mac OS X 10.5 and 10.6, legacy Core 2 Duo Macs report as if they # are 32-bit when, in fact, they can run 64-bit executables if test $macos_vmin = 6 || test $macos_vmin = 5 then if test `sysctl -n hw.cpu64bit_capable` = 1 then TenFen_CPU_Architecture=x86_64 TenFen_MacOSX_MultiArch=true fi fi # TODO: refactor # look into the developer prefix if test -f /Developer/usr/bin/llvm-gcc then CXX=llvm-g++ CC=llvm-gcc # also add the CLI tools to $PATH export PATH="/Developer/usr/bin:$PATH" else CXX=g++ CC=gcc fi fi else # make sure to enable advanced prompt capabilities on macOS 11.0+ (only # when the Xcode toolchain is installed) xcode-select -p > /dev/null 2>&1 && TenFen_Use_Advanced_Prompt=true fi export CXX CC # by the way, Macs have $TEMP in /private/tmp TenFen_Temp_Prefix=/private/tmp else # Unicode emojis might not be supported well by other platforms than # macOS really TenFen_Legacy_Shell=true fi export TenFen_Use_Advanced_Prompt export TenFen_Legacy_Shell export TenFen_Temp_Prefix if $TenFen_Legacy_Shell then # implement seq seq() { increment=1 base=$1 target=$2 if test $# -gt 2 then # custom increment specified increment=$2 target=$3 elif test $# -lt 2 then cli_warn "Usage: seq " return 2 elif test $target -lt $base then # increment must be negative by default increment=-1 fi test $increment = 0 && cli_warn "seq increment parameter cannot be zero, exiting as is" && return 1 # adapt conditional to the arguments properly what_to_test='-lt' test $increment -lt 0 && what_to_test='-gt' while test $base $what_to_test $target do printf '%d\n' $base base=`expr $base + $increment` done printf '%d\n' $target return 0 } # simplified prompt export PROMPT='%~ $ ' else if $TenFen_Use_Advanced_Prompt then # enable prompt substitution first set -o PROMPT_SUBST prompted_git_branch() { # do nothing unless we are in a proper or bare git repository test ! -d "$PWD/.git" && test ! -d "$PWD/refs/heads" && \ return 1 # detect current git branch name branch_name=`git branch --show-current 2>/dev/null` test -z "$branch_name" && return 1 printf '%s \U1F343%s %s' '%K{133}%F{15}' "$branch_name" '%k' return 0 } fi # regular prompt PROMPT='%K{26}%F{15} %(?.'$'\U2705''.'$'\U26A0\UFE0F'' %?) %K{34} %~ %k%f %# ' # advanced prompt (used only when enabled) $TenFen_Use_Advanced_Prompt && PROMPT='`prompted_git_branch`'"$PROMPT" # set it up! export PROMPT fi # detect source code directory TenFen_Development_Prefix="$HOME" for possibility in /Volumes/TimStorage{SSD,}/Dev{,elopment} \ "$HOME/Documents/"{Development,git} \ `gen_dev_prefix_dirs` do test -d "$possibility" && TenFen_Development_Prefix="$possibility" done export TenFen_Development_Prefix # enable -fPIC by default for static builds if test -z "$TenFen_No_fPIC" then CFLAGS='-fPIC' CXXFLAGS='-fPIC' export CFLAGS CXXFLAGS fi TenFen_Use_Pathman=true # detect potential pathman binary location TenFen_Pathman_Command=`command -v pathman 2>/dev/null` test -z "$TenFen_Pathman_Command" && TenFen_Pathman_Command="$HOME/bin/pathman" if test -f "$TenFen_Pathman_Command" then # perfect, pathman is the upcoming replacement for the former buggy # and slow $PATH generation mechanism, and it is responsible for de- # tecting the prefix and generating $PATH TenFen_Pathman_Path=`"$TenFen_Pathman_Command" 2>/dev/null` if test $? != 0 || test -z "$TenFen_Pathman_Path" then # something went wrong with pathman, fallback to the other # $PATH generation mechanism cli_warn "pathman failed to generate a proper \$PATH, you probably don't have the prefix in your $PATH" TenFen_Use_Pathman=false else export PATH="$TenFen_Pathman_Path" export TenFen_Prefix=`"$TenFen_Pathman_Command" -P 2>/dev/null` fi else # pathman unavailable -> use fallback TenFen_Use_Pathman=false fi if ! $TenFen_Use_Pathman then cli_warn "You are using the legacy \$PATH generation mechanism. It is deprecated and will no longer be updated (unless stated otherwise). pathman is the planned more efficient replacement. Please install pathman to $HOME/bin or any other preferred default system \$PATH." # detect prefix depending on the current platform TenFen_Prefix=/Library/TenFen test `uname` != 'Darwin' && TenFen_Prefix=/usr/tenfen # and now for all the arch-dependent stuff case "$TenFen_CPU_Architecture" in x86_64|amd64) ;; i*86) TenFen_Prefix="$TenFen_Prefix/i386" ;; arm64|aarch64) { if test `uname` != "Darwin" || ! deduct_macos_version -is-monterey-or-newer then TenFen_Prefix="$TenFen_Prefix/arm64" fi } ;; mips*) TenFen_Prefix="$TenFen_Prefix/mips" ;; ppc*|Power*) TenFen_Prefix="$TenFen_Prefix/ppc" ;; *) cli_warn "Current architecture is not supported ($TenFen_CPU_Architecture). Using the default prefix '$TenFen_Prefix'." ;; esac export TenFen_Prefix # if this is true, this means that "$HOME/.tfpath.cache" provided $PATH is used TenFen_Prefix_Cache_Intact=false if ! verify_path_prefix_integrity then # set $PATH by importing everything from $TenFen_Prefix verify_path_prefix_integrity -P # save $PATH into a cache file at "$HOME/.tfpath.cache" in order to # speed up $PATH lookup verify_path_prefix_integrity --update-cache else # use cached $PATH then export PATH=`verify_path_prefix_integrity --dump-cached-path` TenFen_Prefix_Cache_Intact=true fi export TenFen_Prefix_Cache_Intact export TenFen_Ruby_Version=system export TenFen_Tcl_Version=system fi # gcc and non-gcc cross-compilation toolchains are all stored there export TenFen_Toolchains_Prefix="$TenFen_Prefix/Toolchains" # create $TenFen_Toolchain_Prefix/bin in advance so that it would land in $PATH if test ! -d "$TenFen_Toolchain_Prefix/bin" then mkdir -vp "$TenFen_Toolchain_Prefix/bin" 2>/dev/null || \ cli_warn "Cannot create \"$TenFen_Toolchain_Prefix/bin\", please create it manually later" fi # set build flair variables export BUILD_FLAIR=`detect_build_flair` export BUILD_FLAIR_ALT=`detect_build_flair --alt` export TenFen_Build_Flair="$BUILD_FLAIR" export TenFen_Build_Flair_Alt="$BUILD_FLAIR_ALT" # set nano as the default editor export EDITOR=`detect_nano` if test `whoami` != "root" && test -f /etc/mandriva-release then # Mandriva Linux and alike have a package manager called urpmi, which # basically exclusively runs as root. Although very user-friendly, it # also has an annoying habit of trying to force users to install # "recommended" packages, a behaviour I personally despise. So in this # alias, it is being turned off for good alias urpmi='sudo /usr/sbin/urpmi --no-recommends' # make other urpmi commands accessible as well for urpmi_postfix in e i.{add,remove}media i.update do alias "urpm$urpmi_postfix"="sudo /usr/sbin/urpm$urpmi_postfix" done fi # add $HOME/bin to $PATH for locally-installed bins export PATH="$HOME/bin:$PATH"