dev-bash.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. nonzero_return() { RETVAL=$?; [ "$RETVAL" -ne 0 ] && echo "$RETVAL "; }
  11. debug_mode() { [ "$EXA_DEBUG" == "trace" ] && echo -n "trace-"; [ -n "$EXA_DEBUG" ] && echo "debug "; }
  12. strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }
  13. lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }
  14. 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. 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. strict() {
  30. case "$1" in
  31. "on") export EXA_STRICT=1 ;;
  32. "off") export EXA_STRICT= ;;
  33. "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;
  34. *) echo "Usage: strict on|off"; return 1 ;;
  35. esac;
  36. }
  37. # The ‘colors’ function sets or unsets the ‘LS_COLORS’ and ‘EXA_COLORS’
  38. # environment variables. There’s also a ‘hacker’ theme which turns everything
  39. # green, which is usually used for checking that all colour codes work, and
  40. # for looking cool while you phreak some mainframes or whatever.
  41. colors() {
  42. case "$1" in
  43. "ls")
  44. 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"
  45. export EXA_COLORS="" ;;
  46. "hacker")
  47. export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32"
  48. 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:" ;;
  49. "off")
  50. export LS_COLORS=
  51. export EXA_COLORS= ;;
  52. "")
  53. [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"
  54. [ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;
  55. *) echo "Usage: ls-colors ls|hacker|off"; return 1 ;;
  56. esac;
  57. }