Add gcc alias to work around MacOS stupidity
[dotfiles] / .bashrc
1 # ~/.bashrc: executed by bash(1) for non-login shells.
2 cat /dev/null > ~/.bash_history
3
4 # If not running interactively, don't do anything
5 case $- in
6     *i*) ;;
7       *) return;;
8 esac
9
10 # don't put duplicate lines in the history. See bash(1) for more options
11 # don't overwrite GNU Midnight Commander's setting of `ignorespace'.
12 export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
13 # ... or force ignoredups and ignorespace
14 export HISTCONTROL=ignoreboth
15
16 # append to the history file, don't overwrite it
17 shopt -s histappend
18
19 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
20
21 # check the window size after each command and, if necessary,
22 # update the values of LINES and COLUMNS.
23 shopt -s checkwinsize
24
25 # make less more friendly for non-text input files, see lesspipe(1)
26 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
27
28 # set the prompt
29 PS1='\w\$ '
30
31 # set variable identifying the chroot you work in (used in the prompt below)
32 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
33     debian_chroot=$(cat /etc/debian_chroot)
34 fi
35
36 # enable color support of ls and also add handy aliases
37 if [ -x /usr/bin/dircolors ]; then
38     eval "`dircolors -b`"
39     alias ls='ls --color=auto'
40     alias dir='dir --color=auto'
41     alias vdir='vdir --color=auto'
42
43     alias grep='grep --color=auto'
44     alias fgrep='fgrep --color=auto'
45     alias egrep='egrep --color=auto'
46 fi
47
48 alias emacs='emacs -nw'
49 alias serve='python -m SimpleHTTPServer 8080'
50 alias gpg='gpg2'
51 alias gnupg='gnupg2'
52
53 alias gcc='gcc-13'
54 alias cc='gcc-13'
55
56 export SVN_EDITOR=vim
57
58 # Enable programmable completion features (you don't need to enable
59 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
60 # sources /etc/bash.bashrc).
61 if [ -f /etc/bash_completion ]; then
62     . /etc/bash_completion
63 fi
64
65 # Add the ~/bin directory to the path.  This allows you to install simple
66 # binaries by simply moving them into ~/bin.
67 if [ -d $HOME/bin ]; then
68         PATH="$HOME/bin:$PATH"
69         export PATH
70 fi
71
72 # Put $HOME/.cabal/bin on the path. Installing cabal doesn't
73 # automatically put installed packages on the path.
74 if [ -d $HOME/.cabal/bin ]; then
75     PATH="$HOME/.cabal/bin:$PATH"
76     export PATH
77 fi
78
79 # Put /usr/local/bin (where homebrew installs stuff) before /usr/bin on the
80 # path. This means that if a program exists at both locations, calls to that
81 # program will use the homebrew version rather than the system version.
82 PATH="/usr/local/bin:$PATH"
83 export PATH
84
85 # Run a machine-specific bashrc (if it exists).
86 if [ -f $HOME/.bashrc_local ]; then
87         source $HOME/.bashrc_local
88 fi
89
90 # Automatically open screen.
91 # The if statement prevents it from recursing (since screen opens bash).
92 if [ $TERM != screen ] && [ $TERM != screen.xterm-256color ] ; then
93         screen
94 fi
95
96 # Gets a directory named .env or .venv if it exists in the currend directory or any of its parents
97 get_env() {
98   if [ -d "$1/.env" ] ; then
99     echo "$1/.env"
100   else
101     if [ -d "$1/.venv" ] ; then
102       echo "$1/.venv"
103     else
104       if [ -d "$1/.." ] ; then
105         get_env "$1/.."
106       fi
107     fi
108   fi
109 }
110
111 get_absolute_path() {
112   python3 -c "import os; print(os.path.realpath('$1'))"
113 }
114
115 on_prompt() {
116   # Load a virtualenv environment if it exists in a file named .env
117   env_folder=$(get_env $(pwd))
118
119   if [ -d "$env_folder" ] ; then
120     if [[ $VIRTUAL_ENV != $(get_absolute_path $env_folder) ]] ; then
121       echo "Activating env '$env_folder'"
122       source "$env_folder/bin/activate"
123     fi
124   else
125     if [ -d "$VIRTUAL_ENV" ] ; then
126       deactivate
127     fi
128   fi
129 }
130
131 # Call on_prompt() every time the command prompt executes
132 PROMPT_COMMAND=on_prompt
133
134 # Set vi keybindings
135 set -o vi
136
137 # pip should only run if there is a virtualenv currently activated
138 export PIP_REQUIRE_VIRTUALENV=true
139
140 export NVM_DIR="$HOME/.nvm"
141 [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
142 [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion