Guest User

Untitled

a guest
Jun 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. # Bash History Replacement Script
  2. # Author: Caesar Kabalan
  3. # Last Modified: June 6th, 2017
  4. # Description:
  5. # Modifies the default Bash Shell prompt tot be in the format of:
  6. # [CWD:COUNT:BRANCH:VENV]
  7. # [USER:HOSTNAME] _
  8. # Where:
  9. # CWD - Current working directory (green if last command returned 0, red otherwise)
  10. # COUNT - Session command count
  11. # BRANCH - Current git branch if in a git repository, omitted if not in a git repo
  12. # VENV - Current Python Virtual Environment if set, omitted if not set
  13. # USER - Current username
  14. # HOSTNAME - System hostname
  15. # Example:
  16. # [~/projects/losteyelid:8:master:losteyelid]
  17. # [ckabalan:spectralcoding] _
  18. # Installation:
  19. # Add the following to one of the following files
  20. # System-wide Prompt Change:
  21. # /etc/profile.d/bash_prompt_custom.sh (new file)
  22. # /etc/bashrc
  23. # Single User Prompt Change:
  24. # ~/.bashrc
  25. # ~/.bash_profile
  26. function set_bash_prompt () {
  27. # Color codes for easy prompt building
  28. COLOR_DIVIDER="\[\e[30;1m\]"
  29. COLOR_CMDCOUNT="\[\e[34;1m\]"
  30. COLOR_USERNAME="\[\e[34;1m\]"
  31. COLOR_USERHOSTAT="\[\e[34;1m\]"
  32. COLOR_HOSTNAME="\[\e[34;1m\]"
  33. COLOR_GITBRANCH="\[\e[33;1m\]"
  34. COLOR_VENV="\[\e[33;1m\]"
  35. COLOR_GREEN="\[\e[32;1m\]"
  36. COLOR_PATH_OK="\[\e[32;1m\]"
  37. COLOR_PATH_ERR="\[\e[31;1m\]"
  38. COLOR_NONE="\[\e[0m\]"
  39. # Change the path color based on return value.
  40. if test $? -eq 0 ; then
  41. PATH_COLOR=${COLOR_PATH_OK}
  42. else
  43. PATH_COLOR=${COLOR_PATH_ERR}
  44. fi
  45. # Set the PS1 to be "[workingdirectory:commandcount"
  46. PS1="${COLOR_DIVIDER}[${PATH_COLOR}\w${COLOR_DIVIDER}:${COLOR_CMDCOUNT}\#${COLOR_DIVIDER}"
  47. # Add git branch portion of the prompt, this adds ":branchname"
  48. if ! git_loc="$(type -p "$git_command_name")" || [ -z "$git_loc" ]; then
  49. # Git is installed
  50. if [ -d .git ] || git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
  51. # Inside of a git repository
  52. GIT_BRANCH=$(git symbolic-ref --short HEAD)
  53. PS1="${PS1}:${COLOR_GITBRANCH}${GIT_BRANCH}${COLOR_DIVIDER}"
  54. fi
  55. fi
  56. # Add Python VirtualEnv portion of the prompt, this adds ":venvname"
  57. if ! test -z "$VIRTUAL_ENV" ; then
  58. PS1="${PS1}:${COLOR_VENV}`basename \"$VIRTUAL_ENV\"`${COLOR_DIVIDER}"
  59. fi
  60. # Close out the prompt, this adds "]\n[username@hostname] "
  61. PS1="${PS1}]\n${COLOR_DIVIDER}[${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER}]${COLOR_NONE} "
  62. }
  63.  
  64. # Tell Bash to run the above function for every prompt
  65. export PROMPT_COMMAND=set_bash_prompt
Add Comment
Please, Sign In to add comment