1
0

bashrc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # ~/.bashrc: executed by bash(1) for non-login shells.
  2. #
  3. # Bash history and shell options
  4. #
  5. # if not running interactively, don't do anything
  6. [ -z "$PS1" ] && return
  7. # don't put duplicate lines or lines starting with space in the history.
  8. # See bash(1) for more options
  9. HISTCONTROL=ignoreboth
  10. # append to the history file, don't overwrite it
  11. shopt -s histappend
  12. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  13. HISTSIZE=1000
  14. HISTFILESIZE=2000
  15. # check the window size after each command and, if necessary,
  16. # update the values of LINES and COLUMNS.
  17. shopt -s checkwinsize
  18. # make less more friendly for non-text input files, see lesspipe(1)
  19. #[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  20. # enable programmable completion features (you don't need to enable
  21. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  22. # sources /etc/bash.bashrc).
  23. if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
  24. . /etc/bash_completion
  25. fi
  26. #
  27. # Setting PS1
  28. #
  29. # set variable identifying the chroot you work in (used in the prompt below)
  30. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  31. debian_chroot=$(cat /etc/debian_chroot)
  32. fi
  33. # comment for uncolored terminal
  34. color_prompt=yes
  35. if [ $UID -eq 0 ]; then
  36. USERCOLOR="\[\e[01;31m\]" # Red if running as root
  37. INDICATOR="#"
  38. else
  39. USERCOLOR="\[\e[01;32m\]" # Green otherwise
  40. INDICATOR="$"
  41. fi
  42. if [ $USER = taddeus ]; then
  43. COLORED_USERNAME=
  44. USERNAME=
  45. else
  46. COLORED_USERNAME="$USERCOLOR\u\[\033[01;33m\]@"
  47. USERNAME="\u@"
  48. fi
  49. if [ "$color_prompt" = yes ]; then
  50. PS1="${debian_chroot:+($debian_chroot)}$COLORED_USERNAME\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$INDICATOR "
  51. else
  52. PS1='${debian_chroot:+($debian_chroot)}'"$USERNAME"'\h:\w\$INDICATOR '
  53. fi
  54. unset color_prompt
  55. #
  56. # Aliases
  57. #
  58. # Enable color support for dir listing
  59. if [ -x /usr/bin/dircolors ]; then
  60. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  61. alias ls='ls --color=auto'
  62. alias dir='dir --color=auto'
  63. alias vdir='vdir --color=auto'
  64. alias grep='grep --color=auto'
  65. alias fgrep='fgrep --color=auto'
  66. alias egrep='egrep --color=auto'
  67. fi
  68. # ls shortcuts
  69. alias l='ls -F'
  70. alias ll='ls -AlhF'
  71. alias lla='ls -alhF'
  72. # ssh shortcuts for multivac
  73. alias mvv='mosh mv -p 8051 -- screen -Uxr'
  74. # more alias fancyness
  75. alias cdhere='cd $(realpath $(pwd))'
  76. alias vimdiff='vim -d -c "colorscheme desert"'
  77. alias ydiff='diff -y -W 196 --left-column'
  78. alias avg="awk '{a+=\$1} END{print a/NR}'"
  79. alias json='python -mjson.tool'
  80. alias g='grep'
  81. alias h='help'
  82. alias dc='docker compose'
  83. alias pc='podman compose'
  84. # git shortcuts
  85. alias gs='git status'
  86. alias gd='git diff'
  87. alias ga='git add'
  88. alias gc='git commit'
  89. alias gp='git push'
  90. alias gr='git pull --rebase'
  91. alias grr='git pull --rebase --recurse-submodules'
  92. alias m='make'
  93. # apt shortcuts
  94. alias aps='apt search'
  95. mytime () {
  96. `which time` -f %e $* > /dev/null
  97. }
  98. mkc() {
  99. mkdir -p "$@" && cd "$@"
  100. }
  101. # Run objdump on a file, open in vim with syntax highlighting
  102. dis() {
  103. if [ ! -f "$1" ]; then
  104. echo "dis: file '$1' does not exist"
  105. return
  106. fi
  107. objdump -d $1 | vim -R - "+set ft=dis"
  108. }
  109. # Add an "alert" alias for long running commands. Use like so:
  110. # sleep 10; alert
  111. alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
  112. # syntax-highlighted cat
  113. alias pcat="pygmentize -f terminal256 -O style=native -g"
  114. pless() {
  115. pcat "$@" | less -r
  116. }
  117. moshx() {
  118. local host="$1"
  119. local session="${2:-default}"
  120. mosh -- "$host" sh -c "tmux attach -t '$session' || exec tmux new -s '$session'"
  121. }
  122. #
  123. # Environment
  124. #
  125. export TERM="xterm-256color"
  126. #export LC_ALL="en_US.UTF-8"
  127. #export LANG="$LC_ALL"
  128. export EDITOR=vim
  129. export PATH=$HOME/.local/bin:$PATH:/sbin:/usr/sbin
  130. #
  131. # SSH agent
  132. #
  133. if [ -S "$XDG_RUNTIME_DIR/openssh_agent" ]; then
  134. export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/openssh_agent"
  135. fi
  136. #
  137. # local, installation-specific config
  138. #
  139. [ -f ~/.bashrc_local ] && . ~/.bashrc_local