Starship: Default prompt as root user

Created on 21 Mar 2020  ·  3Comments  ·  Source: starship/starship

Current Behavior

Right now, whenever I sudo -s in order to login as the root user in my shell, the zsh theme goes back to the default (in my case arch#).
Is this behaviour usual, and either way, what could I do to fix it?
I noticed that there's a Username module in the documentation which should default to appear when with root privileges, but it doesnt't show up.
In order to fix it I, with no hopes for it to work, created a symbolic link in the /root/ directory with my .zshrc, but this doesn't seem to work.
How could I solve this?

Environment

  • Starship version: 0.37.0
  • zsh version: zsh 5.8 (x86_64-pc-linux-gnu)
  • Operating system: Arch Linux
  • Terminal emulator: Kitty

Relevant Shell Configuration

#              __
#  ____  _____/ /_  __________
# /_  / / ___/ __ \/ ___/ ___/
#  / /_(__  ) / / / /  / /__
# /___/____/_/ /_/_/   \___/    t0maslb@github

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.

# scripts
export PATH=$PATH:"$(printf "%s:" ${HOME}/.local/bin/*)"
# encoding
export LANG=en_GB.UTF-8
export LC_ALL=es_ES.UTF-8
# code & langs
export CODE_DIR=$HOME/code
export CODE_RSC=$CODE_DIR/resources
export CODE_PRJ=$CODE_DIR/projects
# rust
export RUSTUP_HOME=$HOME/code/resources/rustup
export CARGO_HOME=$HOME/code/resources/cargo
export PATH=$PATH:$CARGO_HOME/bin
# go
export GOPATH=$CODE_PRJ/go
export PATH=$PATH:$GOPATH/bin
#export GOROOT=/usr/lib/go
export GOBIN=$GOROOT/bin
# zsh: plugins and themes
export STARSHIP_CONFIG=/home/tomas/.config/starship/starship.toml

source $HOME/.local/bin/zsh_plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh


eval "$(starship init zsh)"
eval "$(thefuck --alias)"

alias getvid="youtube-dl --restrict-filenames -f 22"
alias getaudio="youtube-dl --restrict-filenames -x --audio-format mp3"
alias dmi="doas make install"
alias dmci="doas make clean install"
alias drc="sudo make install & pkill dwm"
alias rcst="rm config.h & make & sudo make install"
alias ls="ls --color=auto"
alias l="ls -la"
alias v="vim"

# KEYBINDINGS
bindkey  "^[[H"   beginning-of-line
bindkey  "^[[F"   end-of-line
bindkey "\e[3~" delete-char

/opt/shell-color-scripts/crunchbang-mini

Starship Configuration

add_newline = true

[character]
symbol = ""
error_symbol = "✖"
vicmd_symbol = ""

[git_status]
staged.value = "++"
staged_count.enabled = true
deleted = "🗑"

[haskell]
symbol = " "

[package]
disabled = false

[time]
disabled = false
format = "[%H:%m]"

🐛 bug

Most helpful comment

Alright, thank you, I figured it out. Turns out I've spent all of my time running Linux without knowing about the existence of the /root direcotry. As soon as I made a .zshrc in that dir, and included eval "$(starship init zsh)" in it, as I'd do in my users home directory, everything ran fine.

All 3 comments

Is starship installed in ~/.local/bin? If so, the line export PATH=$PATH:"$(printf "%s:" ${HOME}/.local/bin/*)" won't work, because $HOME refers to the home of the root user.

Can you run eval "$(starship init zsh)" as root and have the prompt appear? If not, you need to fix that first.

Alright, thank you, I figured it out. Turns out I've spent all of my time running Linux without knowing about the existence of the /root direcotry. As soon as I made a .zshrc in that dir, and included eval "$(starship init zsh)" in it, as I'd do in my users home directory, everything ran fine.

Additional to this, the ROOT account default shell is BASH, and if your $USER is under ZSH and your ROOT account is BASH, you should change your ROOT shell from BASH to ZSH for you ROOT one:

usermod --shell /bin/zsh root

Regards.,

Was this page helpful?
0 / 5 - 0 ratings