# # Author: Georg Voell - georg.voell@standby.cloud # Version: @(#)lib.tcsh 3.1.1 07.09.2023 (c)2023 Standby.cloud # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ # # This script can be used free of charge. Use it as is or customize as needed. It is not guaranteed to be # error free and you will not be reimbursed for any damage it may cause. # # To include with "source lib.tcsh" # # Update history: # # V 3.0.0 18.04.2020 New version # V 3.1.0 05.06.2023 New copyright # V 3.1.1 07.09.2023 Use gnu sed and tail if available # # Get the REALUSER if (! $?REALUSER) then setenv USER `whoami` # Current user setenv OS `uname -s` # Infos about the host os (e.g. Darwin, SunOS, Linux) # Check if re run with 'sudo' if ($?SUDO_USER) then setenv REALUSER "$SUDO_USER" setenv REALGROUP `id -gn $SUDO_USER` setenv REALHOME ~${SUDO_USER} setenv HOME ~${USER} else setenv REALUSER "$USER" setenv REALGROUP `id -gn $USER` setenv REALHOME "$HOME" endif endif # Set PATH to something useful if (! $?WORKPATH) then if ("$REALHOME" == "/") then setenv WORKPATH "/usr/local/sbin:/usr/local/bin:/usr/gnu/bin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH" else setenv WORKPATH "${REALHOME}/.local/bin:${REALHOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/gnu/bin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH" endif endif # Define local default variables set pid = "$$" # Get the process id from current shell set exitcode = 0 # Default exit code set errstr = "" # Default error message set tmpdir = "/tmp" # Temporary directory set timestamp = `date '+%y%m%d%H%M%S'` # Extension String with current date and time set scratchfile = "${tmpdir}/${progstr}.${timestamp}.${pid}.tmp" # Temporary file set itrfile = "${tmpdir}/USER_INTERRUPT.tmp" # User interrupt # Don't terminate on file mismatch set nonomatch # If script terminates - do some cleanup # onintr Catch # Define helpful alias unalias * alias echo printf # Use printf instead of echo alias stripcomment sed \'s/\#.\*\$//\' # Ignore all comments alias tolower tr "[:upper:]" "[:lower:]" # Lowercase string alias toupper tr "[:lower:]" "[:upper:]" # Uppercase string alias grep grep -hsi # -h: No prefixing of filenames, -s: Suppess error messages, -i: Ignore case # Check if we have gnu tools installed set gsed = `which gsed` set stat = $? if ("$gsed" != "" && "$stat" == "0") then alias sed "$gsed" endif set gtail = `which gtail` set stat = $? if ("$gtail" != "" && "$stat" == "0") then alias tail "$gtail" endif # Some tail functions if ("$OS" == "SunOS") then # If we are runnung on Solaris, tail had to be handled different if (-x /usr/gnu/bin/tail) then alias tailfromline2 /usr/gnu/bin/tail -n +2 alias taillastline /usr/gnu/bin/tail -n 1 else alias tailfromline2 /usr/bin/tail +2 alias taillastline /usr/bin/tail -1 endif else alias tailfromline2 tail -n +2 alias taillastline tail -n 1 endif # Define some colors and bell if (! $?normal) then setenv normal '\033[0m' setenv bell '\007' setenv red '\033[0;31m' setenv green '\033[0;32m' setenv yellow '\033[0;33m' setenv blue '\033[0;34m' setenv magenta '\033[0;35m' setenv cyan '\033[0;36m' setenv gray '\033[0;90m' setenv white '\033[0;97m' setenv black '\033[0;30m' setenv bold '\033[1m' setenv highred '\033[0;91m' setenv pink '\033[0;95m' endif