Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created April 17, 2012 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larzconwell/2402982 to your computer and use it in GitHub Desktop.
Save larzconwell/2402982 to your computer and use it in GitHub Desktop.
# Options for ZSH
HISTFIL=~/.zshhist
HISTSIZE=1000
SAVEHIST=1000
setopt autocd
setopt appendhistory
unsetopt beep
bindkey -e # eval "$(sed -n 's/^/bindkey /; s/: / /p' /etc/inputrc)"
zstyle :compinstall filename '/home/larz/.zshrc'
autoload -Uz compinit
compinit
setopt inc_append_history # For multiple terminal use
[[ $- != *i* ]] && return # If not running interactively do nothing
# Load RVM in as a function
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
#
# Aliases and exports go here
#
export EDITOR='nano'
[[ ! "$NODE_PATH" =~ '/usr/lib/node_modules' ]] && export NODE_PATH=$NODE_PATH:/usr/lib/node_modules
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias -g less='| less'
alias -g cl='clear'
alias -g clc='clear &&'
alias n='nano -mT 2'
alias reload='source ~/.zshrc'
alias zshrc='n ~/.zshrc'
# Display prompt
PS1='%~:%# '
#
# Custom functions
#
usage() {
if [[ "$@" != '' ]]; then
echo -e "\n $1\n"
echo -e ' Usage:'
echo -e " $1 $2\n"
else
echo -e "\n usage\n"
echo -e ' Usage:'
echo -e " usage <command> <description>\n"
fi
}
print() {
[[ "$@" != "" ]] && echo -e "$@" || usage 'print' '"some example text\\n with a newline char."'
}
delete() {
[[ "$@" != "" ]] && rm -rf '$@' || usage 'delete' '<file/dir>'
}
#
# APT-GET FUNCTIONS
#
install() {
sudo apt-get install "$@"
}
uninstall() {
sudo apt-get purge "$@"
}
update() { sudo apt-get update }
upgrade() { update && sudo apt-get upgrade }
dist-upgrade() { upgrade && sudo apt-get dist-upgrade }
#-GIT FUNCTIONS
github() {
if [[ "$2" != '' ]]; then
# If you have the username and repo
/usr/bin/chromium-browser http://github.com/"$1"/"$2"
elif [[ "$1" != '' ]]; then
# If just the username was given
/usr/bin/chromium-browser http://github.com/"$1"
elif [[ "$@" == '' ]]; then
# If no args are given open your github
/usr/bin/chromium-browser http://github.com/larzconwell
fi
}
ginit() { git init }
gstat() { git status -s }
gdrop() { git fetch origin && git reset --hard origin/master }
gdiff() {
[[ "$@" != '' ]] && git diff "$@" --color-words || git diff --color-words
}
gpull() { git pull }
gbranch() {
[[ "$@" != '' ]] && git checkout -b "$1" || usage 'gbranch' '<branch_name>'
}
gbranchd() {
[[ "$@" != '' ]] && git branch -d "$@"
}
gup() { git checkout master && git pull --rebase }
gupbranch() {
[[ "$@" != '' ]] && git checkout "$1" && git rebase master
}
gcheck() {
[[ "$@" != '' ]] && git checkout "$@"
}
gmerge() {
[[ "$@" != '' ]] && git merge "$@"
}
gclone() {
if [[ ! -d "$2" ]]; then
# Clone folder doesn't exist
if [[ "$2" == "" ]]; then
# Assume it's the users github repo
git clone git@github.com:larzconwell/"$1".git
cd "$1"
git remote add origin git@github.com:larzconwell/"$1".git
else
# Get users repo
git clone git@github.com:"$1"/"$2".git
cd "$2"
git remote add origin git@github.com:"$2"/"$1".git
fi
else
echo "A Clone already exists for this repo..."
fi
}
gadd() {
[[ "$@" != "" ]] && git add "$@" || git add .
}
gcommit() {
if [[ "$@" != "" ]]; then
git commit -m "$@"
else
commit_message=""
vared -cp "==> Enter your commit message:" commit_message
git commit -m "$commit_message"
fi
}
gpush() {
if [[ "$@" != "" ]]; then
git push origin "$@"
else
if [[ "$branch_name" != "" ]]; then
echo "Note: Including previous branch name..."
fi
# Get branch name then push it to that origin
vared -c -p "==> Enter branch name: " branch_name
git push origin "$branch_name"
fi
}
gcompush() {
# Branch first then commit message
if [[ "$@" != "" ]]; then
# Send commit to branch
gcommit "$2"
gpush "$1"
else
# Get commit message then commit it
commit_message=""
vared -c -p "==> Enter your commit message: " commit_message
git commit -m "$commit_message"
if [[ "$branch_name" != "" ]]; then
# Branch name variable already exists, give notice
echo "==> Note: Including previous branch name..."
fi
# Get branch name then push it to that origin
vared -c -p "==> Enter branch name: " branch_name
git push origin "$branch_name"
fi
}
#
# UNIVERSAL EXTRACTION FUNCTION
#
ex() {
if [[ -f "$1" ]]; then
case "$1" in
*.lrz)
lrztar -d "$1"
EXT=.lrz ;;
*.tar.bz2)
tar xjf "$1"
EXT=.tar.bz2 ;;
*.tar.gz)
tar xzf "$1"
EXT=tar.gz ;;
*.tar.xz)
tar Jxf "$1"
EXT=.tar.xz ;;
*.bz2)
bunzip2 "$1"
EXT=.bz2 ;;
*.rar)
rar x "$1"
EXT=.rar ;;
*.gz)
gunzip "$1"
EXT=.gz ;;
*.tar)
tar xf "$1"
EXT=.tar ;;
*.tbz2)
tar xjf "$1"
EXT=.tbz2 ;;
*.tgz)
tar xzf "$1"
EXT=.tgz ;;
*.zip)
unzip "$1"
EXT=.zip ;;
*.Z)
uncompress "$1"
EXT=.Z ;;
*.7z)
7z x "$1"
EXT=.7z ;;
*) sudo echo "'$1' Cannot be extracted..." ;;
esac
rm -rf "$1"
filename=$(basename "$1" $EXT)
[[ -d "$filename" ]] && cd "$filename"
else
usage 'ex' '<file>'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment