Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Bash Prompt? #2

Closed
ghost opened this issue Oct 15, 2016 · 10 comments
Closed

Custom Bash Prompt? #2

ghost opened this issue Oct 15, 2016 · 10 comments

Comments

@ghost
Copy link

ghost commented Oct 15, 2016

Real quick, was just curious if there is already a custom bash prompt available. I looked around and couldn't find one so I started making my own. However, it's incomplete and I thought there's no point in continuing if someone else already made it. Otherwise, I'll keep working on it.

@ghost
Copy link
Author

ghost commented Oct 19, 2016

Here's the initial prompt I've come up with. Works for me. Seems errorless.

screen shot 2016-10-19 at 12 13 33 pm

#!/usr/bin/env bash

# Colors
black="\[$(tput setaf 0)\]"
red="\[$(tput setaf 1)\]"
green="\[$(tput setaf 2)\]"
yellow="\[$(tput setaf 3)\]"
blue="\[$(tput setaf 4)\]"
magenta="\[$(tput setaf 5)\]"
cyan="\[$(tput setaf 6)\]"
white="\[$(tput setaf 7)\]"

# Title bar - "user@host: ~"
title="\u@\h: \w"
titlebar="\[\033]0;"$title"\007\]"

# Git branch
git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)\ /';
}

# Clear attributes
clear_attributes="\[$(tput sgr0)\]"

# Custom bash prompt - "➜  ~ (master) "
export PS1="${titlebar}${green}${blue}\W ${cyan}\$(git_branch)${clear_attributes}"

I worked on this for a little while with some of the minute details and I'm happy with it, however, it'd be cool if there were defined colors for other stuff too. Like maybe git for instance. I've seen in the preview image over here that git is colored, and commands like "cd" are colored as well. Also, the underlining. I'm not personally sure how to customize all of that right away, but it'd be cool if someone shared that if they have already done this. Just trying to use Dracula in a bash prompt the way it looks ultimately in that preview image.

No idea if these git colors are accurate, but I stole it from someone else who was also using Dracula.

[color]
  diff = auto
  status = auto
[color "branch"]
  current = cyan
  local = green
  remote = red
[color "diff"]
  meta = yellow
  frag = magenta
  old = red
  new = green
[color "status"]
  added = cyan
  branch = cyan
  changed = magenta
  deleted = red
  untracked = yellow

@raldred
Copy link

raldred commented Feb 5, 2017

This is a great help. Thanks for sharing @barryanders
I too am really interested in the particular git and command feedback shown in the example.
Maybe @nesl247 can help?

@muyangwu
Copy link

How did you get the green arrows for each beginning lines of commands?

@ghost
Copy link
Author

ghost commented Mar 20, 2017

You can see the arrow in the export PS1 line. It's just written plainly.

@roycehe
Copy link

roycehe commented Jun 24, 2017

excellent! yo😁

@icn2you
Copy link

icn2you commented Sep 2, 2017

Please forgive the elementary question, but how do I define the remaining colors in the Dracula Theme palette (for my bash profile)? For example, I noticed pink and orange are missing from the color definitions above.

@huangboju
Copy link

@BarryMode How to configure git and Linux commands?

@ghost
Copy link
Author

ghost commented Sep 18, 2017

@icn2you 0-7 are the only color options, and the color names are chosen based on what that traditionally represents. On any command line I've ever used, it's always

0 = black
1 = red
2 = green
3 = yellow
4 = blue
5 = magenta
6 = cyan
7 = white

This repo includes a basic profile with the colors set https://github.com/dracula/terminal.app/blob/master/Dracula.terminal

I only added custom bash prompt code above because I wanted it to look the way they showed it on their website.

To my understanding, it's not possible to add additional colors as the color limitations are part of the command line itself. It's likely possible to add more color to different outputs of your prompt, however, I'm not familiar with it. I just know the basics.

@huangboju Add this to .gitconfig

[color]
  diff = auto
  status = auto
[color "branch"]
  current = cyan
  local = green
  remote = red
[color "diff"]
  meta = yellow
  frag = magenta
  old = red
  new = green
[color "status"]
  added = cyan
  branch = cyan
  changed = magenta
  deleted = red
  untracked = yellow

As for Linux commands, I don't know. Maybe you mean something like this? I use this for forcing color output on various commands. You can add this to .bash_prompt. It looks like there's some custom commands in there. Feel free to remove those if you don't want them :)

##########
# Colors #
##########

# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then
  colorflag="--color"
  export LS_COLORS='no=00:fi=00:di=01;31:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
else # macOS `ls`
  colorflag="-G"
  export LSCOLORS='BxBxhxDxfxhxhxhxhxcxcx'
fi

# List all files colorized in long format
alias l="ls -lF ${colorflag}"
# List all files colorized in long format, including dot files
alias la="ls -laF ${colorflag}"
# List only directories
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'"
# Always use color output for `ls`
alias ls="command ls ${colorflag}"

# Always enable colored `grep` output
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

# Always enable colored tree
alias tree='tree -C'

@huangboju
Copy link

@BarryMode THX

@benknoble
Copy link
Member

Closing this since the discussion is a few months old and not 100% relevant to the Terminal.app theme.

Anyone have thoughts on converting it to a wiki page so that it's more accessible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants