.bashrc-root 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. # xhost +local:root > /dev/null 2>&1
  68. # complete -cf sudo
  69. # Bash won't get SIGWINCH if another process is in the foreground.
  70. # Enable checkwinsize so that bash will check the terminal size when
  71. # it regains control. #65623
  72. # http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
  73. shopt -s checkwinsize
  74. shopt -s expand_aliases
  75. # Enable history appending instead of overwriting. #139609
  76. shopt -s histappend
  77. # A two-line colored Bash prompt (PS1) with Git branch and a line decoration
  78. # which adjusts automatically to the width of the terminal.
  79. # Recognizes and shows Git, SVN and Fossil branch/revision.
  80. # Screenshot: http://img194.imageshack.us/img194/2154/twolineprompt.png
  81. # Michal Kottman, 2012
  82. RESET="\[\033[0m\]"
  83. RED="\[\033[0;31m\]"
  84. GREEN="\[\033[01;32m\]"
  85. BLUE="\[\033[01;34m\]"
  86. YELLOW="\[\033[0;33m\]"
  87. function parse_git_branch {
  88. PS_BRANCH=''
  89. if [ -d .svn ]; then
  90. PS_BRANCH="(svn r$(svn info|awk '/Revision/{print $2}'))"
  91. return
  92. elif [ -f _FOSSIL_ -o -f .fslckout ]; then
  93. PS_BRANCH="(fossil $(fossil status|awk '/tags/{print $2}')) "
  94. return
  95. fi
  96. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  97. PS_BRANCH="(git ${ref#refs/heads/}) "
  98. }
  99. PROMPT_COMMAND=parse_git_branch
  100. PS_INFO="$RED\u@\h$RESET:$BLUE\w"
  101. PS_GIT="$YELLOW\$PS_BRANCH"
  102. PS_TIME="\[\033[\$((COLUMNS-10))G\] $RED[\t]"
  103. PS_ROOT_TEXT="$RED[ROOT]$RESET"
  104. # \u2554, \u255A -> box-shaping characters
  105. export PS1="╔═ ${PS_INFO} ${PS_GIT} ${PS_ROOT_TEXT} ${PS_TIME}\n${RESET}╚═ ${RED}#${RESET} "
  106. # alias code = codium for case if codium is installed
  107. if ! command -v "code" &> /dev/null ; then
  108. if command -v "codium" &> /dev/null ; then
  109. alias code='codium'
  110. fi
  111. fi