cmder/vendor/cmder_exinit

107 lines
3.4 KiB
Plaintext
Raw Normal View History

2016-02-27 21:40:47 +08:00
# Copy this file to your non integrated *nix-like environment,
2016-02-28 02:00:40 +08:00
# Cygwin/MSys2/Git for Windows SDK, installs '/etc/profile.d/'
2016-02-27 21:40:47 +08:00
# folder to integrate the externally installed Unix like environment
# into Cmder so it has access to settings stored in Cmder/config
# folder when launched.
#
# The destination file extension depends on the shell you use. For example:
#
# bash - Copy to /etc/profile.d/cmder_exinit.sh
# zsh - Copy to /etc/profile.d/cmder_exinit.zsh
2016-02-27 21:40:47 +08:00
# Add portable user customizations ${CMDER_ROOT}/config/user-profile.sh or
# add whole config scripts to ${CMDER_ROOT}/config/profile.d both will be sourced
# from mthis file and be appied to the environment at startup.
#
# These customizations will follow Cmder if $CMDER_ROOT is copied
# to another machine.
#
# Add system specific users customizations to $HOME/.bashrc, these
# customizations will not follow Cmder to another machine.
2016-02-28 02:00:40 +08:00
# # Uncomment and edit the CMDER_ROOT line to use Cmder/config even when launched
# # from outside Cmder.
# CMDER_ROOT=${USERPROFILE}/cmder # This is not required if launched from Cmder.
2018-03-13 23:38:27 +08:00
function runProfiled {
unset profile_d_scripts
pushd "${1}" >/dev/null
if [ ! "x${ZSH_VERSION}" = "x" ]; then
profile_d_scripts=$(ls *.zsh 2>/dev/null)
elif [ ! "x${BASH_VERSION}" = "x" ]; then
profile_d_scripts=$(ls *.sh 2>/dev/null)
fi
if [ ! "x${profile_d_scripts}" = "x" ] ; then
for x in ${profile_d_scripts} ; do
echo Sourcing "${1}/${x}"...
. "${1}/${x}"
done
fi
popd >/dev/null
}
# Check that we haven't already been sourced.
[[ -z ${CMDER_EXINIT} ]] && CMDER_EXINIT="1" || return
# We do this for bash as admin sessions since $CMDER_ROOT is not being set
if [ "$CMDER_ROOT" = "" -a "$ConEmuDir" != "" ] ; then
2016-02-28 02:00:40 +08:00
if [ -d "${ConEmuDir}../../vendor" ] ; then
case "$ConEmuDir" in *\\*) CMDER_ROOT=$( cd "$(cygpath -u "$ConEmuDir")/../.." ; pwd );; esac
else
echo "Running in ConEmu without Cmder, skipping Cmder integration."
fi
elif [ "$CMDER_ROOT" != "" ] ; then
case "$CMDER_ROOT" in *\\*) CMDER_ROOT="$(cygpath -u "$CMDER_ROOT")";; esac
fi
2016-02-28 02:00:40 +08:00
if [ ! "$CMDER_ROOT" = "" ] ; then
# Remove any trailing '/'
CMDER_ROOT=$(echo $CMDER_ROOT | sed 's:/*$::')
echo "Using \"CMDER_ROOT\" at \"${CMDER_ROOT}\"."
2016-02-28 02:00:40 +08:00
export CMDER_ROOT
PATH=${CMDER_ROOT}/bin:$PATH:${CMDER_ROOT}
export PATH
# Drop *.sh or *.zsh files into "${CMDER_ROOT}\config\profile.d"
# to source them at startup.
if [ ! -d "${CMDER_ROOT}/config/profile.d" ] ; then
mkdir -p "${CMDER_ROOT}/config/profile.d"
2016-02-27 22:43:39 +08:00
fi
2016-02-28 02:00:40 +08:00
if [ -d "${CMDER_ROOT}/config/profile.d" ] ; then
2018-03-13 23:38:27 +08:00
runProfiled "${CMDER_ROOT}/config/profile.d"
2016-02-27 22:43:39 +08:00
fi
2016-02-28 02:00:40 +08:00
2018-03-13 23:38:27 +08:00
if [ -d "${CMDER_USER_CONFIG}/profile.d" ] ; then
runProfiled "${CMDER_USER_CONFIG}/profile.d"
fi
if [ -f "${CMDER_ROOT}/config/user-profile.sh" ] ; then
. "${CMDER_ROOT}/config/user-profile.sh"
2018-03-13 23:38:27 +08:00
fi
if [ -f "${CMDER_USER_CONFIG}/user-profile.sh" ] ; then
. "${CMDER_USER_CONFIG}/user-profile.sh"
2016-02-28 02:00:40 +08:00
else
2018-03-13 23:38:27 +08:00
if [ "${CMDER_USER_CONFIG}" != "" ] ; then
initialProfile="${CMDER_USER_CONFIG}/user-profile.sh"
else
initialProfile="${CMDER_ROOT}/config/user-profile.sh"
fi
echo Creating user startup file: "${initialProfile}"
cat <<-eof >"${initialProfile}"
# use this file to run your own startup commands for msys2 bash'
# To add a new vendor to the path, do something like:
# export PATH=\${CMDER_ROOT}/vendor/whatever:\${PATH}
eof
2016-02-28 02:00:40 +08:00
fi
fi