Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 433aaede3c
Fetching contributors…

Cannot retrieve contributors at this time

324 lines (280 sloc) 8.987 kb
#
# ~/.bashrc
#
# for interactive non-login shells these files are sourced in this order
# /etc/bash.bashrc (a bash compile-time option)
# then ~/.bashrc
# NOTE: Do I need to add 'history -a' to PROMPT_COMMAND to save the command history to disk?
# TODO: Do I need to add something like -
# echo -ne "\033]0;`whoami`@`hostname`\007"
# to set the xterm title?
# TODO: see how alias less='less -r -Q' behaves. It should make less interpret escape codes and not beep at me.
# TODO: Find a way to make the 'K' command work in gvim
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
###############################################################################
# Shell options #
###############################################################################
# correct minor spelling errors for the cd command
shopt -s cdspell
# check that a command saved in the hash table exists before trying to execute
# it, and do a normal path search if not
shopt -s checkhash
# check for any running jobs before exiting an interactive shell
shopt -s checkjobs
# check the window size and update LINES and COLUMNS after each command
shopt -s checkwinsize
# attempt to save all multiple-line commands as the same history entry for
# easier re-editing
shopt -s cmdhist
# include filenames beginning with a . (dot) in pathname expansions
shopt -s dotglob
# enable extended pattern matching
shopt -s extglob
# write shell error messages in the "standard GNU error message format"
shopt -s gnu_errfmt
# append the history list to the file named by $HISTFILE when the shell exits,
# instead of overwriting the file
shopt -s histappend
# allow re-edits on failed history substitutions when readline is being used
shopt -s histreedit
###############################################################################
# Aliases #
###############################################################################
alias ls='ls --color=auto'
# colorized gcc output... eventually check out a program called cope
alias gcc='colorgcc'
# colorized grep output
alias grep='grep --color=auto'
alias g="gvim --remote-silent"
###############################################################################
# Functions #
###############################################################################
# one-line calculator
function calc () {
echo "scale=6;$@" | bc -l ;
}
# colorized pacman search
pacs() {
local CL='\\e['
local RS='\\e[0;0m'
echo -e "$(pacman -Ss "$@" | sed "
/^core/ s,.*,${CL}1;31m&${RS},
/^extra/ s,.*,${CL}0;32m&${RS},
/^community/ s,.*,${CL}1;35m&${RS},
/^[^[:space:]]/ s,.*,${CL}0;36m&${RS},
")"
}
#open a manpage in gvim
vman() {
man "$@" | col -bx | iconv -c | fmt | gvim -c 'set ft=man nomod nolist' -;
}
# fix a side effect of setting colors for less
# where it would make the 'env' command show variables
# in different colors
function env() {
exec /usr/bin/env "$@" | grep -v ^LESS_TERMCAP_
}
#
# Zenburn color scheme for the linux console
#
function zenburn {
if [ "$TERM" = "linux" ]; then
echo -en "\e]P01E2320" #black
echo -en "\e]P8709080" #darkgrey
echo -en "\e]P1705050" #darkred
echo -en "\e]P9dca3a3" #red
echo -en "\e]P260b48a" #darkgreen
echo -en "\e]PAc3bf9f" #green
echo -en "\e]P3dfaf8f" #brown
echo -en "\e]PBf0dfaf" #yellow
echo -en "\e]P4506070" #darkblue
echo -en "\e]PC94bff3" #blue
echo -en "\e]P5dc8cc3" #darkmagenta
echo -en "\e]PDec93d3" #magenta
echo -en "\e]P68cd0d3" #darkcyan
echo -en "\e]PE93e0e3" #cyan
echo -en "\e]P7dcdccc" #lightgrey
echo -en "\e]PFffffff" #white
clear #for background artifacting
fi
}
#
# the normal linux color console colors
#
function normalcolors {
if [ "$TERM" = "linux" ]; then
echo -en "\e]P0000000" #black
echo -en "\e]P8555555" #darkgrey
echo -en "\e]P1AA0000" #darkred
echo -en "\e]P9FF5555" #red
echo -en "\e]P200AA00" #darkgreen
echo -en "\e]PA55FF55" #green
echo -en "\e]P3AA5500" #brown
echo -en "\e]PBFFFF55" #yellow
echo -en "\e]P40000AA" #darkblue
echo -en "\e]PC5555FF" #blue
echo -en "\e]P5AA00AA" #darkmagenta
echo -en "\e]PDFF55FF" #magenta
echo -en "\e]P600AAAA" #darkcyan
echo -en "\e]PE55FFFF" #cyan
echo -en "\e]P7AAAAAA" #lightgrey
echo -en "\e]PFFFFFFF" #white
clear #for background artifacting
fi
}
#
# phrakture's color scheme for the linux console
#
function phrakture {
if [ "$TERM" = "linux" ]; then
echo -en "\e]P0222222" #black
echo -en "\e]P8222222" #darkgrey
echo -en "\e]P1803232" #darkred
echo -en "\e]P9982b2b" #red
echo -en "\e]P25b762f" #darkgreen
echo -en "\e]PA89b83f" #green
echo -en "\e]P3aa9943" #brown
echo -en "\e]PBefef60" #yellow
echo -en "\e]P4324c80" #darkblue
echo -en "\e]PC2b4f98" #blue
echo -en "\e]P5706c9a" #darkmagenta
echo -en "\e]PD826ab1" #magenta
echo -en "\e]P692b19e" #darkcyan
echo -en "\e]PEa1cdcd" #cyan
echo -en "\e]P7ffffff" #lightgrey
echo -en "\e]PFdedede" #white
clear #for background artifacting
fi
}
#
# sets a color bash prompt
# it looks like the following, depending on the shell environment:
# local xterm: [user|/some/dir:master] ls
# xterm ssh: [user@host|/some/dir:master] ls
# local console: [13:45|user|/some/dir:master] ls
# console ssh: [13:45|user@host|/some/dir:master] ls
# TODO: customize console colors. the current setup looks alright in xterm
#
set_prompt() {
local color_off='\e[0m'
local blue='\e[0;34m'
local green='\e[0;32m'
local red='\e[0;31m'
local purple='\e[0;35m'
local cyan='\e[0;36m'
local iwhite='\e[0;97m'
# Regular Colors
#local black='\e[0;30m'
#local red='\e[0;31m'
#local green='\e[0;32m'
#local yellow='\e[0;33m'
#local blue='\e[0;34m'
#local purple='\e[0;35m'
#local cyan='\e[0;36m'
#local white='\e[0;37m'
# Bold
#local bblack='\e[1;30m'
#local bred='\e[1;31m'
#local bgreen='\e[1;32m'
#local byellow='\e[1;33m'
#local bblue='\e[1;34m'
#local bpurple='\e[1;35m'
#local bcyan='\e[1;36m'
#local bwhite='\e[1;37m'
# High Intensty
#local iblack='\e[0;90m'
#local ired='\e[0;91m'
#local igreen='\e[0;92m'
#local iyellow='\e[0;93m'
#local iblue='\e[0;94m'
#local ipurple='\e[0;95m'
#local icyan='\e[0;96m'
#local iwhite='\e[0;97m'
# Bold High Intensty
#local biblack='\e[1;90m'
#local bired='\e[1;91m'
#local bigreen='\e[1;92m'
#local biyellow='\e[1;93m'
#local biblue='\e[1;94m'
#local bipurple='\e[1;95m'
#local bicyan='\e[1;96m'
#local biwhite='\e[1;97m'
local outer_color=$iwhite
#
# put the current (24 hour) time in HH:MM:SS format in the prompt when
# not in an X session
#
time_prompt() {
local time_color=$purple
if [ -z $DISPLAY ]
then
echo "\[$color_off\]\[$time_color\]\t\[$outer_color\]|\[$color_off\]"
fi
}
#
# put the user name in the prompt when running locally, otherwise
# put user@hostname in the prompt
# is it better to check $SSH_TTY?
#
user_prompt() {
local user_color=$cyan
echo "\[$color_off\]\[$user_color\]"
if [ -n "${SSH_CLIENT+x}" ]
then
echo "\u@\h"
else
echo "\u"
fi
echo "\[$outer_color\]|\[$color_off\]"
}
#
# put the current directory in the prompt
# when running in a console abbreviate the path
#
dir_prompt() {
local dir_color=$blue
if [ $DISPLAY ]
then
PROMPT_DIRTRIM=2
fi
echo "\[$color_off\]\[$dir_color\]\w\[$color_off\]"
}
#
# when inside a git repository directory, display the currently active branch
# the branch is colored red when there are changed files not yet committed, or
# green when there are no changes to be committed
# TODO: i read something about this being built into bash-completion
git_prompt() {
#determine if the current directory is a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
local git_dirty=$red
local git_clean=$green
local git_color
#get the current branch
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
#set the branch color green if clean, red if dirty
if git diff --quiet 2>/dev/null >&2; then
git_color=$git_clean
else
git_color=$git_dirty
fi
echo "\[$outer_color\]:\[$git_color\]$git_branch\[$color_off\]"
}
#
# a hack that sets part of the prompt so that my PS1 line would not be
# 200-something characters
#
inner_prompt() {
echo $(user_prompt)$(dir_prompt)$(git_prompt)
}
PS1="\[$outer_color\][$(time_prompt)$(inner_prompt)\[$outer_color\]]\[$color_off\] "
}
PROMPT_COMMAND=set_prompt
# prevent screen from turning off when not working in X
if [ -z $DISPLAY ]
then
setterm -blank 0 -powerdown 0
fi
Jump to Line
Something went wrong with that request. Please try again.