Skip to content

Commit

Permalink
fix: oh-my-posh setup
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonos committed Nov 5, 2024
1 parent d4ab871 commit 8fbee27
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .assets/config/pwsh_cfg/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Remove-Variable path
#endregion

#region prompt
if (-not $isWSL1 -and (Test-Path '/usr/bin/oh-my-posh')) {
oh-my-posh --init --shell pwsh --config "$(Resolve-Path $env:OMP_PATH/theme.omp.json -ErrorAction Stop)" | Invoke-Expression | Out-Null
if (-not $isWSL1 -and (Test-Path /usr/bin/oh-my-posh -PathType Leaf) -and (Test-Path "$env:OMP_PATH/theme.omp.json" -PathType Leaf)) {
oh-my-posh init pwsh --config "$env:OMP_PATH/theme.omp.json" | Invoke-Expression | Out-Null
# disable venv prompt as it is handled in oh-my-posh theme
[Environment]::SetEnvironmentVariable('VIRTUAL_ENV_DISABLE_PROMPT', $true)
} else {
Expand Down
1 change: 0 additions & 1 deletion .assets/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ RUN \
# install and setup oh-my-posh theme
&& mkdir -p /usr/local/share/oh-my-posh \
&& install -m 0644 /tmp/cfg/base.omp.json /usr/local/share/oh-my-posh/theme.omp.json \
&& oh-my-posh disable notice \
# cleanup
&& apt-get autoremove -y \
&& apt-get clean -y \
Expand Down
11 changes: 7 additions & 4 deletions .assets/provision/setup_profile_allusers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,24 @@ fi

# *bash profile
# add common bash aliases
grep -qw 'd/aliases.sh' ~/.bashrc 2>/dev/null || cat <<EOF >>~/.bashrc
grep -qw 'd/aliases.sh' $HOME/.bashrc 2>/dev/null || cat <<EOF >>$HOME/.bashrc
# common aliases
if [ -f "$PROFILE_PATH/aliases.sh" ]; then
source "$PROFILE_PATH/aliases.sh"
fi
EOF

# add oh-my-posh invocation
if ! grep -qw 'oh-my-posh' ~/.bashrc 2>/dev/null && type oh-my-posh &>/dev/null; then
cat <<EOF >>~/.bashrc
if ! grep -qw 'oh-my-posh' $HOME/.bashrc 2>/dev/null && type oh-my-posh &>/dev/null; then
cat <<EOF >>$HOME/.bashrc
# initialize oh-my-posh prompt
if [ -f "$OMP_PATH/theme.omp.json" ] && type oh-my-posh &>/dev/null; then
eval "\$(oh-my-posh --init --shell bash --config "$OMP_PATH/theme.omp.json")"
eval "\$(oh-my-posh init bash --config "$OMP_PATH/theme.omp.json")"
fi
EOF
elif grep -qw 'oh-my-posh --init' $HOME/.bashrc 2>/dev/null; then
# convert oh-my-posh initialization to the new API
sed -i 's/oh-my-posh --init --shell bash/oh-my-posh init bash/' $HOME/.bashrc &>/dev/null
fi

# make path autocompletion case insensitive
Expand Down
4 changes: 0 additions & 4 deletions .assets/provision/setup_profile_user.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ if (Get-Module -Name Microsoft.PowerShell.PSResourceGet -ListAvailable) {
.assets/provision/update_psresources.ps1
}
}
# disable oh-my-posh update notice
if (Get-Command oh-my-posh -CommandType Application) {
oh-my-posh disable notice | Out-Null
}
# install PSReadLine
for ($i = 0; ((Get-Module PSReadLine -ListAvailable).Count -eq 1) -and $i -lt 5; $i++) {
Write-Host 'installing PSReadLine...'
Expand Down
23 changes: 13 additions & 10 deletions .assets/provision/setup_profile_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ PROFILE_PATH='/etc/profile.d'
OMP_PATH='/usr/local/share/oh-my-posh'

# add common bash aliases
grep -qw 'd/aliases.sh' ~/.bashrc 2>/dev/null || cat <<EOF >>~/.bashrc
grep -qw 'd/aliases.sh' $HOME/.bashrc 2>/dev/null || cat <<EOF >>$HOME/.bashrc
# common aliases
if [ -f "$PROFILE_PATH/aliases.sh" ]; then
source "$PROFILE_PATH/aliases.sh"
fi
EOF

# add git aliases
if ! grep -qw 'd/aliases_git.sh' ~/.bashrc 2>/dev/null && type git &>/dev/null; then
cat <<EOF >>~/.bashrc
if ! grep -qw 'd/aliases_git.sh' $HOME/.bashrc 2>/dev/null && type git &>/dev/null; then
cat <<EOF >>$HOME/.bashrc
# git aliases
if [ -f "$PROFILE_PATH/aliases_git.sh" ] && type git &>/dev/null; then
source "$PROFILE_PATH/aliases_git.sh"
Expand All @@ -25,16 +25,16 @@ EOF
fi

# add custom functions
grep -qw 'd/functions.sh' ~/.bashrc 2>/dev/null || cat <<EOF >>~/.bashrc
grep -qw 'd/functions.sh' $HOME/.bashrc 2>/dev/null || cat <<EOF >>$HOME/.bashrc
# custom functions
if [ -f "$PROFILE_PATH/functions.sh" ]; then
source "$PROFILE_PATH/functions.sh"
fi
EOF

# add kubectl autocompletion and aliases
if ! grep -qw 'kubectl' ~/.bashrc 2>/dev/null && type -f kubectl &>/dev/null; then
cat <<EOF >>~/.bashrc
if ! grep -qw 'kubectl' $HOME/.bashrc 2>/dev/null && type -f kubectl &>/dev/null; then
cat <<EOF >>$HOME/.bashrc
# kubectl autocompletion and aliases
if type -f kubectl &>/dev/null; then
source <(kubectl completion bash)
Expand All @@ -51,16 +51,19 @@ EOF
fi

# add conda initialization
if ! grep -qw '__conda_setup' ~/.bashrc 2>/dev/null && [ -f $HOME/miniconda3/bin/conda ]; then
if ! grep -qw '__conda_setup' $HOME/.bashrc 2>/dev/null && [ -f $HOME/miniconda3/bin/conda ]; then
$HOME/miniconda3/bin/conda init bash >/dev/null
fi

# add oh-my-posh invocation
if ! grep -qw 'oh-my-posh' ~/.bashrc 2>/dev/null && type oh-my-posh &>/dev/null; then
cat <<EOF >>~/.bashrc
if ! grep -qw 'oh-my-posh' $HOME/.bashrc 2>/dev/null && type oh-my-posh &>/dev/null; then
cat <<EOF >>$HOME/.bashrc
# initialize oh-my-posh prompt
if [ -f "$OMP_PATH/theme.omp.json" ] && type oh-my-posh &>/dev/null; then
eval "\$(oh-my-posh --init --shell bash --config "$OMP_PATH/theme.omp.json")"
eval "\$(oh-my-posh init bash --config "$OMP_PATH/theme.omp.json")"
fi
EOF
elif grep -qw 'oh-my-posh --init' $HOME/.bashrc 2>/dev/null; then
# convert oh-my-posh initialization to the new API
sed -i 's/oh-my-posh --init --shell bash/oh-my-posh init bash/' $HOME/.bashrc
fi
23 changes: 13 additions & 10 deletions .assets/provision/setup_profile_user_zsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ -d $HOME/.zsh/zsh-autocomplete ]; then
else
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $HOME/.zsh/zsh-autocomplete
fi
if ! grep -w 'zsh-autocomplete.plugin.zsh' ~/.zshrc 2>/dev/null; then
if ! grep -w 'zsh-autocomplete.plugin.zsh' $HOME/.zshrc 2>/dev/null; then
cat <<'EOF' >>$HOME/.zshrc
# *plugins
source $HOME/.zsh/zsh-autocomplete/zsh-autocomplete.plugin.zsh
Expand All @@ -27,7 +27,7 @@ if [ -d $HOME/.zsh/zsh-autosuggestions ]; then
else
git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.zsh/zsh-autosuggestions
fi
if ! grep -w 'zsh-autosuggestions.zsh' ~/.zshrc 2>/dev/null; then
if ! grep -w 'zsh-autosuggestions.zsh' $HOME/.zshrc 2>/dev/null; then
echo 'source $HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >>$HOME/.zshrc
fi
# ~zsh-syntax-highlighting
Expand All @@ -37,7 +37,7 @@ if [ -d $HOME/.zsh/zsh-syntax-highlighting ]; then
else
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.zsh/zsh-syntax-highlighting
fi
if ! grep -w 'zsh-syntax-highlighting.zsh' ~/.zshrc 2>/dev/null; then
if ! grep -w 'zsh-syntax-highlighting.zsh' $HOME/.zshrc 2>/dev/null; then
echo 'source $HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >>$HOME/.zshrc
fi
if ! grep -q '^bindkey .* autosuggest-accept' $HOME/.zshrc; then
Expand All @@ -46,15 +46,15 @@ fi

# *aliases
# add common zsh aliases
grep -qw 'd/aliases.sh' ~/.zshrc 2>/dev/null || cat <<EOF >>$HOME/.zshrc
grep -qw 'd/aliases.sh' $HOME/.zshrc 2>/dev/null || cat <<EOF >>$HOME/.zshrc
# *aliases
if [ -f "$PROFILE_PATH/aliases.sh" ]; then
source "$PROFILE_PATH/aliases.sh"
fi
EOF

# add git aliases
if ! grep -qw 'd/aliases_git.sh' ~/.zshrc 2>/dev/null && type git &>/dev/null; then
if ! grep -qw 'd/aliases_git.sh' $HOME/.zshrc 2>/dev/null && type git &>/dev/null; then
cat <<EOF >>$HOME/.zshrc
# git aliases
if [ -f "$PROFILE_PATH/aliases_git.sh" ] && type git &>/dev/null; then
Expand All @@ -64,7 +64,7 @@ EOF
fi

# add kubectl autocompletion and aliases
if ! grep -qw 'kubectl' ~/.zshrc 2>/dev/null && type -f kubectl &>/dev/null; then
if ! grep -qw 'kubectl' $HOME/.zshrc 2>/dev/null && type -f kubectl &>/dev/null; then
cat <<EOF >>$HOME/.zshrc
# kubectl autocompletion and aliases
if type -f kubectl &>/dev/null; then
Expand All @@ -76,16 +76,19 @@ EOF
fi

# *add conda initialization
if ! grep -qw '__conda_setup' ~/.zshrc 2>/dev/null && [ -f $HOME/miniconda3/bin/conda ]; then
if ! grep -qw '__conda_setup' $HOME/.zshrc 2>/dev/null && [ -f $HOME/miniconda3/bin/conda ]; then
$HOME/miniconda3/bin/conda init zsh >/dev/null
fi

# *add oh-my-posh invocation
if ! grep -qw 'oh-my-posh' ~/.zshrc 2>/dev/null && type oh-my-posh &>/dev/null; then
cat <<EOF >>~/.zshrc
if ! grep -qw 'oh-my-posh' $HOME/.zshrc 2>/dev/null && type oh-my-posh &>/dev/null; then
cat <<EOF >>$HOME/.zshrc
# initialize oh-my-posh prompt
if [ -f "$OMP_PATH/theme.omp.json" ] && type oh-my-posh &>/dev/null; then
eval "\$(oh-my-posh --init --shell zsh --config "$OMP_PATH/theme.omp.json")"
eval "\$(oh-my-posh init zsh --config "$OMP_PATH/theme.omp.json")"
fi
EOF
elif grep -qw 'oh-my-posh --init' $HOME/.zshrc 2>/dev/null; then
# convert oh-my-posh initialization to the new API
sed -i 's/oh-my-posh --init --shell zsh/oh-my-posh init zsh/' $HOME/.zshrc
fi

0 comments on commit 8fbee27

Please sign in to comment.