dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

.bashrc (2312B) [raw]


      1 #!/usr/bin/env bash
      2 # .bashrc
      3 # The way I like to roll in the shell
      4 
      5 # If not running interactively, don't do anything
      6 [[ $- != *i* ]] && return
      7 
      8 # Functions
      9 include() { [ -r "$1" ] && source "$1"; }
     10 aw()  { w3m "https://wiki.archlinux.org/index.php?search=$1"; }
     11 ddg() { w3m "https://duckduckgo.com/lite?q=$1"; }
     12 last_err() {
     13     err="$?"
     14     if [ $err -ne "0" ]; then
     15         echo "($err) "
     16     fi
     17 }
     18 
     19 # Load ~/.shrc from $ENV (similar to sh(1)'s init)
     20 include "$ENV"
     21 
     22 # Settings / Shell Variables
     23 stty -ixon             # Disable XON/XOFF to allow forward search w CTRL-S
     24 shopt -s checkwinsize  # check win size after each cmd, update if needed
     25 shopt -s histappend    # append to the history file, don't overwrite it
     26 shopt -s direxpand     # expand variables in directory names
     27 HISTSIZE=10000         # Max lines in history (in memory)
     28 HISTFILESIZE=200000    # Max size of the history file
     29 HISTIGNORE=fg:pwd:ls   # Don't store common commands in history
     30 HISTCONTROL=ignoreboth # Don't store duped / whitespace-led commands in history
     31 PROMPT_COMMAND="history -a" # Record history after each command
     32 
     33 if [ -n "$PRETTY_COLORS" ]; then
     34     # ls colors
     35     if ls --color &>/dev/null; then
     36         alias ls='ls --color'
     37     elif ls -G &>/dev/null; then
     38         alias ls='ls -G'
     39     elif colorls -G &>/dev/null; then
     40         alias ls='colorls -G'
     41     fi
     42 
     43     parse_git_dirty() {
     44         if [ -z "$BASH_PROMPT_NO_GSTATUS" ]; then
     45             [ -n "$(git status --porcelain=v1 2>/dev/null)" ] && echo "*"
     46         fi
     47     }
     48 
     49     git_info() {
     50         echo " $(git branch --show-current 2>/dev/null)$(parse_git_dirty)"
     51     }
     52 
     53     # Preferred Prompt: fancy with colors from tput
     54     if tput setaf 1 &> /dev/null; then
     55         tput sgr0 # reset effects of test command
     56         RED="\[$(tput setaf 1)\]"
     57         MAGENTA="\[$(tput setaf 5)\]"
     58         YELLOW="\[$(tput setaf 3)\]"
     59         GRAY="\[$(tput setaf 8)\]"
     60         BLUE="\[$(tput setaf 4)\]"
     61         BOLD="\[$(tput bold)\]"
     62         RESET="\[$(tput sgr0)\]"
     63 
     64         PS1_TOP="$BOLD$RED\$(last_err)$BLUE\w $RESET$GRAY[\u@\h]\$(git_info)"
     65         PS1="$PS1_TOP\n$BOLD$MAGENTA\$ $RESET"
     66         PS2="$YELLOW> $RESET"
     67     else
     68         PS1="\$(last_err)\w [\u@\h]\$(git_info)\n\$ "
     69     fi
     70 fi
     71 
     72 # Include .local version last as override mechanism
     73 include "$HOME/.bashrc.local"