Skip to content
Merged

dev #228

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .assets/provision/install_nodejs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ debian | ubuntu)
URL="https://deb.nodesource.com/setup_lts.x"
# download and install homebrew
if download_file --uri "$URL" --target_dir "$TMP_DIR"; then
chmod +x "$TMP_DIR/setup_lts.x"
bash -c "$TMP_DIR/setup_lts.x"
fi
# install nodejs
apt-get update && apt-get install -y $APP npm
apt-get update && apt-get install -y $APP
;;
opensuse)
zypper --non-interactive in -y $APP npm
Expand Down
83 changes: 60 additions & 23 deletions .assets/provision/setup_profile_user.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@ for ($i = 0; ((Get-Module PSReadLine -ListAvailable).Count -eq 1) -and $i -lt 5;
Install-PSResource -Name PSReadLine
}

# install kubectl autocompletion
if (Test-Path /usr/bin/kubectl -PathType Leaf) {
$kubectlSet = try { Select-String 'kubecolor' -Path $PROFILE.CurrentUserCurrentHost -SimpleMatch -Quiet } catch { $false }
if (-not $kubectlSet) {
Write-Host 'adding kubectl auto-completion...'
# build completer text
$completer = [string]::Join("`n",
(/usr/bin/kubectl completion powershell) -join "`n",
"`n# setup autocompletion for the 'k' alias",
'Set-Alias -Name k -Value kubectl',
"Register-ArgumentCompleter -CommandName 'k' -ScriptBlock `${__kubectlCompleterBlock}",
"`n# setup autocompletion for the 'kubecolor' binary",
'if (Test-Path /usr/bin/kubecolor -PathType Leaf) {',
' Set-Alias -Name kubectl -Value kubecolor',
" Register-ArgumentCompleter -CommandName 'kubecolor' -ScriptBlock `${__kubectlCompleterBlock}",
'}'
)
# add additional ArgumentCompleter at the end of the profile
[System.IO.File]::WriteAllText($PROFILE, "$($completer.Trim())`n")
}
}

<# TODO uncomment once copilot-cli is added to the automation
# add gh copilot aliases
if (Test-Path /usr/bin/gh) {
Expand All @@ -71,7 +49,49 @@ if (Test-Path /usr/bin/gh) {
}
#>

#region $PROFILE.CurrentUserAllHosts,
#region $PROFILE.CurrentUserCurrentHost
# load existing profile
$profileContent = [System.Collections.Generic.List[string]]::new()
if (Test-Path $PROFILE.CurrentUserCurrentHost -PathType Leaf) {
$profileContent.AddRange([System.IO.File]::ReadAllLines($PROFILE.CurrentUserCurrentHost))
}
# track if profile is modified
$isProfileModified = $false

# install kubectl autocompletion
if (Test-Path /usr/bin/kubectl -PathType Leaf) {
if (-not ($profileContent | Select-String '__kubectlCompleterBlock' -SimpleMatch -Quiet)) {
Write-Host 'adding kubectl auto-completion...'
# build completer text
$profileContent.AddRange(
[string[]]@(
"`n#region kubectl completer"
(/usr/bin/kubectl completion powershell) -join "`n"
"`n# setup autocompletion for the 'k' alias"
'Set-Alias -Name k -Value kubectl'
"Register-ArgumentCompleter -CommandName 'k' -ScriptBlock `${__kubectlCompleterBlock}"
"`n# setup autocompletion for the 'kubecolor' binary"
'if (Test-Path /usr/bin/kubecolor -PathType Leaf) {'
' Set-Alias -Name kubectl -Value kubecolor'
" Register-ArgumentCompleter -CommandName 'kubecolor' -ScriptBlock `${__kubectlCompleterBlock}"
'}'
'#endregion'
)
)
$isProfileModified = $true
}
}

# save profile if modified
if ($isProfileModified) {
[System.IO.File]::WriteAllText(
$PROFILE.CurrentUserCurrentHost,
"$(($profileContent -join "`n").Trim())`n"
)
}
#endregion

#region $PROFILE.CurrentUserAllHosts
# load existing profile
$profileContent = [System.Collections.Generic.List[string]]::new()
if (Test-Path $PROFILE.CurrentUserAllHosts -PathType Leaf) {
Expand Down Expand Up @@ -134,6 +154,23 @@ if (Test-Path "$HOME/$uvCli" -PathType Leaf) {
}
}

# set up make completer
$completerFunction = 'Register-MakeCompleter'
if (Get-Command $completerFunction -Module 'do-linux' -CommandType Function -ErrorAction SilentlyContinue) {
if (-not ($profileContent | Select-String $completerFunction -SimpleMatch -Quiet)) {
Write-Host 'adding make auto-completion...'
$profileContent.AddRange(
[string[]]@(
"`n#region make completer"
'Set-Alias -Name m -Value make'
$completerFunction
'#endregion'
)
)
$isProfileModified = $true
}
}

# set up pixi
$pixiCli = '.pixi/bin/pixi'
if (Test-Path "$HOME/$pixiCli" -PathType Leaf) {
Expand Down
9 changes: 9 additions & 0 deletions .assets/provision/setup_profile_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ fi
EOF
fi

# *set Makefile completer
if ! grep -qw "Makefile" $HOME/.bashrc 2>/dev/null; then
cat <<'EOF' >>$HOME/.bashrc

# initialize make autocompletion
complete -W "\`if [ -f Makefile ]; then grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' Makefile | sed 's/[^a-zA-Z0-9_-]*$//'; elif [ -f makefile ]; then grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' makefile | sed 's/[^a-zA-Z0-9_-]*$//'; fi \`" make
EOF
fi

# *set up pixi
COMPLETION_CMD='pixi completion --shell bash'
PIXI_PATH=".pixi/bin"
Expand Down
136 changes: 136 additions & 0 deletions .assets/provision/setup_profile_user.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env zsh
: '
.assets/provision/setup_profile_user.zsh
'
# path variables
PROFILE_PATH='/etc/profile.d'
OMP_PATH='/usr/local/share/oh-my-posh'

# *install plugins
# ~zsh-autocomplete
# https://github.com/marlonrichert/zsh-autocomplete
zsh_plugin='zsh-autocomplete'
if [ -d "$HOME/.zsh/$zsh_plugin" ]; then
git -C "$HOME/.zsh/$zsh_plugin" pull --quiet
else
git clone https://github.com/marlonrichert/$zsh_plugin.git "$HOME/.zsh/$zsh_plugin"
fi
if ! grep -w "$zsh_plugin.plugin.zsh" "$HOME/.zshrc" 2>/dev/null; then
cat <<EOF >>"$HOME/.zshrc"
# *plugins
source "\$HOME/.zsh/$zsh_plugin/$zsh_plugin.plugin.zsh"
EOF
fi
# ~zsh-make-complete
# https://github.com/22peacemaker/zsh-make-complete
zsh_plugin='zsh-make-complete'
if [ -d "$HOME/.zsh/$zsh_plugin" ]; then
git -C "$HOME/.zsh/$zsh_plugin" pull --quiet
else
git clone https://github.com/22peacemaker/$zsh_plugin.git "$HOME/.zsh/$zsh_plugin"
fi
if ! grep -Fqw "$zsh_plugin.plugin.zsh" "$HOME/.zshrc" 2>/dev/null; then
echo "source \"\$HOME/.zsh/$zsh_plugin/$zsh_plugin.plugin.zsh\"" >>"$HOME/.zshrc"
fi
# ~zsh-autosuggestions
# https://github.com/zsh-users/zsh-autosuggestions
zsh_plugin='zsh-autosuggestions'
if [ -d "$HOME/.zsh/$zsh_plugin" ]; then
git -C "$HOME/.zsh/$zsh_plugin" pull --quiet
else
git clone https://github.com/zsh-users/$zsh_plugin.git "$HOME/.zsh/$zsh_plugin"
fi
if ! grep -w '$zsh_plugin.zsh' "$HOME/.zshrc" 2>/dev/null; then
echo "source \"\$HOME/.zsh/$zsh_plugin/$zsh_plugin.zsh\"" >>"$HOME/.zshrc"
fi
# ~zsh-syntax-highlighting
# https://github.com/zsh-users/zsh-syntax-highlighting
zsh_plugin='zsh-syntax-highlighting'
if [ -d "$HOME/.zsh/$zsh_plugin" ]; then
git -C "$HOME/.zsh/$zsh_plugin" pull --quiet
else
git clone https://github.com/zsh-users/$zsh_plugin.git "$HOME/.zsh/$zsh_plugin"
fi
if ! grep -w "$zsh_plugin.zsh" "$HOME/.zshrc" 2>/dev/null; then
echo "source \"\$HOME/.zsh/$zsh_plugin/$zsh_plugin.zsh\"" >>"$HOME/.zshrc"
fi
if ! grep -q '^bindkey .* autosuggest-accept' "$HOME/.zshrc"; then
echo "bindkey '^ ' autosuggest-accept\n" >>"$HOME/.zshrc"
fi

# *aliases
# add common zsh aliases
grep -qw 'd/aliases.sh' "$HOME/.zshrc" 2>/dev/null || cat <<EOF >>"$HOME/.zshrc"
# 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' "$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
source "$PROFILE_PATH/aliases_git.sh"
fi
EOF
fi

# add kubectl autocompletion and aliases
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
if [ -f "$PROFILE_PATH/aliases_kubectl.sh" ]; then
source "$PROFILE_PATH/aliases_kubectl.sh"
fi
fi
EOF
fi

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

# *set up uv
COMPLETION_CMD='uv generate-shell-completion zsh'
UV_PATH=".local/bin"
if ! grep -qw "$COMPLETION_CMD" "$HOME/.zshrc" 2>/dev/null && [ -x "$HOME/$UV_PATH/uv" ]; then
cat <<EOF >>"$HOME/.zshrc"

# initialize uv autocompletion
if [ -x "\$HOME/$UV_PATH/uv" ]; then
export UV_NATIVE_TLS=true
eval "\$(\$HOME/$UV_PATH/$COMPLETION_CMD)"
fi
EOF
fi

# *set up pixi
COMPLETION_CMD='pixi completion --shell zsh'
PIXI_PATH=".pixi/bin"
if ! grep -qw "$COMPLETION_CMD" "$HOME/.zshrc" 2>/dev/null && [ -x "$HOME/$PIXI_PATH/pixi" ]; then
cat <<EOF >>"$HOME/.zshrc"

# initialize pixi autocompletion
if [ -x "\$HOME/$PIXI_PATH/pixi" ]; then
autoload -Uz compinit && compinit
eval "\$(\$HOME/$PIXI_PATH/$COMPLETION_CMD)"
fi
EOF
fi

# *add oh-my-posh invocation
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 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
122 changes: 0 additions & 122 deletions .assets/provision/setup_profile_user_zsh.zsh

This file was deleted.

Loading