.bashrc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/bash
  2. # ~/.bashrc
  3. #
  4. # If not running interactively, don't do anything
  5. [[ $- != *i* ]] && return
  6. # TODO: Fix
  7. # # Bash options
  8. # shopt -s histappend
  9. # # Auto append history
  10. # PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  11. # Add local bin to path if it exists
  12. [[ -d $HOME/.local/bin ]] && PATH="$PATH:$HOME/.local/bin"
  13. # Load tmux t-smart-tmux-session-manager
  14. # [[ -d $HOME/.config/tmux/plugins/t-smart-tmux-session-manager/bin ]] && PATH="$PATH:$HOME/.config/tmux/plugins/t-smart-tmux-session-manager/bin"
  15. # Load starship prompt if starship is installed:
  16. command -v starship >/dev/null && eval "$(starship init bash)"
  17. # Load zoxide if installed:
  18. command -v zoxide >/dev/null && eval "$(zoxide init bash)"
  19. # Load Mcfly history lookup plugin if installed:
  20. command -v mcfly >/dev/null && eval "$(mcfly init bash)"
  21. # Autocompletion
  22. # init talosctl
  23. command -v talosctl >/dev/null && eval "$(talosctl completion bash)"
  24. # init cilium
  25. command -v cilium >/dev/null && eval "$(cilium completion bash)"
  26. # init hubble
  27. command -v hubble >/dev/null && eval "$(hubble completion bash)"
  28. # Advanced command-not-found hook
  29. [[ -f /usr/share/doc/find-the-command/ftc.bash ]] && source /usr/share/doc/find-the-command/ftc.bash
  30. ## Run fastfetch, neofetch or screenfetch
  31. if command -v fastfetch &>/dev/null; then
  32. fastfetch --load-config neofetch.jsonc
  33. elif command -v neofetch &>/dev/null; then
  34. neofetch
  35. elif command -v screenfetch &>/dev/null; then
  36. screenfetch
  37. fi
  38. # Pyenv config
  39. [[ -d "$HOME/.pyenv" ]] && export PYENV_ROOT="$HOME/.pyenv"
  40. command -v pyenv >/dev/null && export PATH="$PYENV_ROOT/bin:$PATH"
  41. command -v pyenv >/dev/null && eval "$(pyenv init -)"
  42. command -v pyenv >/dev/null && eval "$(pyenv virtualenv-init -)"
  43. # Cargo config
  44. [[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
  45. # Init custom scripts
  46. [[ -f "$HOME/.config/scripts/_aliases" ]] && source "$HOME/.config/scripts/_aliases"
  47. [[ -f "$HOME/.config/scripts/_secrets" ]] && source "$HOME/.config/scripts/_secrets"
  48. # Load exceutable scripts and add to PATH
  49. [[ -d "$HOME/.config/scripts" ]] && PATH="$PATH:$HOME/.config/scripts"
  50. # Kubectl aliases based on shell
  51. # Based on https://github.com/ahmetb/kubectl-aliases
  52. [[ -f "$HOME/.config/scripts/kubectl-aliases/.kubectl_aliases" ]] && source "$HOME/.config/scripts/kubectl-aliases/.kubectl_aliases"
  53. # Set trucolor
  54. export COLORTERM=truecolor
  55. # wakatime for bash
  56. #
  57. # include this file in your "~/.bashrc" file with this command:
  58. # . path/to/bash-wakatime.sh
  59. #
  60. # or this command:
  61. # source path/to/bash-wakatime.sh
  62. #
  63. # Don't forget to create and configure your "~/.wakatime.cfg" file.
  64. # hook function to send wakatime a tick
  65. pre_prompt_command() {
  66. version="1.0.0"
  67. entity=$(echo $(fc -ln -0) | cut -d ' ' -f1)
  68. [ -z "$entity" ] && return # $entity is empty or only whitespace
  69. $(git rev-parse --is-inside-work-tree 2>/dev/null) && local project="$(basename $(git rev-parse --show-toplevel))" || local project="Bash"
  70. (wakatime-cli --write --plugin "bash-wakatime/$version" --entity-type app --project "$project" --entity "$entity" 2>&1 >/dev/null &)
  71. }
  72. command -v wakatime-cli >/dev/null && PROMPT_COMMAND="pre_prompt_command; $PROMPT_COMMAND"
  73. function start_tmux() {
  74. if ! command -v tmux &>/dev/null; then
  75. # Check if tmux is installed
  76. # if not, exit function
  77. return
  78. fi
  79. if [[ "$TERM_PROGRAM" = @(vscode) || -n "$NVIM" || -n "$FLOATERM" ]]; then
  80. # Check if terminal inside an IDE
  81. IN_IDE=1
  82. fi
  83. if [[ -n "$SSH_CONNECTION" || -n "$SSH_CLIENT" || -n "$SSH_TTY" || -n "$KONSOLE_DBUS_SESSION" ]]; then
  84. # $SSH_* - Check if inside a SSH session
  85. # If so, do not enter a tmux session and exit function
  86. # $KONSOLE_DBUS_SESSION - Check if inside a Konsole session
  87. # Since Konsole is assumed to not be the default terminal app
  88. # Whenever a integrated terminal opens within a KDE framework app
  89. # exit function
  90. if [[ -z "$IN_IDE" ]]; then
  91. # If inside IDE, ignore
  92. return
  93. fi
  94. # echo "🛑 Inside SSH session, not starting tmux session"
  95. fi
  96. if [[ -n "$TMUX" || "$TERM" = "screen" ]]; then
  97. # Check if already inside tmux or custom variable
  98. # if so, exit function
  99. return
  100. fi
  101. # Attach to tmux session on shell login if tmux is installed
  102. # Set default session name to "main"
  103. tmux_session_name="🐺$(whoami)"
  104. if [[ -n "$IN_IDE" ]]; then
  105. # Check if term is inside an IDE or other environments
  106. folder="$(pwd)"
  107. folder_name="$(basename $folder)"
  108. tmux_session_name="🖥️$folder_name"
  109. fi
  110. # Attach to existing or create a new tmux session
  111. tmux -2 attach -t "$tmux_session_name" || tmux -2 new-session -s "$tmux_session_name"
  112. }
  113. start_tmux