feat(shell): add rust + starship setup

This commit is contained in:
Marc 2024-02-16 01:18:37 -05:00
parent 28581fd055
commit 548a03b724
Signed by: marc
GPG key ID: 048E042F22B5DC79
3 changed files with 124 additions and 2 deletions

View file

@ -3,14 +3,19 @@
# Ensuring steps are defined.
. ./steps.sh
TOTAL_STEPS=6
TOTAL_STEPS=8
# Refer to steps.sh for step definition.
bootstrap() {
ensure_apt_up_to_date
ensure_apt_dependencies
ensure_omz
install_rust
ensure_nvm
# Shell & prompt setup
ensure_omz
install_and_configure_starship
inject_shell_configuration
inject_vim_configuration
}

73
files/starship.toml Normal file
View file

@ -0,0 +1,73 @@
format = """
[](#9A348E)\
$username\
$os\
[](bg:#33658a fg:#9A348E)\
$time\
[](bg:#DA627D fg:#33658a)\
$directory\
[](fg:#DA627D bg:#3208e0)\
$git_branch\
$git_status\
[](fg:#4208e0 bg:#9A348E)\
$python\
[](fg:#9A348E)
>
"""
# Disable the blank line at the start of the prompt
add_newline = true
[python]
style = "bg:#9A348E"
format = '[${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'
# You can also replace your username with a neat symbol like  or disable this
# and use the os module below
[username]
show_always = true
style_user = "bg:#9A348E"
style_root = "bg:#9A348E"
format = '[$user ]($style)'
disabled = false
# An alternative to the username module which displays a symbol that
# represents the current operating system
[os]
style = "bg:#9A348E"
disabled = true # Disabled by default
[directory]
style = "bg:#DA627D"
format = "[ $path ]($style)"
truncation_length = 3
truncation_symbol = "…/"
# Here is how you can shorten some long paths by text replacement
# similar to mapped_locations in Oh My Posh:
[directory.substitutions]
"Documents" = "󰈙 "
"Downloads" = " "
"Music" = " "
"Pictures" = " "
# Keep in mind that the order matters. For example:
# "Important Documents" = " 󰈙 "
# will not be replaced, because "Documents" was already substituted before.
# So either put "Important Documents" before "Documents" or use the substituted version:
# "Important 󰈙 " = " 󰈙 "
[git_branch]
symbol = ""
style = "bg:#4208e0"
format = '[ $symbol $branch ]($style)'
[git_status]
style = "bg:#4208e0"
format = '[$all_status$ahead_behind ]($style)'
[time]
time_format = "%T"
style = "bg:#33658A"
format = '[ $time ]($style)'
disabled = false

View file

@ -1,13 +1,20 @@
#!/bin/bash
STEP_COUNT=0
SUBSTEP_COUNT=0
# Helpers to pretty-print step titles and count.
pre_step() {
STEP_COUNT=$(($STEP_COUNT + 1))
SUBSTEP_COUNT=0
echo -e "\e[1m[$STEP_COUNT/$TOTAL_STEPS] <====== $1 =======>\e[0m"
}
pre_substep() {
SUBSTEP_COUNT=$(($SUBSTEP_COUNT + 1))
echo -e "\e[1m[$STEP_COUNT.$SUBSTEP_COUNT] <====== $1 =======>\e[0m"
}
# Ensures that all existing Apt packages are up-to-date.
ensure_apt_up_to_date() {
pre_step "Ensuring apt packages are up-to-date"
@ -38,11 +45,48 @@ ensure_apt_dependencies() {
fi
}
# Installs the rustup toolchain if not installed.
# If installed, the toolchain is updated.
install_rust() {
pre_step "Install and configure Rust toolchain"
if [ -z "$(rustup --version 2> /dev/null)" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
else
rustup update
fi
}
ensure_omz() {
pre_step "Installs Oh My ZSH"
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash
}
# Installs the Starship prompt and adds an initialization
# command to the shell configuration file.
#
# Requires: install_rust
install_and_configure_starship() {
pre_step "Install and configure Starship"
pre_substep "Install Starship via cargo"
cargo install starship --locked
pre_substep "Add initialization command to shell configuration"
STARSHIP_INIT_COMMAND='eval "$(starship init zsh)"'
if [ -z "$(rg "starship init zsh" ~/.zshrc)" ]; then
echo "#Initialize Starship prompt\n$STARSHIP_INIT_COMMAND" >> ~/.zshrc
fi
pre_substep "Copy configuration in configuration directory"
STARSHIP_CONFIGURATION_PATH=~/.config/starship.toml
if [ -f $STARSHIP_CONFIGURATION_PATH ]; then
cp $STARSHIP_CONFIGURATION_PATH $STARSHIP_CONFIGURATION_PATH.old
fi
cp ./files/starship.toml $STARSHIP_CONFIGURATION_PATH
}
ensure_nvm() {
pre_step "Installing nvm to manage node version"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash