Skip to content

Commit

Permalink
Merge pull request #133 from pluswerk/advanced-ps1-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Nov 29, 2023
2 parents 428a6d5 + bc1d37a commit 2c6b5ee
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .additional_bashrc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ if [[ $CONTAINER_ID != ${HOSTNAME}* ]] ; then
fi

source ~/.bash_git

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$ ';
source ~/.additional_bashrc_ps1.sh

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

Expand Down
69 changes: 69 additions & 0 deletions .additional_bashrc_ps1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
COLOR_RESET=$(echo -en '\001\033[0m\002')
COLOR_RED=$(echo -en '\001\033[00;31m\002')
COLOR_GREEN=$(echo -en '\001\033[00;32m\002')
COLOR_YELLOW=$(echo -en '\001\033[00;33m\002')
COLOR_BLUE=$(echo -en '\001\033[00;34m\002')
COLOR_MAGENTA=$(echo -en '\001\033[00;35m\002')
COLOR_PURPLE=$(echo -en '\001\033[00;35m\002')
COLOR_CYAN=$(echo -en '\001\033[00;36m\002')
COLOR_LIGHTGRAY=$(echo -en '\001\033[00;37m\002')
COLOR_LRED=$(echo -en '\001\033[01;31m\002')
COLOR_LGREEN=$(echo -en '\001\033[01;32m\002')
COLOR_LYELLOW=$(echo -en '\001\033[01;33m\002')
COLOR_LBLUE=$(echo -en '\001\033[01;34m\002')
COLOR_LMAGENTA=$(echo -en '\001\033[01;35m\002')
COLOR_LPURPLE=$(echo -en '\001\033[01;35m\002')
COLOR_LCYAN=$(echo -en '\001\033[01;36m\002')
COLOR_WHITE=$(echo -en '\001\033[01;37m\002')


# Set Terminal title - current folder
function userTerminalTitlePwd {
echo -e '\033]2;' # open terminal title
# content of the terminal window:
echo -e '${HOST_DISPLAY_NAME}: \w'
echo -e '\007' # close terminal title
}

# Render exit code
function exitCodeWarning {
code=$?
if [[ $code != 0 ]]; then
echo -e "${COLOR_RED}✗✗✗ exit code was ${code} ✗✗✗\n\n${COLOR_RESET}"
fi
}

# Render Git branch for PS1
function renderGitBranch {
if [ -f $(which git) ]; then
echo "${COLOR_YELLOW}$(__git_ps1)"
fi
}

function customPrompt {
# this function is only there that it can be overwritten in with your own custom prompt
true
}

# Style bash prompt
PS1=''
PS1+='\033]2;${HOST_DISPLAY_NAME}: \w\007' # terminal Title
PS1+='$(exitCodeWarning)' # git information
#PS1+='$(if [[ $? != 0 ]]; then echo "\n"; fi)'
PS1+='${COLOR_CYAN}['

PS1+='${COLOR_LRED}\u' # user
PS1+='${COLOR_CYAN}@'
PS1+='${COLOR_LBLUE}${HOST_DISPLAY_NAME}' # container name
PS1+='${COLOR_CYAN}: '
PS1+='${COLOR_RESET}\w' # working directory

PS1+='${COLOR_CYAN}]'

PS1+='$(renderGitBranch)' # git information
PS1+='$(customPrompt)' # git information

PS1+='${COLOR_CYAN}> '
PS1+='${COLOR_RESET} ';
PS1+='\n'
PS1+='\$ '
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN install-php-extensions @fix_letsencrypt xhprof mongodb pcov && \
USER application

COPY bin/* /usr/local/bin/
COPY .additional_bashrc.sh /home/application/.additional_bashrc.sh
COPY .additional_bashrc.sh .additional_bashrc_ps1.sh /home/application/
COPY .vimrc /home/application/.vimrc
COPY .vimrc /root/.vimrc
COPY apache.conf /opt/docker/etc/httpd/vhost.common.d/apache.conf
Expand Down

0 comments on commit 2c6b5ee

Please sign in to comment.