Last active
November 26, 2019 19:48
-
-
Save ggrandes/f2b5d541ba2c1affdc3e to your computer and use it in GitHub Desktop.
Linux Colored Prompt
This file contains hidden or 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 | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
# Original Source: | |
# https://gist.github.com/ggrandes/f2b5d541ba2c1affdc3e | |
# | |
# /etc/profile.d/prompt.sh | |
# | |
# Define PROMPT_SCHEMA with: | |
# sudo tee /etc/profile.d/prompt-type.sh <<<'export PROMPT_SCHEMA="XXXX"' | |
# | |
newprompt () { | |
# | |
local NO_COLOUR="\[\e[0m\]" | |
# | |
local BLACK="\[\e[0;30m\]" | |
local DARK_RED="\[\e[0;31m\]" | |
local DARK_GREEN="\[\e[0;32m\]" | |
local DARK_YELLOW="\[\e[0;33m\]" | |
local DARK_BLUE="\[\e[0;34m\]" | |
local DARK_PINK="\[\e[0;35m\]" | |
local DARK_CYAN="\[\e[0;36m\]" | |
local DARK_WHITE="\[\e[0;37m\]" | |
# | |
local GRAY="\[\e[1;30m\]" | |
local LIGHT_RED="\[\e[1;31m\]" | |
local LIGHT_GREEN="\[\e[1;32m\]" | |
local LIGHT_YELLOW="\[\e[1;33m\]" | |
local LIGHT_BLUE="\[\e[1;34m\]" | |
local LIGHT_PINK="\[\e[1;35m\]" | |
local LIGHT_CYAN="\[\e[1;36m\]" | |
local LIGHT_WHITE="\[\e[1;37m\]" | |
# | |
case "${PROMPT_SCHEMA:-UNK}" in | |
DMZPRO|COMMON) | |
local MARK_COLOR="${LIGHT_YELLOW}" | |
local DATA_COLOR="${LIGHT_PINK}" | |
;; | |
PRO|UAT) | |
local MARK_COLOR="${LIGHT_BLUE}" | |
local DATA_COLOR="${LIGHT_CYAN}" | |
;; | |
PRE|TST|TEST) | |
local MARK_COLOR="${LIGHT_RED}" | |
local DATA_COLOR="${LIGHT_YELLOW}" | |
;; | |
DEV|DEVEL) | |
local MARK_COLOR="${LIGHT_PINK}" | |
local DATA_COLOR="${DARK_GREEN}" | |
;; | |
*) | |
local MARK_COLOR="${GRAY}" | |
local DATA_COLOR="${DARK_WHITE}" | |
;; | |
esac | |
# | |
local DIR_COLOR="${LIGHT_WHITE}" | |
# | |
local PROMPT="${MARK_COLOR}[${DATA_COLOR}\u${MARK_COLOR}@${DATA_COLOR}\h ${DIR_COLOR}\w${MARK_COLOR}]${DATA_COLOR}\\$" | |
export PS1="$PROMPT ${NO_COLOUR}" | |
# Export Host/Directory to Terminal Title | |
tty 2>/dev/null | grep -q '^/dev/tty' 1>/dev/null 2>&1 || | |
export PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\h\a\]$PS1" | |
} | |
# Set prompt in profile script | |
grep -q newprompt ~/.profile 1>/dev/null 2>&1 || echo 'type -p newprompt 1>/dev/null 2>&1 && newprompt' >> ~/.profile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/tmp/scancolors.sh