forked from devcontainers/features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_theme_snippet.sh
More file actions
44 lines (40 loc) · 2.06 KB
/
Copy pathbash_theme_snippet.sh
File metadata and controls
44 lines (40 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme
__bash_prompt() {
local userpart='`export XIT=$? \
&& [ ! -z "${GITHUB_USER:-}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER:-} " || echo -n "\[\033[0;32m\]\u " \
&& [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
local gitbranch='`\
if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \
export BRANCH="$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null)"; \
if [ "${BRANCH:-}" != "" ]; then \
echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH:-}" \
&& if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \
git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
echo -n " \[\033[1;33m\]✗"; \
fi \
&& echo -n "\[\033[0;36m\]) "; \
fi; \
fi`'
local lightblue='\[\033[1;34m\]'
local removecolor='\[\033[0m\]'
PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ "
unset -f __bash_prompt
}
__bash_prompt
export PROMPT_DIRTRIM=4
# Check if the terminal is xterm
if [[ "$TERM" == "xterm" ]]; then
# Function to set the terminal title to the current command
preexec() {
local cmd="${BASH_COMMAND}"
echo -ne "\033]0;${USER}@${HOSTNAME}: ${cmd}\007"
}
# Function to reset the terminal title to the shell type after the command is executed
precmd() {
echo -ne "\033]0;${USER}@${HOSTNAME}: ${SHELL}\007"
}
# Trap DEBUG signal to call preexec before each command
trap 'preexec' DEBUG
# Append to PROMPT_COMMAND to call precmd before displaying the prompt
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }precmd"
fi