.bashrc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #
  2. # ~/.bashrc
  3. #
  4. [[ $- != *i* ]] && return
  5. # mkdircd - create directory and change current directory to created one
  6. # usage mkdircd <new_directory>
  7. mkdircd () {
  8. mkdir -p $1
  9. cd $1
  10. }
  11. # ex - archive extractor
  12. # usage: ex <file>
  13. ex ()
  14. {
  15. if [ -f $1 ] ; then
  16. case $1 in
  17. *.tar.bz2) tar xjf $1 ;;
  18. *.tar.gz) tar xzf $1 ;;
  19. *.bz2) bunzip2 $1 ;;
  20. *.rar) unrar x $1 ;;
  21. *.gz) gunzip $1 ;;
  22. *.tar) tar xf $1 ;;
  23. *.tbz2) tar xjf $1 ;;
  24. *.tgz) tar xzf $1 ;;
  25. *.zip) unzip $1 ;;
  26. *.Z) uncompress $1;;
  27. *.7z) 7z x $1 ;;
  28. *) echo "'$1' cannot be extracted via ex()" ;;
  29. esac
  30. else
  31. echo "'$1' is not a valid file"
  32. fi
  33. }
  34. use_color=true
  35. # highlight results of common Unix commands
  36. safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
  37. match_lhs=""
  38. [[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
  39. [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
  40. [[ -z ${match_lhs} ]] \
  41. && type -P dircolors >/dev/null \
  42. && match_lhs=$(dircolors --print-database)
  43. [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
  44. if ${use_color} ; then
  45. # Enable colors for ls, etc. Prefer ~/.dir_colors #64489
  46. if type -P dircolors >/dev/null ; then
  47. if [[ -f ~/.dir_colors ]] ; then
  48. eval $(dircolors -b ~/.dir_colors)
  49. elif [[ -f /etc/DIR_COLORS ]] ; then
  50. eval $(dircolors -b /etc/DIR_COLORS)
  51. fi
  52. fi
  53. alias ls='ls --color=auto'
  54. alias ll='ls -lhA --color=auto'
  55. alias grep='grep --colour=auto'
  56. alias egrep='egrep --colour=auto'
  57. alias fgrep='fgrep --colour=auto'
  58. else
  59. alias ll='ls -lhA'
  60. fi
  61. [ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
  62. unset use_color safe_term match_lhs sh
  63. # aliases for common Unix commands
  64. alias cp="cp -i" # confirm before overwriting something
  65. alias df='df -h' # human-readable sizes
  66. alias free='free -m' # show sizes in MB
  67. # Bash won't get SIGWINCH if another process is in the foreground.
  68. # Enable checkwinsize so that bash will check the terminal size when
  69. # it regains control. #65623
  70. # http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
  71. shopt -s checkwinsize
  72. shopt -s expand_aliases
  73. # Enable history appending instead of overwriting. #139609
  74. shopt -s histappend
  75. # A two-line colored Bash prompt (PS1) with Git branch and a line decoration
  76. # which adjusts automatically to the width of the terminal.
  77. # Recognizes and shows Git, SVN and Fossil branch/revision.
  78. # Screenshot: http://img194.imageshack.us/img194/2154/twolineprompt.png
  79. # Michal Kottman, 2012
  80. RESET="\[\033[0m\]"
  81. RED="\[\033[0;31m\]"
  82. GREEN="\[\033[01;32m\]"
  83. BLUE="\[\033[01;34m\]"
  84. YELLOW="\[\033[0;33m\]"
  85. function parse_git_branch {
  86. PS_BRANCH=''
  87. if [ -d .svn ]; then
  88. PS_BRANCH="(svn r$(svn info|awk '/Revision/{print $2}'))"
  89. return
  90. elif [ -f _FOSSIL_ -o -f .fslckout ]; then
  91. PS_BRANCH="(fossil $(fossil status|awk '/tags/{print $2}')) "
  92. return
  93. fi
  94. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  95. PS_BRANCH="(git ${ref#refs/heads/}) "
  96. }
  97. PROMPT_COMMAND=parse_git_branch
  98. PS_INFO="$GREEN\u@\h$RESET:$BLUE\w"
  99. PS_GIT="$YELLOW\$PS_BRANCH"
  100. PS_TIME="\[\033[\$((COLUMNS-10))G\] $RED[\t]"
  101. # \u2554, \u255A -> box-shaping characters
  102. export PS1="╔═ ${PS_INFO} ${PS_GIT}${PS_TIME}\n${RESET}╚═ \$ "
  103. # alias code = codium for case if codium is installed
  104. if ! command -v "code" &> /dev/null ; then
  105. if command -v "codium" &> /dev/null ; then
  106. alias code='codium'
  107. fi
  108. fi