Created
February 5, 2020 07:58
-
-
Save lunix33/1acbedfd3982b42906a9788d2e3c822b to your computer and use it in GitHub Desktop.
Bash prompt displaying last command exit code, user, host, ssh and screen info, path and git info.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Load Git for Windows prompt. | |
if [ -f "/c/Program Files/Git/mingw64/share/git/completion/git-prompt.sh" ]; then | |
source "/c/Program Files/Git/mingw64/share/git/completion/git-prompt.sh" | |
fi | |
# colors | |
white='\[\033[1;37m\]' | |
gray='\[\033[1;30m\]' | |
lightgray='\[\033[0;37m\]' | |
black='\[\033[0;30m\]' | |
red='\[\033[0;31m\]' | |
lightred='\[\033[1;31m\]' | |
green='\[\033[0;32m\]' | |
lightgreen='\[\033[1;32m\]' | |
brown='\[\033[0;33m\]' | |
yellow='\[\033[1;33m\]' | |
blue='\[\033[0;34m\]' | |
lightblue='\[\033[1;34m\]' | |
purple='\[\033[0;35m\]' | |
pink='\[\033[1;35m\]' | |
cyan='\[\033[0;36m\]' | |
lightcyan='\[\033[1;36m\]' | |
reset='\[\033[0m\]' | |
bracket_color="${lightgray}" | |
# ROOT | |
root_flag="0" | |
root_color="${green}" | |
if [[ ( "${MSYSTEM}" != "" && "$(id -G | grep -E '(114|544)')" != "" ) || "${LOGNAME}" == "root" ]]; then | |
root_flag="1" | |
root_color="${red}" | |
fi | |
function __prompt() { | |
local exit="$?" | |
## | |
# Line 1 | |
## | |
PS1="\n" | |
# Prompt arrow | |
PS1="${PS1}${root_color}\342\224\214\342\224\200" | |
# Last exec | |
local last_exec="${green}✔" | |
[ "${exit}" != "0" ] && last_exec="${red}✘" | |
PS1+="${bracket_color}[${last_exec} (${exit})${bracket_color}]" | |
# User, host, ssh and screen | |
## SSH | |
local ssh_prompt="" | |
[[ "${SSH_CLIENT}" != "" || "${SSH2_CLIENT}" != "" ]] && ssh_prompt="${yellow}SSH${purple}:" | |
## Screen | |
local screen_prompt="" | |
[ "${STY}" != "" ] && screen_prompt="${purple}:${gray}${STY}" | |
## User & host + composition. | |
PS1+="${bracket_color}[${root_color}\u${purple}@${ssh_prompt}${lightblue}\h${screen_prompt}${bracket_color}]" | |
# Current working directory & Git branch | |
## CWD | |
local cwd="${yellow}\w" | |
# Git branch | |
local git_prompt="${cyan}$(__git_ps1)" | |
# Composition | |
PS1+="${bracket_color}[${cwd}${git_prompt}${bracket_color}]" | |
## | |
# Line 2 | |
## | |
# Prompt | |
PS1+="\n${root_color}\342\224\224\342\224\200\342\224\200> ${reset}" | |
} | |
PROMPT_COMMAND="__prompt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment