1
0

dev-bash.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # This file gets executed when a user starts a `bash` shell, usually because
  2. # they’ve just started a new Vagrant session with `vagrant ssh`. It configures
  3. # some (but not all) of the commands that you can use.
  4. # Display the installed versions of tools.
  5. # help banner
  6. bash /vagrant/devtools/dev-versions.sh
  7. # Configure the Cool Prompt™ (not actually trademarked).
  8. # The Cool Prompt tells you whether you’re in debug or strict mode, whether
  9. # you have colours configured, and whether your last command failed.
  10. function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }
  11. function debug_mode() { [ "$EXA_DEBUG" == "trace" ] && echo -n "trace-"; [ -n "$EXA_DEBUG" ] && echo "debug "; }
  12. function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }
  13. function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }
  14. function exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; }
  15. export PS1="\[\e[1;36m\]\h \[\e[32m\]\w \[\e[31m\]\`nonzero_return\`\[\e[35m\]\`debug_mode\`\[\e[32m\]\`lsc_mode\`\[\e[1;32m\]\`exac_mode\`\[\e[33m\]\`strict_mode\`\[\e[36m\]\\$\[\e[0m\] "
  16. # The ‘debug’ function lets you switch debug mode on and off.
  17. # Turn it on if you need to see exa’s debugging logs.
  18. function debug () {
  19. case "$1" in
  20. ""|"on") export EXA_DEBUG=1 ;;
  21. "off") export EXA_DEBUG= ;;
  22. "trace") export EXA_DEBUG=trace ;;
  23. "status") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;
  24. *) echo "Usage: debug on|off|trace|status"; return 1 ;;
  25. esac;
  26. }
  27. # The ‘strict’ function lets you switch strict mode on and off.
  28. # Turn it on if you’d like exa’s command-line arguments checked.
  29. function strict () {
  30. case "$1" in "on") export EXA_STRICT=1 ;;
  31. "off") export EXA_STRICT= ;;
  32. "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;
  33. *) echo "Usage: strict on|off"; return 1 ;;
  34. esac;
  35. }
  36. # The ‘colors’ function sets or unsets the ‘LS_COLORS’ and ‘EXA_COLORS’
  37. # environment variables. There’s also a ‘hacker’ theme which turns everything
  38. # green, which is usually used for checking that all colour codes work, and
  39. # for looking cool while you phreak some mainframes or whatever.
  40. function colors () {
  41. case "$1" in
  42. "ls")
  43. export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
  44. export EXA_COLORS="" ;;
  45. "hacker")
  46. export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32"
  47. export EXA_COLORS="ur=32:uw=32:ux=32:ue=32:gr=32:gw=32:gx=32:tr=32:tw=32:tx=32:su=32:sf=32:xa=32:sn=32:sb=32:df=32:ds=32:uu=32:un=32:gu=32:gn=32:lc=32:lm=32:ga=32:gm=32:gd=32:gv=32:gt=32:xx=32:da=32:in=32:bl=32:hd=32:lp=32:cc=32:" ;;
  48. "off")
  49. export LS_COLORS=
  50. export EXA_COLORS= ;;
  51. "")
  52. [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"
  53. [ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;
  54. *) echo "Usage: ls-colors ls|hacker|off"; return 1 ;;
  55. esac;
  56. }