2015-10-15 18:15:19 +08:00
|
|
|
|
# Init Script for PowerShell
|
2015-10-15 01:50:49 +08:00
|
|
|
|
# Created as part of cmder project
|
|
|
|
|
|
|
|
|
|
# !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
|
|
|
|
|
# !!! Use "%CMDER_ROOT%\config\user-profile.ps1" to add your own startup commands
|
|
|
|
|
|
Added/enhanced bash with cmder.sh/user-cmder.sh, organized tasks menu
added personal files to .gitignore so they never get uploaded to the repo and added support for msys2 bash in the new git for windows
added autocreate of config/user-cmder.sh if iot does not exist and added it to the .gitignore
Added tasks: cmd::Cmder, cmd::Cmder as Admin, bash::bash, bash::bash as Admin, bash::mintty, bash::mintty as admin, powershell::powershell, powershell::powershell as Admin. Set default task to cmd::Cmder. Cot rid of init.bat running before /bin/bash, fixes double exit requirement
Added running git for windows post-install.bat on first cmder launch
fixed file/path not found errors when launching powershell as admin
fixed file/path not found errors when launching bash/mintty as admin
fixed PATH in vendor/cmder.sh
Added sourcing ~/.bashrc if it exists.
changed .gitignore to ignore anything with path of config/user-*
removed my personal files from .gitignore, left in config/user-*
Make sure $CMDER_ROOT does not have a trailing '/'
%CMDER_ROOT% does not have trailing '\'. allow user to specify a conemu.xml on the command line
Removed '\' from %CMDER_ROOT%
2015-11-09 11:25:42 +08:00
|
|
|
|
# We do this for Powershell as Admin Sessions because CMDER_ROOT is not beng set.
|
|
|
|
|
if (! $ENV:CMDER_ROOT ) {
|
|
|
|
|
$ENV:CMDER_ROOT = resolve-path( $ENV:ConEmuDir + "\..\.." )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Remove trailing '\'
|
|
|
|
|
$ENV:CMDER_ROOT = (($ENV:CMDER_ROOT).trimend("\"))
|
|
|
|
|
|
2015-10-15 02:24:54 +08:00
|
|
|
|
# Compatibility with PS major versions <= 2
|
2015-05-19 22:44:32 +08:00
|
|
|
|
if(!$PSScriptRoot) {
|
|
|
|
|
$PSScriptRoot = Split-Path $Script:MyInvocation.MyCommand.Path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Add Cmder modules directory to the autoload path.
|
2015-03-18 23:33:55 +08:00
|
|
|
|
$CmderModulePath = Join-path $PSScriptRoot "psmodules/"
|
2014-09-17 15:55:15 +08:00
|
|
|
|
|
2015-03-18 23:33:55 +08:00
|
|
|
|
if( -not $env:PSModulePath.Contains($CmderModulePath) ){
|
|
|
|
|
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-12 12:28:04 +08:00
|
|
|
|
try {
|
|
|
|
|
Get-command -Name "vim" -ErrorAction Stop >$null
|
|
|
|
|
} catch {
|
2015-11-24 08:10:22 +08:00
|
|
|
|
# # You could do this but it may be a little drastic and introduce a lot of
|
|
|
|
|
# # unix tool overlap with powershel unix like aliases
|
|
|
|
|
# $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\usr\bin")
|
|
|
|
|
# set-alias -name "vi" -value "vim"
|
|
|
|
|
# # I think the below is safer.
|
2016-01-12 05:09:23 +08:00
|
|
|
|
|
2015-11-25 00:58:58 +08:00
|
|
|
|
new-alias -name "vim" -value $($ENV:CMDER_ROOT + "\vendor\git-for-windows\usr\bin\vim.exe")
|
|
|
|
|
new-alias -name "vi" -value vim
|
2015-11-12 12:28:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 20:22:07 +08:00
|
|
|
|
try {
|
2015-05-19 22:47:06 +08:00
|
|
|
|
# Check if git is on PATH, i.e. Git already installed on system
|
2015-03-25 20:22:07 +08:00
|
|
|
|
Get-command -Name "git" -ErrorAction Stop >$null
|
2015-05-19 22:47:06 +08:00
|
|
|
|
} catch {
|
Added/enhanced bash with cmder.sh/user-cmder.sh, organized tasks menu
added personal files to .gitignore so they never get uploaded to the repo and added support for msys2 bash in the new git for windows
added autocreate of config/user-cmder.sh if iot does not exist and added it to the .gitignore
Added tasks: cmd::Cmder, cmd::Cmder as Admin, bash::bash, bash::bash as Admin, bash::mintty, bash::mintty as admin, powershell::powershell, powershell::powershell as Admin. Set default task to cmd::Cmder. Cot rid of init.bat running before /bin/bash, fixes double exit requirement
Added running git for windows post-install.bat on first cmder launch
fixed file/path not found errors when launching powershell as admin
fixed file/path not found errors when launching bash/mintty as admin
fixed PATH in vendor/cmder.sh
Added sourcing ~/.bashrc if it exists.
changed .gitignore to ignore anything with path of config/user-*
removed my personal files from .gitignore, left in config/user-*
Make sure $CMDER_ROOT does not have a trailing '/'
%CMDER_ROOT% does not have trailing '\'. allow user to specify a conemu.xml on the command line
Removed '\' from %CMDER_ROOT%
2015-11-09 11:25:42 +08:00
|
|
|
|
$env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin")
|
2015-05-19 22:47:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2015-03-25 20:22:07 +08:00
|
|
|
|
Import-Module -Name "posh-git" -ErrorAction Stop >$null
|
|
|
|
|
$gitStatus = $true
|
|
|
|
|
} catch {
|
2015-05-18 05:13:23 +08:00
|
|
|
|
Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder."
|
2015-03-25 20:22:07 +08:00
|
|
|
|
$gitStatus = $false
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 20:29:10 +08:00
|
|
|
|
function checkGit($Path) {
|
2016-02-10 21:42:12 +08:00
|
|
|
|
if (Test-Path -Path (Join-Path $Path '.git') ) {
|
2015-03-25 20:29:10 +08:00
|
|
|
|
Write-VcsStatus
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
$SplitPath = split-path $path
|
|
|
|
|
if ($SplitPath) {
|
|
|
|
|
checkGit($SplitPath)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 15:55:15 +08:00
|
|
|
|
# Set up a Cmder prompt, adding the git prompt parts inside git repos
|
|
|
|
|
function global:prompt {
|
|
|
|
|
$realLASTEXITCODE = $LASTEXITCODE
|
2014-09-17 21:07:34 +08:00
|
|
|
|
$Host.UI.RawUI.ForegroundColor = "White"
|
2015-03-18 23:47:01 +08:00
|
|
|
|
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
|
2015-03-25 20:22:07 +08:00
|
|
|
|
if($gitStatus){
|
2015-03-25 20:29:10 +08:00
|
|
|
|
checkGit($pwd.ProviderPath)
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
$global:LASTEXITCODE = $realLASTEXITCODE
|
2014-10-29 04:25:25 +08:00
|
|
|
|
Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"
|
|
|
|
|
return " "
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Load special features come from posh-git
|
2015-03-25 20:22:07 +08:00
|
|
|
|
if ($gitStatus) {
|
2014-09-17 15:55:15 +08:00
|
|
|
|
Start-SshAgent -Quiet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Move to the wanted location
|
2016-01-12 05:09:23 +08:00
|
|
|
|
# This is either a env variable set by the user or the result of
|
|
|
|
|
# cmder.exe setting this variable due to a commandline argument or a "cmder here"
|
|
|
|
|
if ( $ENV:CMDER_START ) {
|
|
|
|
|
Set-Location -Path "$ENV:CMDER_START"
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
2015-08-03 22:06:41 +08:00
|
|
|
|
|
|
|
|
|
# Enhance Path
|
2015-10-15 00:50:52 +08:00
|
|
|
|
$env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT"
|
|
|
|
|
|
2016-02-25 21:53:57 +08:00
|
|
|
|
# Drop *.ps1 files into "$ENV:CMDER_ROOT\config\profile.d"
|
2016-02-26 08:22:43 +08:00
|
|
|
|
# to source them at startup.
|
2016-02-25 21:53:57 +08:00
|
|
|
|
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) {
|
2016-03-03 07:52:12 +08:00
|
|
|
|
# write-host write-host Sourcing $x
|
2016-02-25 21:53:57 +08:00
|
|
|
|
. $x
|
|
|
|
|
}
|
2016-03-03 07:52:12 +08:00
|
|
|
|
popd
|
2016-02-25 21:53:57 +08:00
|
|
|
|
|
Added/enhanced bash with cmder.sh/user-cmder.sh, organized tasks menu
added personal files to .gitignore so they never get uploaded to the repo and added support for msys2 bash in the new git for windows
added autocreate of config/user-cmder.sh if iot does not exist and added it to the .gitignore
Added tasks: cmd::Cmder, cmd::Cmder as Admin, bash::bash, bash::bash as Admin, bash::mintty, bash::mintty as admin, powershell::powershell, powershell::powershell as Admin. Set default task to cmd::Cmder. Cot rid of init.bat running before /bin/bash, fixes double exit requirement
Added running git for windows post-install.bat on first cmder launch
fixed file/path not found errors when launching powershell as admin
fixed file/path not found errors when launching bash/mintty as admin
fixed PATH in vendor/cmder.sh
Added sourcing ~/.bashrc if it exists.
changed .gitignore to ignore anything with path of config/user-*
removed my personal files from .gitignore, left in config/user-*
Make sure $CMDER_ROOT does not have a trailing '/'
%CMDER_ROOT% does not have trailing '\'. allow user to specify a conemu.xml on the command line
Removed '\' from %CMDER_ROOT%
2015-11-09 11:25:42 +08:00
|
|
|
|
$CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user-profile.ps1"
|
2015-10-15 00:50:52 +08:00
|
|
|
|
if(Test-Path $CmderUserProfilePath) {
|
|
|
|
|
# Create this file and place your own command in there.
|
2015-10-15 17:47:32 +08:00
|
|
|
|
. "$CmderUserProfilePath"
|
2015-10-15 00:50:52 +08:00
|
|
|
|
} else {
|
|
|
|
|
Write-Host "Creating user startup file: $CmderUserProfilePath"
|
|
|
|
|
"# Use this file to run your own startup commands" | Out-File $CmderUserProfilePath
|
2015-11-12 12:28:04 +08:00
|
|
|
|
}
|