Last active
April 12, 2017 15:30
-
-
Save codyzu/7428c100c0a37912e5ed to your computer and use it in GitHub Desktop.
.bashrc for arch (antegros)
This file contains 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
# | |
# ~/.bashrc | |
# | |
# If not running interactively, don't do anything | |
[[ $- != *i* ]] && return | |
# improve the path | |
if [ -d "$HOME/bin" ] ; then | |
PATH="$HOME/bin:$PATH" | |
fi | |
if [ -d "$HOME/.local/bin" ] ; then | |
PATH="$HOME/.local/bin:$PATH" | |
fi | |
# make ls and tree freindly | |
alias ls='ls --color=auto -h' | |
alias ll='ls -la --group-directories-first' | |
alias tree='tree -Csuh' # Nice alternative to 'recursive ls' ... | |
# -> Prevents accidentally clobbering files. | |
alias rm='rm -i' | |
alias cp='cp -i' | |
alias mv='mv -i' | |
alias mkdir='mkdir -p' | |
alias path='echo -e ${PATH//:/\\n}' | |
alias du='du -kh' # Makes a more readable output. | |
alias df='df -kTh' | |
# my default rsync options | |
alias rsync='rsync -ah --stats --progress' | |
#PS1='[\u@\h \W]\$ ' | |
#DO NOT USE RAW ESCAPES, USE TPUT | |
reset=$(tput sgr0) | |
red=$(tput setaf 1) | |
green=$(tput setaf 2) | |
yellow=$(tput setaf 3) | |
blue=$(tput setaf 4) | |
purple=$(tput setaf 5) | |
lightblue=$(tput setaf 6) | |
white=$(tput setaf 7) | |
if [ $(id -u) -eq 0 ]; | |
then # you are root, make the prompt red | |
COLOR_USER=$red | |
else # else light blue | |
COLOR_USER=$lightblue | |
fi | |
#PS1='\[$red\]\u\[$reset\] \[$blue\]\w\[$reset\] \[$red\]\$ \[$reset\]\[$green\] ' | |
PS1='\[$COLOR_USER\]\u\[$reset\]\[$green\]@\h\[$reset\] \[$yellow\]\w\[$reset\] > ' | |
# This will change your title to the last command run, and make sure your history file is always up-to-date: | |
export HISTCONTROL=ignoreboth | |
export HISTIGNORE='history*' | |
export PROMPT_COMMAND='history -a;echo -en "\e]2;";history 1|sed "s/^[ \t]*[0-9]\{1,\} //g";echo -en "\e\\";' | |
# prefor emacs to nano | |
export VISUAL=emacs | |
export EDITOR="$VISUAL" | |
alias more='less' | |
export PAGER=less | |
export LESS='-i -w -z-4 -g -e -M -X -F -R -P%t?f%f \ | |
:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' | |
# LESS man page colors (makes Man pages more readable). | |
export LESS_TERMCAP_mb=$'\E[01;31m' | |
export LESS_TERMCAP_md=$'\E[01;31m' | |
export LESS_TERMCAP_me=$'\E[0m' | |
export LESS_TERMCAP_se=$'\E[0m' | |
export LESS_TERMCAP_so=$'\E[01;44;33m' | |
export LESS_TERMCAP_ue=$'\E[0m' | |
export LESS_TERMCAP_us=$'\E[01;32m' | |
#------------------------------------------------------------- | |
# File & strings related functions: | |
#------------------------------------------------------------- | |
# Find a file with a pattern in name: | |
function ff() { find . -type f -iname '*'"$*"'*' -ls ; } | |
# Find a file with pattern $1 in name and Execute $2 on it: | |
function fe() { find . -type f -iname '*'"${1:-}"'*' \ | |
-exec ${2:-file} {} \; ; } | |
# Find a pattern in a set of files and highlight them: | |
#+ (needs a recent version of egrep). | |
function fstr() | |
{ | |
OPTIND=1 | |
local mycase="" | |
local usage="fstr: find string in files. | |
Usage: fstr [-i] \"pattern\" [\"filename pattern\"] " | |
while getopts :it opt | |
do | |
case "$opt" in | |
i) mycase="-i " ;; | |
*) echo "$usage"; return ;; | |
esac | |
done | |
shift $(( $OPTIND - 1 )) | |
if [ "$#" -lt 1 ]; then | |
echo "$usage" | |
return; | |
fi | |
find . -type f -name "${2:-*}" -print0 | \ | |
xargs -0 egrep --color=always -sn ${case} "$1" 2>&- | more | |
} | |
function swap() | |
{ # Swap 2 filenames around, if they exist (from Uzi's bashrc). | |
local TMPFILE=tmp.$$ | |
[ $# -ne 2 ] && echo "swap: 2 arguments needed" && return 1 | |
[ ! -e $1 ] && echo "swap: $1 does not exist" && return 1 | |
[ ! -e $2 ] && echo "swap: $2 does not exist" && return 1 | |
mv "$1" $TMPFILE | |
mv "$2" "$1" | |
mv $TMPFILE "$2" | |
} | |
function extract() # Handy Extract Program | |
{ | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xvf $1 ;; | |
*.tbz2) tar xvjf $1 ;; | |
*.tgz) tar xvzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "'$1' cannot be extracted via >extract<" ;; | |
esac | |
else | |
echo "'$1' is not a valid file!" | |
fi | |
} | |
# Creates an archive (*.tar.gz) from given directory. | |
function maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } | |
# Create a ZIP archive of a file or folder. | |
function makezip() { zip -r "${1%%/}.zip" "$1" ; } | |
# Make your directories and files access rights sane. | |
function sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;} | |
#--------------------------------------------------------- | |
# NVM init (if it exists) | |
#--------------------------------------------------------- | |
if [ -f /usr/share/nvm/init-nvm.sh ] ; then | |
source /usr/share/nvm/init-nvm.sh | |
fi | |
###-begin-npm-completion-### | |
# | |
# npm command completion script | |
# | |
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc) | |
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm | |
# | |
if type complete &>/dev/null; then | |
_npm_completion () { | |
local words cword | |
if type _get_comp_words_by_ref &>/dev/null; then | |
_get_comp_words_by_ref -n = -n @ -w words -i cword | |
else | |
cword="$COMP_CWORD" | |
words=("${COMP_WORDS[@]}") | |
fi | |
local si="$IFS" | |
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \ | |
COMP_LINE="$COMP_LINE" \ | |
COMP_POINT="$COMP_POINT" \ | |
npm completion -- "${words[@]}" \ | |
2>/dev/null)) || return $? | |
IFS="$si" | |
} | |
complete -o default -F _npm_completion npm | |
elif type compdef &>/dev/null; then | |
_npm_completion() { | |
local si=$IFS | |
compadd -- $(COMP_CWORD=$((CURRENT-1)) \ | |
COMP_LINE=$BUFFER \ | |
COMP_POINT=0 \ | |
npm completion -- "${words[@]}" \ | |
2>/dev/null) | |
IFS=$si | |
} | |
compdef _npm_completion npm | |
elif type compctl &>/dev/null; then | |
_npm_completion () { | |
local cword line point words si | |
read -Ac words | |
read -cn cword | |
let cword-=1 | |
read -l line | |
read -ln point | |
si="$IFS" | |
IFS=$'\n' reply=($(COMP_CWORD="$cword" \ | |
COMP_LINE="$line" \ | |
COMP_POINT="$point" \ | |
npm completion -- "${words[@]}" \ | |
2>/dev/null)) || return $? | |
IFS="$si" | |
} | |
compctl -K _npm_completion npm | |
fi | |
###-end-npm-completion-### | |
#---------------------------------------- | |
# Ruby gems | |
#---------------------------------------- | |
if [ -f "/usr/bin/ruby" ] ; then | |
PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment