Last active
March 15, 2019 20:11
-
-
Save simonrad/5897857 to your computer and use it in GitHub Desktop.
A basic shell setup file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Set up custom bash command prompt. | |
| # Default is "\h:\W \u\$ ". | |
| RED="\[\e[0;31m\]" | |
| GREEN="\[\e[0;32m\]" | |
| BLUE="\[\e[0;34m\]" | |
| PLAIN="\[\e[m\]" | |
| PS1="${RED}\u@\h: \w\$ ${PLAIN}" | |
| # Aliases. | |
| alias l='ls -G' | |
| alias la='l -a' | |
| alias ll='l -l' | |
| alias lla='l -la' | |
| alias b='cd ..' | |
| alias pec='echo $?' # print exit code | |
| alias sumlines='pbpaste | python -c "import sys; print sum(float(line) for line in sys.stdin.read().splitlines() if line.strip())"' | |
| alias g='git' | |
| alias gd='git branch; git status; git --no-pager diff' | |
| alias gds='git --no-pager diff --staged' | |
| alias gitnp='git --no-pager' | |
| alias gnp='git --no-pager' | |
| alias gsu='git submodule update --init' | |
| alias gitsha='git rev-parse --verify HEAD' | |
| alias gpr='git pull --rebase' | |
| alias gca='git commit --amend' | |
| alias gs='git stash' | |
| alias gss='git show --stat' | |
| alias gb='git branch' | |
| alias gbv='git branch -vv' | |
| alias grep='grep --color' | |
| # Override the ssh command with a function that copies a bashrc file to the remote machine before running bash. | |
| myssh(){ /usr/bin/ssh -l ubuntu -t $* "curl --silent --show-error 'https://gist.github.com/simonrad/997b6577b326398b2a38/raw' --output /tmp/ssh_override_bashrc_file && /bin/bash --rcfile /tmp/ssh_override_bashrc_file -i"; } | |
| # Pass aliases through sudo. | |
| alias sudo='sudo ' | |
| # Increase bash history size. | |
| export HISTFILESIZE=50000 | |
| export HISTSIZE=50000 | |
| # Make writing to .bash_history immediate. | |
| shopt -s histappend # Append to history, don't overwrite it. | |
| export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" # Append, clear, and reload history. | |
| export EDITOR='nano -w' | |
| # export EDITOR='subl -nw' | |
| # Add to my PATH. | |
| export PATH="/usr/local/bin:/usr/local/sbin:$PATH" | |
| # Enable magical cd abilities. | |
| export CDPATH='.:~/workspace/' | |
| # Git helpers. | |
| alias get_current_git_branch_name='python -c "print \"$(git symbolic-ref HEAD 2>/dev/null)\".split(\"/\",2)[-1] or \"!no_branch!\""' | |
| alias publish_git_branch='git push -u origin $(get_current_git_branch_name)' | |
| alias delete_remote_git_branch='git push origin --delete' | |
| # Enable git autocompletion. | |
| if [ -f ~/.git-completion.bash ]; then | |
| source ~/.git-completion.bash | |
| else | |
| echo "Git autocompletion script (~/.git-completion.bash) not found. Attempting to download it." | |
| curl "https://gist.githubusercontent.com/simonrad/d57469270f78327f2fcf/raw" -o ~/.git-completion.bash | |
| source ~/.git-completion.bash | |
| fi | |
| # Set up virtualenvwrapper. | |
| export WORKON_HOME=$HOME/.virtualenvs | |
| export PROJECT_HOME=$HOME/workspace | |
| source /usr/local/bin/virtualenvwrapper.sh | |
| # Aliases to start and stop the Postgresql server manually. | |
| export PGDATA='/usr/local/var/postgres' | |
| export PGHOST=localhost | |
| alias pgstart='pg_ctl -D $PGDATA -l $PGDATA/server.log start' | |
| alias pgstop='pg_ctl -D $PGDATA stop -s -m fast' | |
| alias pgc='pg_ctl' | |
| # Function to run a command in a new iTerm tab/window. | |
| run_in_new_terminal() { | |
| TEMP_SCRIPT=`mktemp -t run_in_new_terminal` | |
| echo '#!/bin/bash' >> $TEMP_SCRIPT | |
| echo "cd '$PWD'" >> $TEMP_SCRIPT | |
| echo "echo 'Running: $@'" >> $TEMP_SCRIPT | |
| echo "echo" >> $TEMP_SCRIPT | |
| echo "$@" >> $TEMP_SCRIPT | |
| echo "echo" >> $TEMP_SCRIPT | |
| echo "echo 'Done'" >> $TEMP_SCRIPT | |
| echo "read" >> $TEMP_SCRIPT | |
| chmod +x $TEMP_SCRIPT | |
| open -a iTerm.app $TEMP_SCRIPT | |
| } | |
| # Encryption / decryption utilities. | |
| # ---------------------------------- | |
| function set_password_for_encryption { | |
| echo "Please type your password:" | |
| export PASSWORD_FOR_ENCRYPTION=$(cat) | |
| echo "Your password is now \"$PASSWORD_FOR_ENCRYPTION\"." | |
| } | |
| function print_password_for_encryption { | |
| echo "Your password is \"$PASSWORD_FOR_ENCRYPTION\"." | |
| } | |
| function encrypt { | |
| if [ -z "$PASSWORD_FOR_ENCRYPTION" ]; then | |
| echo "Please set your password first, by running set_password_for_encryption" | |
| else | |
| # Reads plaintext from stdin. | |
| # Writes encrypted and base64-encoded cyphertext to stdout. | |
| openssl des -e -aes128 -k "$PASSWORD_FOR_ENCRYPTION" | base64 | |
| fi | |
| } | |
| function decrypt { | |
| if [ -z "$PASSWORD_FOR_ENCRYPTION" ]; then | |
| echo "Please set your password first, by running set_password_for_encryption" | |
| else | |
| # Reads encrypted and base64-encoded cyphertext from stdin. | |
| # Writes plaintext to stdout. | |
| base64 -D | openssl des -d -aes128 -k "$PASSWORD_FOR_ENCRYPTION" | |
| fi | |
| } | |
| # ---------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment