.bashrc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # add aliases with optimized settings
  3. alias ls='ls -vhFA --color=auto'
  4. alias grep='grep --color=auto'
  5. alias ..='cd ..'
  6. alias ...='cd ../..'
  7. alias sshfs='sshfs -o cache=yes,compression=yes,kernel_cache'
  8. # alias for discord wayland, since it ignores configs
  9. alias discord='discord --enable-features=UseOzonePlatform --ozone-platform=wayland'
  10. # define pretty man pages colors
  11. man() {
  12. env \
  13. LESS_TERMCAP_md=$'\e[1;36m' \
  14. LESS_TERMCAP_me=$'\e[0m' \
  15. LESS_TERMCAP_se=$'\e[0m' \
  16. LESS_TERMCAP_so=$'\e[1;40;92m' \
  17. LESS_TERMCAP_ue=$'\e[0m' \
  18. LESS_TERMCAP_us=$'\e[1;32m' \
  19. man "$@"
  20. }
  21. # colors for enhanced prompt
  22. c_bold="\033[1m"
  23. c_red="\033[31m"
  24. c_green="\033[32m"
  25. c_blue="\033[34m"
  26. c_purple="\033[35m"
  27. c_cyan="\033[36m"
  28. c_sgr0="\033[0m"
  29. # promptify is an updated prompt enhancement enabled by default
  30. promptify() {
  31. local prompt_string
  32. prompt_string="${c_blue}${0} ($(date +'%R:%S.%3N'):${timer_show}s) ${c_purple}$(whoami)${c_sgr0}@${c_green}$(hostname) ${c_bold}${c_blue}$(dirs)${c_sgr0}"
  33. if git rev-parse --git-dir &> /dev/null; then
  34. git_branch=$(git branch 2> /dev/null | sed -n 's/^\*[ ]*//p')
  35. git_stats=$(git status --porcelain --untracked-files=all 2> /dev/null)
  36. if [ $(echo "${git_stats}" | sed '/^\s*$/d' | wc -l) -gt 0 ]; then
  37. prompt_string="${prompt_string} [${c_red}${git_branch}${c_sgr0}"
  38. untracked_count=$(echo "${git_stats}" | grep -ce "^??")
  39. new_file_count=$(echo "${git_stats}" | grep -ce "^A ")
  40. renamed_count=$(echo "${git_stats}" | grep -ce "^R ")
  41. modified_staged_count=$(echo "${git_stats}" | grep -ce "^M ")
  42. modified_unstaged_count=$(echo "${git_stats}" | grep -ce "^ M")
  43. deleted_staged_count=$(echo "${git_stats}" | grep -ce "^D ")
  44. deleted_unstaged_count=$(echo "${git_stats}" | grep -ce "^ D")
  45. [ $(($untracked_count + $new_file_count + $renamed_count + $modified_staged_count + $modified_unstaged_count + $deleted_staged_count + $deleted_unstaged_count)) -gt 0 ] && prompt_string="${prompt_string}:"
  46. [ $untracked_count -gt 0 ] && prompt_string="${prompt_string} ${c_red}u${untracked_count}${c_sgr0}"
  47. [ $new_file_count -gt 0 ] && prompt_string="${prompt_string} ${c_green}a${new_file_count}${c_sgr0}"
  48. [ $renamed_count -gt 0 ] && prompt_string="${prompt_string} ${c_green}r${renamed_count}${c_sgr0}"
  49. [ $modified_unstaged_count -gt 0 ] || [ $modified_staged_count -gt 0 ] && prompt_string="${prompt_string} ${c_red}m${c_sgr0}"
  50. [ $modified_unstaged_count -gt 0 ] && prompt_string="${prompt_string}${c_red}${modified_unstaged_count}${c_sgr0}" && [ $modified_staged_count -gt 0 ] && prompt_string="${prompt_string}/"
  51. [ $modified_staged_count -gt 0 ] && prompt_string="${prompt_string}${c_green}${modified_staged_count}${c_sgr0}"
  52. [ $deleted_unstaged_count -gt 0 ] || [ $deleted_staged_count -gt 0 ] && prompt_string="${prompt_string} ${c_red}d${c_sgr0}"
  53. [ $deleted_unstaged_count -gt 0 ] && prompt_string="${prompt_string}${c_red}${deleted_unstaged_count}${c_sgr0}" && [ $deleted_staged_count -gt 0 ] && prompt_string="${prompt_string}/"
  54. [ $deleted_staged_count -gt 0 ] && prompt_string="${prompt_string}${c_green}${deleted_staged_count}${c_sgr0}"
  55. prompt_string="${prompt_string}]"
  56. else
  57. prompt_string="${prompt_string} [${c_green}${git_branch}${c_sgr0}]"
  58. fi
  59. fi
  60. echo -ne "\n${prompt_string}\n "
  61. }
  62. # time every command
  63. timer_start() {
  64. timer=${timer:-$SECONDS}
  65. }
  66. timer_stop() {
  67. timer_show=$(($SECONDS - $timer))
  68. unset timer
  69. }
  70. trap 'timer_start' DEBUG
  71. # apply prompt enhancements
  72. PS2='continue-> '
  73. PS1='$(promptify)'
  74. if [ -z "$PROMPT_COMMAND" ]; then
  75. PROMPT_COMMAND="timer_stop"
  76. else
  77. PROMPT_COMMAND="$PROMPT_COMMAND; timer_stop"
  78. fi
  79. # load bash auto-completion and command-not-found
  80. . /usr/share/bash-completion/bash_completion
  81. . /usr/share/doc/pkgfile/command-not-found.bash
  82. # use shared agent to load ssh-keys; expects systemd to manage agent
  83. export SSH_AUTH_SOCK="$HOME/.ssh/socket"
  84. ssh-add -l &> /dev/null || ssh-add