From 734b63dd617e7b0f47e4b21de7b7748aced513c4 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Thu, 25 Feb 2016 07:53:57 -0600 Subject: [PATCH] Added profile.d like support for all supported shells --- README.md | 10 ++++++++++ vendor/cmder.sh | 13 +++++++++++++ vendor/init.bat | 14 ++++++++++++++ vendor/profile.ps1 | 12 ++++++++++++ 4 files changed, 49 insertions(+) diff --git a/README.md b/README.md index 5c1c250da..99fb51edb 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,16 @@ User specific configuration is possible using the cmder specific shell config fi Note: Bash and Mintty sessions will also source the '$HOME/.bashrc' file it it exists after it sources '$CMDER_ROOT/config/user-profile.sh'. +### Linux like 'profile.d' support for all supported shell types. +You can write *.cmd|*.bat, *.ps1, and *.sh scripts and just drop them in the %CMDER_ROOT%\config\profile.d folder to add startup config to Cmder. + +|Shell|Cmder 'Profile.d' Scripts| +| ------------- |:-------------:| +|Cmder|%CMDER_ROOT%\config\profile.d\*.bat and *.cmd| +|Powershell|$ENV:CMDER_ROOT\config\profile.d\*.ps1| +|Bash/Mintty|$CMDER_ROOT/config/profile.d/*.sh| + + ### Aliases #### Cmder(Cmd.exe) Aliases You can define simple aliases for `cmd.exe` sessions with a command like `alias name=command`. Cmd.exe aliases support optional parameters through the `$1-9` or the `$*` special characters so the alias `vi=vim.exe $*` typed as `vi [filename]` will open `[filename]` in `vim.exe`. diff --git a/vendor/cmder.sh b/vendor/cmder.sh index 4d1da3ac0..f51ace398 100644 --- a/vendor/cmder.sh +++ b/vendor/cmder.sh @@ -35,6 +35,19 @@ PATH=${CMDER_ROOT}/bin:$PATH:${CMDER_ROOT} export PATH +# Drop *.sh files into "%CMDER_ROOT%\config\profile.d" +# to run them at startup. +if [ ! -d ${CMDER_ROOT}/config/profile.d ] ; then + mkdir -p "${CMDER_ROOT}/config/profile.d" +fi + +pushd ${CMDER_ROOT}/config/profile.d >/dev/null +for x in $(ls ${CMDER_ROOT}/config/profile.d/*.sh) ; do + # echo ${x} + . $x +done +popd >/dev/null + if [ -f ${CMDER_ROOT}/config/user-profile.sh ] ; then . ${CMDER_ROOT}/config/user-profile.sh else diff --git a/vendor/init.bat b/vendor/init.bat index 89e27c00d..72221e695 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -88,6 +88,20 @@ @cd /d "%CMDER_START%" ) +:: Drop *.bat and *.cmd files into "%CMDER_ROOT%\config\profile.d" +:: to run them at startup. +@if not exist "%CMDER_ROOT%\config\profile.d" ( + mkdir "%CMDER_ROOT%\config\profile.d" +} + +@pushd "%CMDER_ROOT%\config\profile.d" +for /f "usebackq" %%x in ( `dir /b *.bat *.cmd` ) do ( + REM @echo Calling %CMDER_ROOT%\config\profile.d\%%x... + @call %%x +) +@popd + + @if exist "%CMDER_ROOT%\config\user-profile.cmd" ( @rem create this file and place your own command in there call "%CMDER_ROOT%\config\user-profile.cmd" diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 5713f761c..1aa037abb 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -91,6 +91,18 @@ if ( $ENV:CMDER_START ) { # Enhance Path $env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT" +# Drop *.ps1 files into "$ENV:CMDER_ROOT\config\profile.d" +# to run them at startup. +if (-not (test-path "$ENV:CMDER_ROOT\config\profile.d")) { + mkdir "$ENV:CMDER_ROOT\config\profile.d" +} + +pushd $ENV:CMDER_ROOT\config\profile.d +foreach ($x in ls *.ps1) { + # write-host Sourcing $ENV:CMDER_ROOT\config\profile.d\$x + . $x +} + $CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user-profile.ps1" if(Test-Path $CmderUserProfilePath) { # Create this file and place your own command in there.