Just wonder if it's possible to run some command (enter virtualenv e.g.) at Cmder startup. I saw a couple of threads describing running .bat file at startup, but that's not quite what I want.
Just feel like there must be a way for me to add something in the tasks and somehow when my git bash fires up, it can automatically run some commands. Any help would be appreciated. Thanks.
Drop a script into $cmder_root/config/profile.d folder. It has to end with '.sh' for bash, '.cmd' for cmder, or 'ps1' for PowerShell. Drop as many as you want it will run all scripts in that folder for each shell type.
@daxgames Thanks for the reply.
I go into my config folder, there is no folder called profile.d, so I just manually created one.
I just type in source activate python3 for example save the file as .sh as I'm using git bash in Cmder.
Did I do anything wrong? Sorry I'm really new to this. Thanks.
Are you using cmder 1.3.x? If not update to it and you will have a profile.d folder
@daxgames I'm not even sure where to check Cmder version... In the about, it says it stable version 160914. I'm pretty sure this should be the latest one, and I checked again, there is no profile.d folder.
I also checked the Cmder Repo here, and there is no profile.d folder either...
Hmm.... Thats odd, I thought the profile.d folder was in the distribution but apparently not. I guess I need to update the code to create it if its is not there on first run. Will do that today and create a PR.
Type ' ls $CMDER_ROOT\vendor\git-for-windows\etc\profile.d\cmder.sh'. If you have it then you are at least on 1.3.0 and creating '$CMDER_ROOT/config/profile.d/script.sh' should run that script when git bash starts if you are using git-for-windows included with commander (meaning you do not have it installed externally in the path). Cmder will prefer external git for windows over its own embedded version.
Never mind it already is in the source to create it so if its not there you may be downlevel on cmder version OR you are using external git for windows. if you are using an external git for windows see the readme on how to integrate it with 'cmder_exinit'.
Check version by doing 'ls $CMDER_ROOT'
CHANGELOG.md CONTRIBUTING.md Cmder.exe* README.md 'Version v1.3.0' bin/ config/ icons/ vendor/
Thanks @daxgames
It all makes sense now. I'm now using 1.3.1 with external git for windows. Although the command source activate python3 was run properly, the virtual environment was not displayed in cmder in bracket. Moreover, when I deactivate it, it just breaks the UI in Cmder as shown below. Is there a way to fix this? Thanks.

Another side effect based on this is it only works for within Cmder.
I use ConEmu Here in integration menu to make a Git Bash Here, so I can always get git bash open in the current directly. However, running git bash here now gives the message below:

This means I can't get the command running on startup any more... Just wonder if I'm doing everything right?
I tried to use cmder here instead by creating a task that runs Git Bash at current working directory, but I just can't get it to work. In the task command, it won't recognise %CD%.
Any help would be appreciated. Thanks.
If you copy cmder_exinit as stated in the cmder readme.md to your external git for windows /etc/profile.d I folder think it will do what you want. Have you tried this?
@daxgames I did, and it did work. It just breaks the UI when I deactivate it as I posted above.
Also, it only work if I start using cmder.exe, but won't work if I start using context menu which uses integration from ConEmu.exe
From cmder_exinit:
# # 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.
@daxgames Thanks for the highlight. I did change this, but I didn't read through the code and just assume ${USERPROFILE}=%USERPROFILE%. After fixing this, it's all good now.
However, it will still break the UI if I put virtual environment related code in the profile. You don't have to fix this as I've found a work-around for my environment. Just an observation.
Meanwhile, I noticed that in 1.3.1, you put cmd /c "%ConEmuDir%\..\git-for-windows\bin\bash --login -i" -new_console:d:%USERPROFILE% as Git Bash start command. It won't work, you should change it to cmd /c "%ConEmuDir%\..\git-for-windows\bin\bash" --login -i -new_console:d:%USERPROFILE% for it to work, i.e. leaving --login -i outside the quotes. Just another observation.
Thanks for the help along the way. Please keep up the awesome work.
I just wanted to run "vagrant up" and "vagrant ssh" every time I open Cmder. Perhaps this helps someone:
> "%ConEmuDrive%\Program Files\Git\bin\bash.exe" --login -i -new_console:a:C:"%ConEmuDrive%\Program Files\Git\etc\git.ico":t:"DrupalVM Site" -new_console:d:C:\drupalvm-site -c "echo 'Running \"vagrant up\"' && vagrant up && echo 'Running \"vagrant ssh\"' && vagrant ssh" -new_console:c
The last "-new_console:c" part is required to keep the console open once it's done running the commands.
Most helpful comment
I just wanted to run "vagrant up" and "vagrant ssh" every time I open Cmder. Perhaps this helps someone:
> "%ConEmuDrive%\Program Files\Git\bin\bash.exe" --login -i -new_console:a:C:"%ConEmuDrive%\Program Files\Git\etc\git.ico":t:"DrupalVM Site" -new_console:d:C:\drupalvm-site -c "echo 'Running \"vagrant up\"' && vagrant up && echo 'Running \"vagrant ssh\"' && vagrant ssh" -new_console:cThe last "-new_console:c" part is required to keep the console open once it's done running the commands.