sensible.bash 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Sensible Bash - An attempt at saner Bash defaults
  2. # Maintainer: mrzool <http://mrzool.cc>
  3. # Repository: https://github.com/mrzool/bash-sensible
  4. # Version: 0.2.2
  5. # Unique Bash version check
  6. if ((BASH_VERSINFO[0] < 4))
  7. then
  8. echo "sensible.bash: Looks like you're running an older version of Bash."
  9. echo "sensible.bash: You need at least bash-4.0 or some options will not work correctly."
  10. echo "sensible.bash: Keep your software up-to-date!"
  11. fi
  12. ## GENERAL OPTIONS ##
  13. # Prevent file overwrite on stdout redirection
  14. # Use `>|` to force redirection to an existing file
  15. set -o noclobber
  16. # Update window size after every command
  17. shopt -s checkwinsize
  18. # Automatically trim long paths in the prompt (requires Bash 4.x)
  19. PROMPT_DIRTRIM=2
  20. # Enable history expansion with space
  21. # E.g. typing !!<space> will replace the !! with your last command
  22. bind Space:magic-space
  23. # Turn on recursive globbing (enables ** to recurse all directories)
  24. shopt -s globstar 2> /dev/null
  25. # Case-insensitive globbing (used in pathname expansion)
  26. shopt -s nocaseglob;
  27. ## SMARTER TAB-COMPLETION (Readline bindings) ##
  28. # Perform file completion in a case insensitive fashion
  29. bind "set completion-ignore-case on"
  30. # Treat hyphens and underscores as equivalent
  31. bind "set completion-map-case on"
  32. # Display matches for ambiguous patterns at first tab press
  33. bind "set show-all-if-ambiguous on"
  34. # Immediately add a trailing slash when autocompleting symlinks to directories
  35. bind "set mark-symlinked-directories on"
  36. ## SANE HISTORY DEFAULTS ##
  37. # Append to the history file, don't overwrite it
  38. shopt -s histappend
  39. # Save multi-line commands as one command
  40. shopt -s cmdhist
  41. # Record each line as it gets issued
  42. PROMPT_COMMAND='history -a'
  43. # Huge history. Doesn't appear to slow things down, so why not?
  44. HISTSIZE=500000
  45. HISTFILESIZE=100000
  46. # Avoid duplicate entries
  47. HISTCONTROL="erasedups:ignoreboth"
  48. # Don't record some commands
  49. export HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history:clear"
  50. # Use standard ISO 8601 timestamp
  51. # %F equivalent to %Y-%m-%d
  52. # %T equivalent to %H:%M:%S (24-hours format)
  53. HISTTIMEFORMAT='%F %T '
  54. # Enable incremental history search with up/down arrows (also Readline goodness)
  55. # Learn more about this here: http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
  56. bind '"\e[A": history-search-backward'
  57. bind '"\e[B": history-search-forward'
  58. bind '"\e[C": forward-char'
  59. bind '"\e[D": backward-char'
  60. ## BETTER DIRECTORY NAVIGATION ##
  61. # Prepend cd to directory names automatically
  62. shopt -s autocd 2> /dev/null
  63. # Correct spelling errors during tab-completion
  64. shopt -s dirspell 2> /dev/null
  65. # Correct spelling errors in arguments supplied to cd
  66. shopt -s cdspell 2> /dev/null
  67. # This defines where cd looks for targets
  68. # Add the directories you want to have fast access to, separated by colon
  69. # Ex: CDPATH=".:~:~/projects" will look for targets in the current working directory, in home and in the ~/projects folder
  70. CDPATH="."
  71. # This allows you to bookmark your favorite places across the file system
  72. # Define a variable containing a path and you will be able to cd into it regardless of the directory you're in
  73. shopt -s cdable_vars
  74. # Examples:
  75. # export dotfiles="$HOME/dotfiles"
  76. # export projects="$HOME/projects"
  77. # export documents="$HOME/Documents"
  78. # export dropbox="$HOME/Dropbox"