You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.0 KiB

  1. # Via https://tanguy.ortolo.eu/blog/article25/shrc
  2. #
  3. # At startup, depending on the case:
  4. # - run as a login shell (or with the option --login), it executes profile (or
  5. # bash_profile instead if it exists (only user-specific version));
  6. # - run as an interactive, non-login shell, it executes bashrc (the system-wide
  7. # version is called bash.bashrc).
  8. #
  9. # At exit, it executes ~/.bash_logout (the system-wide version is called
  10. # bash.bash_logout).
  11. # Note the funny (read: insane) non-login condition for executing bashrc: it is
  12. # often worked around by having the profile execute bashrc anyway.
  13. # If not running interactively, don't do anything
  14. [ -z "$PS1" ] && return
  15. # Source global definitions
  16. test -r /etc/bashrc && . /etc/bashrc
  17. test -r ~/.shell-env && . ~/.shell-env
  18. test -r ~/.shell-aliases && . ~/.shell-aliases
  19. test -r ~/.shell-common && . ~/.shell-common
  20. # don't put duplicate lines in the history. See bash(1) for more options
  21. # ... or force ignoredups and ignorespace
  22. HISTCONTROL=ignoreboth
  23. export HISTIGNORE="&:ls:[bf]g:pwd:exit:cd .."
  24. # append to the history file, don't overwrite it
  25. shopt -s histappend
  26. PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  27. # Store multiline commands as one line.
  28. shopt -s cmdhist
  29. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  30. HISTSIZE=10000
  31. HISTFILESIZE=20000
  32. # check the window size after each command and, if necessary,
  33. # update the values of LINES and COLUMNS.
  34. shopt -s checkwinsize
  35. # Spellcheck directories
  36. shopt -s dirspell
  37. # enable programmable completion features (you don't need to enable
  38. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  39. # sources /etc/bash.bashrc).
  40. test -f /usr/share/bash-completion/bash_completion && . /usr/share/bash-completion/bash_completion
  41. test -f /etc/bash_completion && . /etc/bash_completion
  42. test -f $BREW_PREFIX/etc/bash_completion && . $BREW_PREFIX/etc/bash_completion
  43. test -r ~/.bashrc.local && . ~/.bashrc.local
  44. if command -v fzf-share >/dev/null; then
  45. source "$(fzf-share)/key-bindings.bash"
  46. source "$(fzf-share)/completion.bash"
  47. fi
  48. eval "$(direnv hook bash)"
  49. function right_prompt(){
  50. RIGHT_PROMPT="$(starship prompt --right)"
  51. RIGHT_PROMPT_RENDERED="${RIGHT_PROMPT@P}"
  52. # For some reason this one is less accurate, while the other method below
  53. # gives better precision, but also throws errors. Curious!
  54. #RIGHT_PROMPT_RENDERED_stripped=$(sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" <<<"$RIGHT_PROMPT_RENDERED")
  55. RIGHT_PROMPT_RENDERED_stripped="$(sed -r 's:\\\[([^\\]|\\[^]])*\\\]::g' <<<$RIGHT_PROMPT_RENDERED)"
  56. RIGHT_PROMPT_RENDERED_stripped="$(eval echo -e $RIGHT_PROMPT_RENDERED_stripped 2>/dev/null)"
  57. printf "\033[50D\033[$((${COLUMNS:-$(tput cols)}-${#RIGHT_PROMPT_RENDERED_stripped}))C$RIGHT_PROMPT_RENDERED\n"
  58. }
  59. starship_precmd_user_func="right_prompt"
  60. eval "$(starship init bash)"
  61. # Prepare LC_ALL for correct fonts rendering in tmux
  62. export LC_ALL=en_US.UTF-8
  63. export LANG=ru_RU.UTF-8
  64. # auto into tmux session
  65. if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
  66. tmux attach || tmux
  67. fi