117
submitted 11 months ago by stepanzak@iusearchlinux.fyi to c/linux@lemmy.ml

Hi. I've been using powerlevel10k for a long time, but a few days ago, I decided I wanted to customize it a bit. I opened the .p10k.zsh file, and I was shocked. It's really massive, with TONS of options. I've been digging through for a few hours already, and it's absolutely amazing how much you can customize it without actually programming anything. I was wondering what other people are using. So my questions are:

  • Do you customize your shell prompt?
  • If yes, do you use some framework or pre-made theme, or do you just configure it the vanilla way in your bashrc/zshrc/...
  • How is your experiences with it so far?
  • Share screenshot of your prompts, please (Sadly, my prompt is currently half done, so I can't really share it)
you are viewing a single comment's thread
view the rest of the comments
[-] 30p87@feddit.de 6 points 11 months ago* (last edited 11 months ago)

As I use bash basically for everything, I wanted my prompt to be as basic as possible (No newlines, fixed format) and compatible across my PC, Laptop as well as server and Pi via SSH.
Therefore, it's a simple __prompt_command function in my .bashrc (nearly) everywhere.
It's structured as:

  1. Terminal/TTY number in orange
  2. Username in green (for roots .bashrc it's red)
  3. Hostname in green
  4. Current working dir in blue
  5. Current git branch in yellow (if in a git repo)
  6. Exit code in red (if not 0)

Looks like this: 1000011281

I used some prompt generator to get the variables and colors right, and then wrapped parts in if-then where needed.
The result is:

__prompt_command() {
    local EXIT="$?"
    PS1="\[\033[38;5;216m\](\l)\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;85m\]\u@\H\[$(tput sgr0)\]:\[$(tput sgr0)\]\[\033[38;5;68m\][\w\[$(tput sgr0)\]"
    local GIT_BRANCH="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')"
    if ! [[ -z "$GIT_BRANCH" ]]; then
        PS1+=":\[$(tput sgr0)\]\[\033[38;5;142m\]${GIT_BRANCH}\[$(tput sgr0)\]"
    fi
    PS1+="\[\033[38;5;68m\]]\[$(tput sgr0)\]"
    if [ $EXIT != 0 ]; then
        PS1+=":\[$(tput sgr0)\]\[\033[38;5;1m\]${EXIT}\[$(tput sgr0)\]"
    fi
    PS1+="\\$ \[$(tput sgr0)\]"
}

In practice I use every aspect of it. The terminal number is useful for sorting, the username is needed especially when handling e.g. git or db servers with specific users, and one has a terminal as the user, one as root and one as normal user. Hostname is obviously important with multiple ssh sessions open all the time (especially without terminal emulator titles). Typing pwd all the time would be very tedious, as I only move around my system in bash, so having it in the prompt is nice. If I am in a git repo I also need to know the branch and otherwise it's not displayed anyway. Quickly identifying silently failed commands is tedious, especially because issuing one command overwrites $? again, so 'logging' it if necessary is nice.

this post was submitted on 21 Oct 2023
117 points (96.8% liked)

Linux

47504 readers
1765 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS