Skip to content

Commit 1b4397c

Browse files
authored
Codespace prompt (#16)
* Multi-line codespace prompt * Install Terraform via apt-get * Remove PS modules not used
1 parent 32010bc commit 1b4397c

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

common/bootstrap_pwsh.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ $functionsDirectory = Join-Path $scriptDirectory functions
1313
if (-not $NoPackages) {
1414
# Check whether Az modules have been installed
1515
AddorUpdateModule -ModuleName Az -AllowClobber
16-
#AddorUpdateModule AzureADPreview
1716
#AddorUpdateModule MicrosoftPowerBIMgmt
1817
#AddorUpdateModule MicrosoftTeams
1918
AddorUpdateModule Oh-My-Posh
2019
AddorUpdateModule Posh-Git
21-
# https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-72?view=powershell-7.2#separating-dsc-from-powershell-7-to-enable-future-improvements
22-
if ($PSVerSionTable.PSVersion -ge 7.2) {
23-
# The PSDesiredStateConfiguration module was removed from the PowerShell 7.2 package and is now published to the PowerShell Gallery
24-
AddorUpdateModule PSDesiredStateConfiguration
25-
}
20+
# # https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-72?view=powershell-7.2#separating-dsc-from-powershell-7-to-enable-future-improvements
21+
# if ($PSVerSionTable.PSVersion -ge 7.2) {
22+
# # The PSDesiredStateConfiguration module was removed from the PowerShell 7.2 package and is now published to the PowerShell Gallery
23+
# AddorUpdateModule PSDesiredStateConfiguration
24+
# }
2625
AddorUpdateModule PSReadLine
2726
# https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-72?view=powershell-7.2#psreadline-21-predictive-intellisense
2827
$psReadLineOptionCommand = (Get-Command Set-PSReadLineOption -ErrorAction SilentlyContinue)
@@ -31,7 +30,7 @@ if (-not $NoPackages) {
3130
}
3231
AddorUpdateModule SqlServer
3332
AddorUpdateModule Terminal-Icons
34-
AddorUpdateModule VSTeam
33+
# AddorUpdateModule VSTeam
3534
if ($IsWindows) {
3635
AddorUpdateModule WindowsCompatibility
3736
}

common/profile.ps1

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#!/usr/bin/env pwsh
22

3-
# Define Functions
4-
Write-Verbose "Defining functions..."
5-
$functionsPath = (Join-Path (Split-Path $MyInvocation.MyCommand.Path –Parent) "functions")
6-
Get-ChildItem $functionsPath -filter "*.ps1" | ForEach-Object {
7-
Write-Host "$($_.FullName) : loaded"
8-
. $_.FullName
9-
}
10-
113
# Define prompt
124
Write-Verbose "Defining prompt..."
135
function global:Prompt {
@@ -17,11 +9,15 @@ function global:Prompt {
179
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
1810
# Don't overwrite the title set in iTerm2/Windows Terminal
1911
$GitPromptSettings.WindowTitle = $null
12+
if ($env:CODESPACES -ieq "true") {
13+
$GitPromptSettings.DefaultPromptPrefix = "[${env:GITHUB_USER}@${env:CODESPACE_NAME}]: "
14+
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
15+
}
2016
if (IsElevated) {
2117
$GitPromptSettings.DefaultPromptSuffix = "`$('#' * (`$nestedPromptLevel + 1)) "
2218
} else {
2319
$GitPromptSettings.DefaultPromptSuffix = "`$('>' * (`$nestedPromptLevel + 1)) "
24-
}
20+
}
2521
$prompt = (& $GitPromptScriptBlock)
2622
} else {
2723
$host.ui.rawui.WindowTitle = "PowerShell Core $($host.Version.ToString())"
@@ -50,7 +46,17 @@ function global:Prompt {
5046
}
5147

5248
# Only print when not in a nested shell, tmux session, or Codespace
53-
$printMessages = (($nestedPromptLevel -eq 0) -and $($env:TERM -notmatch "^screen") -and $($env:TERM -notmatch "^tmux") -and (!($env:CLOUDENV_ENVIRONMENT_ID)))
49+
$printMessages = (($nestedPromptLevel -eq 0) -and $($env:TERM -notmatch "^screen") -and $($env:TERM -notmatch "^tmux") -and (!($env:CODESPACES -ieq "true")))
50+
51+
# Define Functions
52+
Write-Verbose "Defining functions..."
53+
$functionsPath = (Join-Path (Split-Path $MyInvocation.MyCommand.Path –Parent) "functions")
54+
Get-ChildItem $functionsPath -filter "*.ps1" | ForEach-Object {
55+
if ($printMessages) {
56+
Write-Host "$($_.FullName) : loaded"
57+
}
58+
. $_.FullName
59+
}
5460

5561
if ($host.Name -eq 'ConsoleHost')
5662
{

linux/apt-packages.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ msodbcsql17
2828
mssql-tools
2929
nano
3030
node-typescript
31+
packer
3132
powershell
3233
sed
3334
snapd
3435
telnet
36+
terraform
3537
tmux
3638
traceroute
3739
tree

linux/bootstrap_linux2.sh

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ else
6464
echo $'\napt-get not found, skipping packages'
6565
else
6666
# pre-requisites
67-
$SUDO apt-get install -y apt-transport-https curl software-properties-common
67+
$SUDO apt-get install -y apt-transport-https curl gnupg software-properties-common
6868

6969
# Kubernetes requirement
7070
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | $SUDO apt-key add -
@@ -87,6 +87,10 @@ EOF
8787
# For Ubuntu, this PPA provides the latest stable upstream Git version
8888
$SUDO add-apt-repository ppa:git-core/ppa -y
8989

90+
# Hashicorp
91+
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
92+
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
93+
9094
# Microsoft dependencies
9195
# Source: https://github.com/Azure/azure-functions-core-tools
9296
curl -s https://packages.microsoft.com/keys/microsoft.asc | $SUDO apt-key add -
@@ -108,6 +112,7 @@ EOF
108112
$SUDO dpkg -i packages-microsoft-prod.deb
109113
fi
110114

115+
111116
echo $'\nUpdating package list...'
112117
$SUDO apt-get update
113118

@@ -137,19 +142,4 @@ if test ! $(which pwsh); then
137142
else
138143
echo $'\nSetting up PowerShell Core...'
139144
pwsh -nop -file $SCRIPT_PATH/../common/common_setup.ps1 $COMMON_SETUP_ARGS
140-
fi
141-
142-
# Set up terraform with tfenv
143-
if test $(which unzip); then
144-
if [ ! -d $HOME/.tfenv ]; then
145-
echo $'\nInstalling tfenv...'
146-
git clone -q https://github.com/tfutils/tfenv.git $HOME/.tfenv
147-
else
148-
echo $'\nUpdating tfenv...'
149-
git -C $HOME/.tfenv pull
150-
fi
151-
TFENV_CURL_OUTPUT=0
152-
$HOME/.tfenv/bin/tfenv install latest #2>&1
153-
else
154-
echo $'\nunzip not found, skipping tfenv set up'
155-
fi
145+
fi

0 commit comments

Comments
 (0)