Permalink
Browse files

Added a bunch more stuff.

  • Loading branch information...
1 parent 6921f28 commit 2729490f45c53d869370ec51c158d9274fab5503 Ben Alman committed Dec 21, 2011
Showing with 306 additions and 2 deletions.
  1. +7 −0 README.md
  2. +89 −0 bin/dotfiles
  3. +1 −1 bin/isip
  4. +5 −1 bin/pid
  5. +24 −0 bin/serve
  6. +3 −0 link/.bash_profile
  7. +13 −0 link/.bashrc
  8. +14 −0 source/editor.sh
  9. +32 −0 source/file.sh
  10. +6 −0 source/history.sh
  11. +13 −0 source/misc.sh
  12. +9 −0 source/net.sh
  13. +7 −0 source/osx.sh
  14. +83 −0 source/prompt.sh
View
@@ -2,6 +2,13 @@
My linux / OS X dotfiles. This is a work in progress, as I'm currently rebuilding my system!
+## Installation
+`bash <(curl -s https://raw.github.com/cowboy/dotfiles/master/bin/dotfiles)`
+
+## Sources
+<https://github.com/gf3/dotfiles>
+<https://github.com/mathiasbynens/dotfiles/blob/master/.aliases>
+
## License
Copyright (c) 2011 "Cowboy" Ben Alman
Licensed under the MIT license.
View
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
+Initialize dotfiles
+http://benalman.com/
+
+Usage: `basename "$0"`
+
+Copyright (c) 2011 "Cowboy" Ben Alman
+Licensed under the MIT license.
+http://benalman.com/about/license/
+
+HELP
+exit; fi
+
+# Doesn't exist? Clone it!
+if [ ! -d ~/.dotfiles ]; then
+ git clone --recursive git://github.com/cowboy/dotfiles.git ~/.dotfiles
+fi
+
+read -p "This may overwrite existing files in your home directory, are you sure? (Yes/No) " -n 1
+echo
+if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ echo "Operation aborted!"
+ exit
+fi
+
+# Gotta start somewhere.
+cd ~/.dotfiles
+
+# Make sure we have the latest files.
+echo -e "\nChecking git for updates..."
+git pull origin master
+git submodule init
+git submodule update
+
+# Enable dotfile globbing
+shopt -q dotglob
+DOTGLOBOFF=$?
+shopt -s dotglob
+
+# Copy files.
+function do_copy() {
+ if [ ! "$1" ]; then echo "Copying files into home directory..."; return; fi
+ echo "Copying ~/$1."
+ cp "$2" "$3"
+}
+
+# Link files.
+function do_link() {
+ if [ ! "$1" ]; then echo "Linking files into home directory..."; return; fi
+ echo "Linking ~/$1."
+ ln -sf "$2" "$3"
+}
+
+# Copy, link, etc.
+function do_stuff() {
+ echo
+ "do_$1"
+ for FILE in ~/.dotfiles/$1/*; do
+ BASE="$(basename $FILE)"
+ DEST="$HOME/$BASE"
+ REPLY=Y
+ if [[ ! "$ALL" && -e "$DEST" ]]; then
+ read -p "~/$BASE already exists, overwrite? (Yes/No/All) " -n 1
+ echo
+ if [[ "$REPLY" =~ ^[Aa]$ ]]; then
+ ALL=1
+ fi
+ fi
+ if [[ "$REPLY" =~ ^[YyAa]$ ]]; then
+ "do_$1" "$BASE" "$FILE" "$DEST"
+ fi
+ done
+}
+
+ALL=
+do_stuff "copy"
+do_stuff "link"
+
+# Restore dotfile globbing to its previous value
+if [ "$DOTGLOBOFF" ]; then
+ shopt -u dotglob
+fi
+
+# All done!
+source ~/.bash_profile
+
+echo -e "\nAll done!"
View
@@ -16,7 +16,7 @@ http://benalman.com/about/license/
HELP
exit; fi
-IPLIST=$(ifconfig -u | grep -w "inet" | grep -v "127[.]0[.]0[.]1" | cut -d " " -f 2 | sed 's/^ *//;s/ *$//')
+IPLIST=$(ifconfig -a | perl -nle'/inet (\d+\.\d+\.\d+\.\d+)/ && print $1')
if [ "$1" ]; then
if [ "$(echo $IPLIST | grep -w $1)" ]; then
View
@@ -15,4 +15,8 @@ http://benalman.com/about/license/
HELP
exit; fi
-echo $(ps auxww | grep -v "grep $@" | grep -v "pid $@" | grep "$@" | sort | awk '{print $2}')
+if [ ! "$1" ]; then
+ ps -axco pid,tty,user,command | sort -bdfk4
+else
+ echo $(ps -axco pid,tty,user,command | grep -w "$@" | sort | awk '{print $1}')
+fi
View
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
+Serve a file (or the current directory)
+http://benalman.com/
+
+Usage: `basename "$0"` [PORT] [FILE]
+
+If a port isn't specified, use 8080. If a file isn't specified, serve the
+current directory. Once started, open the specified file (or the current
+directory) with the default web browser.
+
+Copyright (c) 2011 "Cowboy" Ben Alman
+Licensed under the MIT license.
+http://benalman.com/about/license/
+
+HELP
+exit; fi
+
+PORT=8080; if [[ "$1" =~ ^[0-9]+$ ]]; then PORT=$1; shift; fi
+FILE=$1
+
+( { sleep 0.5; open "http://localhost:$PORT/$FILE"; } & )
+python -m SimpleHTTPServer $PORT
View
@@ -0,0 +1,3 @@
+if [ -f ~/.bashrc ]; then
+ source ~/.bashrc
+fi
View
@@ -0,0 +1,13 @@
+# Add binaries into the path
+PATH=$PATH:~/.dotfiles/bin/
+export PATH
+
+# Source all files in ~/.dotfiles/source/
+function src() {
+ local FILE
+ for FILE in ~/.dotfiles/source/*; do
+ source "$FILE"
+ done
+}
+
+src
View
@@ -0,0 +1,14 @@
+# Editing
+
+if [[ ! "$SSH_TTY" && "$OSTYPE" =~ ^darwin ]]; then
+ export EDITOR='mate -w'
+ export LESSEDIT='mate -l %lm %f'
+ alias q="mate"
+else
+ export EDITOR=$(type nano pico vi vim 2>/dev/null | sed "s/ .*$//;q")
+ alias q="$EDITOR -w -z"
+fi
+
+export VISUAL="$EDITOR"
+
+alias qs="q ~/.bashrc"
View
@@ -0,0 +1,32 @@
+# Files will be created with these permissions:
+# files 644 -rw-r--r-- (666 minus 022)
+# dirs 755 drwxr-xr-x (777 minus 022)
+umask 022
+
+# Always use color output for `ls`
+if [[ "$OSTYPE" =~ ^darwin ]]; then
+ alias ls="command ls -G"
+else
+ alias ls="command ls --color"
+ export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
+fi
+
+# Directory listing
+alias ll='ls -al'
+alias lsd='ls -l | grep "^d"'
+
+# Easier navigation: .., ..., -
+alias ..='cd ..'
+alias ...='cd ../..'
+alias -- -='cd -'
+
+# File size
+alias fs="stat -f \"%z bytes\""
+
+# Recursively delete `.DS_Store` files
+alias dsstore="find . -name '*.DS_Store' -type f -ls -delete"
+
+# Create a new directory and enter it
+function md() {
+ mkdir -p "$@" && cd "$@"
+}
View
@@ -0,0 +1,6 @@
+# History settings
+
+export HISTCONTROL=erasedups
+export HISTTIMEFORMAT='[%F %T] '
+export HISTSIZE=10000
+export HISTFILESIZE=10000
View
@@ -0,0 +1,13 @@
+# Case-insensitive globbing (used in pathname expansion)
+shopt -s nocaseglob
+
+# Prefer US English and use UTF-8
+export LC_ALL="en_US.UTF-8"
+export LANG="en_US"
+
+#export TERM="xterm-color"
+
+export GREP_OPTIONS='--color=auto'
+
+# Misc shortcuts
+alias g=git
View
@@ -0,0 +1,9 @@
+# IP addresses
+alias wanip="dig +short myip.opendns.com @resolver1.opendns.com"
+alias whois="whois -h whois-servers.net"
+
+# Flush Directory Service cache
+alias flush="dscacheutil -flushcache"
+
+# View HTTP traffic
+alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
View
@@ -0,0 +1,7 @@
+# OSX-only stuff
+if [[ ! "$OSTYPE" =~ ^darwin ]]; then
+ return
+fi
+
+# Trim new lines and copy to clipboard
+alias c="tr -d '\n' | pbcopy"
View
@@ -0,0 +1,83 @@
+# My bash prompt
+#
+# Copyright (c) 2011 "Cowboy" Ben Alman
+# Licensed under the MIT license.
+# http://benalman.com/about/license/
+#
+# Example:
+# [master:AMU][cowboy@Bens-MacBook-Pro:~/.dotfiles]
+# [11:14:45] $
+#
+# Screenshot:
+# http://www.flickr.com/photos/rj3/3959554047/sizes/o/
+
+function prompt_git() {
+ local GITDIR=$(git rev-parse --git-dir 2>/dev/null)
+ local HEADSHA=$(git rev-parse --verify HEAD 2>/dev/null)
+ if [[ "$GITDIR" && "$HEADSHA" ]]; then
+ local BRANCH=$(git branch --no-color 2>/dev/null | awk '/^\*/ { print($2) }')
+ else
+ local BRANCH='(new)'
+ fi
+ local STATUS=$(git status 2>/dev/null | awk 'BEGIN {r=""} /^# Changes to be committed:$/ {r=r "A"}\
+ /^# Changes not staged for commit:$/ {r=r "M"} /^# Untracked files:$/ {r=r "U"} END {print(r)}')
+
+ local OUT=$BRANCH
+ if [ "$STATUS" ]; then
+ OUT=$OUT$3:$2$STATUS
+ fi
+ if [ "$OUT" ]; then
+ OUT=$4[$2$OUT$4]$1
+ fi
+
+ echo $OUT
+}
+
+function prompt_svn() {
+ svn info . 2>/dev/null | awk "/Revision:/ {r=\$2} /Last Changed Rev:/ {c=\$4; printf(\"$4[$2%d$3:$2%d$4]$1\",c,r)}"
+}
+
+function prompt_init() {
+ # ANSI CODES - SEPARATE MULTIPLE VALUES WITH ;
+ #
+ # 0 reset
+ # 1 bold
+ # 4 underline
+ # 7 inverse
+ #
+ # FG BG COLOR
+ # 30 40 black
+ # 31 41 red
+ # 32 42 green
+ # 33 43 yellow
+ # 34 44 blue
+ # 35 45 magenta
+ # 36 46 cyan
+ # 37 47 white
+
+ local TEXT_COLOR
+ local SIGIL_COLOR='37'
+ local BRACKET_COLOR=$SIGIL_COLOR
+
+ if [ "$SSH_TTY" ]; then # connected via ssh
+ TEXT_COLOR=32
+ elif [ "$USER" == "root" ]; then # logged in as root
+ TEXT_COLOR=31
+ else # connected locally
+ TEXT_COLOR=36
+ fi
+
+ local C1='\[\e[0m\]'
+ local C2='\[\e[0;'$TEXT_COLOR'm\]'
+ local C3='\[\e[0;'$SIGIL_COLOR'm\]'
+ local C4='\[\e[0;'$BRACKET_COLOR'm\]'
+
+export PS1="\n\
+\$(prompt_svn '$C1' '$C2' '$C3' '$C4')\
+\$(prompt_git '$C1' '$C2' '$C3' '$C4')\
+$C4[$C2\u$C3@$C2\h$C3:$C2\w$C4]$C1\n\
+$C4[$C2\$(date +%H)$C3:$C2\$(date +%M)$C3:$C2\$(date +%S)$C4]$C1\
+ \\$ "
+}
+
+prompt_init

0 comments on commit 2729490

Please sign in to comment.