.bashrc 4.0 KB

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