Skip to content

Commit bc1d37a

Browse files
committed
✨ add advanced PS1 handling with overwriteable customPrompt function
1 parent 428a6d5 commit bc1d37a

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

.additional_bashrc.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ if [[ $CONTAINER_ID != ${HOSTNAME}* ]] ; then
1919
fi
2020

2121
source ~/.bash_git
22-
23-
PS1='\033]2;$HOST_DISPLAY_NAME: \w\007\[\e[0;36m\][\[\e[1;31m\]\u\[\e[0;36m\]@\[\e[1;34m\]$HOST_DISPLAY_NAME\[\e[0;36m\]: \[\e[0m\]\w\[\e[0;36m\]]\[\e[0m\]\$\[\e[1;32m\]\s\[\e[0;33m\]$(__git_ps1)\[\e[0;36m\]> \[\e[0m\]\n$ ';
22+
source ~/.additional_bashrc_ps1.sh
2423

2524
alias xdebug-toggle='test $(php -m | grep xdebug) && xdebug-disable && echo "xdebug disabled" || (xdebug-enable && echo "xdebug enabled")'
2625

.additional_bashrc_ps1.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
COLOR_RESET=$(echo -en '\001\033[0m\002')
2+
COLOR_RED=$(echo -en '\001\033[00;31m\002')
3+
COLOR_GREEN=$(echo -en '\001\033[00;32m\002')
4+
COLOR_YELLOW=$(echo -en '\001\033[00;33m\002')
5+
COLOR_BLUE=$(echo -en '\001\033[00;34m\002')
6+
COLOR_MAGENTA=$(echo -en '\001\033[00;35m\002')
7+
COLOR_PURPLE=$(echo -en '\001\033[00;35m\002')
8+
COLOR_CYAN=$(echo -en '\001\033[00;36m\002')
9+
COLOR_LIGHTGRAY=$(echo -en '\001\033[00;37m\002')
10+
COLOR_LRED=$(echo -en '\001\033[01;31m\002')
11+
COLOR_LGREEN=$(echo -en '\001\033[01;32m\002')
12+
COLOR_LYELLOW=$(echo -en '\001\033[01;33m\002')
13+
COLOR_LBLUE=$(echo -en '\001\033[01;34m\002')
14+
COLOR_LMAGENTA=$(echo -en '\001\033[01;35m\002')
15+
COLOR_LPURPLE=$(echo -en '\001\033[01;35m\002')
16+
COLOR_LCYAN=$(echo -en '\001\033[01;36m\002')
17+
COLOR_WHITE=$(echo -en '\001\033[01;37m\002')
18+
19+
20+
# Set Terminal title - current folder
21+
function userTerminalTitlePwd {
22+
echo -e '\033]2;' # open terminal title
23+
# content of the terminal window:
24+
echo -e '${HOST_DISPLAY_NAME}: \w'
25+
echo -e '\007' # close terminal title
26+
}
27+
28+
# Render exit code
29+
function exitCodeWarning {
30+
code=$?
31+
if [[ $code != 0 ]]; then
32+
echo -e "${COLOR_RED}✗✗✗ exit code was ${code} ✗✗✗\n\n${COLOR_RESET}"
33+
fi
34+
}
35+
36+
# Render Git branch for PS1
37+
function renderGitBranch {
38+
if [ -f $(which git) ]; then
39+
echo "${COLOR_YELLOW}$(__git_ps1)"
40+
fi
41+
}
42+
43+
function customPrompt {
44+
# this function is only there that it can be overwritten in with your own custom prompt
45+
true
46+
}
47+
48+
# Style bash prompt
49+
PS1=''
50+
PS1+='\033]2;${HOST_DISPLAY_NAME}: \w\007' # terminal Title
51+
PS1+='$(exitCodeWarning)' # git information
52+
#PS1+='$(if [[ $? != 0 ]]; then echo "\n"; fi)'
53+
PS1+='${COLOR_CYAN}['
54+
55+
PS1+='${COLOR_LRED}\u' # user
56+
PS1+='${COLOR_CYAN}@'
57+
PS1+='${COLOR_LBLUE}${HOST_DISPLAY_NAME}' # container name
58+
PS1+='${COLOR_CYAN}: '
59+
PS1+='${COLOR_RESET}\w' # working directory
60+
61+
PS1+='${COLOR_CYAN}]'
62+
63+
PS1+='$(renderGitBranch)' # git information
64+
PS1+='$(customPrompt)' # git information
65+
66+
PS1+='${COLOR_CYAN}> '
67+
PS1+='${COLOR_RESET} ';
68+
PS1+='\n'
69+
PS1+='\$ '

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ RUN install-php-extensions @fix_letsencrypt xhprof mongodb pcov && \
3535
USER application
3636

3737
COPY bin/* /usr/local/bin/
38-
COPY .additional_bashrc.sh /home/application/.additional_bashrc.sh
38+
COPY .additional_bashrc.sh .additional_bashrc_ps1.sh /home/application/
3939
COPY .vimrc /home/application/.vimrc
4040
COPY .vimrc /root/.vimrc
4141
COPY apache.conf /opt/docker/etc/httpd/vhost.common.d/apache.conf

0 commit comments

Comments
 (0)