Skip to content

Commit

Permalink
initial commit with support for generic and spike bash dotfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Apr 4, 2014
0 parents commit 3f04657
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Makefile
@@ -0,0 +1,60 @@
#
# Makefile for simple dotfiles. We make dotfiles for several different
# TARGETS (e.g., "my_laptop", "work_laptop", "generic", and so on). Each
# dotfiles consists of concatenating dotfiles from one of several source GROUPS
# (e.g., "base", "work", "macos", and so on).
#
# You configure this by updating
#

.DEFAULT_GOAL: all



#
# For each new set of dotfiles (a TARGET), you'll want to set:
#
# DOTFILES_$target relative paths to dotfiles you want to create
#
# SOURCES_$target names of source groups whose dotfiles will be
# concatenated to produce each target dotfile
#
# You'll also want to:
#
# - update ALLDOTFILES as shown below.
#
# - define a target as shown below, under Targets
#
DOTFILES_spike = .bashrc .bash_profile
SOURCES_spike = base joyent
ALLDOTFILES += $(DOTFILES_spike:%=$(OUTDIR)/spike/%)
out/spike/%: force
./mkdotfile $* out/spike $(SOURCES_spike)

DOTFILES_sharptooth = .bashrc .bash_profile
SOURCES_sharptooth = base joyent sharptooth
ALLDOTFILES += $(DOTFILES_sharptooth:%=$(OUTDIR)/sharptooth/%)
out/sharptooth/%: force
./mkdotfile $* out/sharptooth $(SOURCES_sharptooth)

DOTFILES_generic = .bashrc .bash_profile
SOURCES_generic = base
ALLDOTFILES += $(DOTFILES_generic:%=$(OUTDIR)/generic/%)
out/generic/%: force
./mkdotfile $* out/generic $(SOURCES_generic)

#
# You shouldn't need to modify anything below this line.
#

# Global configuration
OUTDIR = out

# Targets
all: $(ALLDOTFILES)

clean:
rm -rf $(OUTDIR)

.PHONY: force
force:
2 changes: 2 additions & 0 deletions base/.bash_profile
@@ -0,0 +1,2 @@
[[ -e ~/.profile ]] && . ~/.profile
[[ -e ~/.bashrc ]] && . ~/.bashrc
131 changes: 131 additions & 0 deletions base/.bashrc
@@ -0,0 +1,131 @@
#
# bashrc settings
# Dave Pacheco (dap)
#

#
# path_append DIR: appends DIR to path only if it exists
#
function path_append
{
[[ -d "$1" ]] || return
export PATH="$PATH:$1"
}

#
# titlebar [args...]: set the window title bar to the specified string
#
# Updates PS1 to avoid resetting titlebar with each prompt. This is provided
# for use interactively or from other scripts.
#
function titlebar
{
[[ -n $RAWPS1 ]] && export PS1="$RAWPS1"
echo -n -e "\033]0;$@\007"
}

#
# MISCELLANEOUS GLOBAL ENVIRONMENT VARIABLES AND PATHS
#
export HOST=$(basename $(uname -n) .local)
export MACH=$(uname -p)
export PATH=

# Prefer my own versions of tools to copies installed elsewhere.
path_append $HOME/bin
path_append $HOME/install/bin

# SmartOS pkgsrc
path_append /opt/local/bin
path_append /opt/local/sbin

# OS X pkgsrc
path_append /usr/pkg/bin
path_append /usr/pkg/sbin

# System tools
path_append /bin
path_append /sbin
path_append /usr/bin
path_append /usr/sbin

# Locally installed tools
path_append /usr/local/bin
path_append /usr/local/sbin


#
# Non-interactive command customizations
#
export TZ=US/Pacific # San Francisco
export MACHINE_THAT_GOES_PING=1 # use "ping -s" by default
export BUNYAN_NO_PAGER=1 # don't page by default

export MANTA_URL=https://us-east.manta.joyent.com
export MANTA_USER=dap
export MANTA_KEY_ID="56:f3:e1:56:3d:e6:f7:83:a9:ce:19:5d:62:ba:5c:1f"
export SDC_URL=https://us-west-1.api.joyentcloud.com
export SDC_ACCOUNT=$MANTA_USER
export SDC_KEY_ID=$MANTA_KEY_ID

#
# Interactive behavior
#
if [[ -n $PS1 ]]; then
#
# On supporting terminals, set TITLEBAR to a sequence that replaces the
# current title bar text with "<directory> (<host>)". We'll set the PS1
# prompt to include this string so that we always update the title bar
# with the current directory.
#
case $TERM in
rxvt*|xterm*|sun*)
TITLEBAR='\[\033]0;\w (\h)\007\]'
;;
*)
TITLEBAR=''
;;
esac

#
# RAWPS1 represents the actual text that shows up in the prompt (PS1).
# The actual value of PS1 includes TITLEBAR, which sets the window's
# title bar text. RAWPS1 exists so that we can keep the prompt text the
# same if we later change the title bar text. See the titlebar()
# function above.
#
_BOLD="`tput bold 2>/dev/null`" # start printing bold text
_SGR0="`tput sgr0 2>/dev/null`" # stop printing bold text
export RAWPS1="\u@${HOST} \[${_BOLD}\]\W\[${_SGR0}\] $ "
export PS1="${TITLEBAR}$RAWPS1"

#
# Miscellaneous shell and command tweaks
#
shopt -s checkwinsize # check window size after each command

export EDITOR=vim # use 'vim' to edit
export VISUAL=vim # use 'vim' to edit
export PAGER=less # use 'less' to page
export LESS='-P ?f%f .line %lb/%L .byte %bB?s/%s. ?e(END):?pB%pB\%..%t'
export CSCOPEOPTIONS="-r -p8" # show more results per page

alias mv='mv -i' # conservative 'mv' by default
alias cp='cp -i' # conservative 'cp' by default
alias mls="mls -l"

#
# We want ls(1) to use colors, but this isn't supported everywhere and
# even where it is, the mechanism differs between systems.
#
if ls -d --color=auto / > /dev/null 2>&1; then
# GNU
alias ls="ls -lHF --color=auto"
elif ls -dG / > /dev/null 2>&1; then
# newer Solaris
alias ls="ls -lHFG"
else
# older Solaris
alias ls="ls -lHF"
fi
fi
27 changes: 27 additions & 0 deletions joyent/.bashrc
@@ -0,0 +1,27 @@
#
# On work dev systems, add marlin and manta tools to the PATH.
#
path_append $HOME/work/marlin/client/sbin
path_append $HOME/work/marlin/node_modules/moray/bin
path_append $HOME/work/tools/node-manta/bin

# On work systems, we always use thoth user "thoth".
export THOTH_USER=thoth

# Dev tool configuration (assumes local Moray tunnel)
export MORAY_URL=tcp://127.0.0.1:2020/

#
# Interactive behavior
#
if [[ -n $PS1 ]]; then
function ilcs
{
(cd $HOME/work/reference/illumos-joyent/usr/src; cscope -dqp8)
}

function cph
{
awk 'NR<3 && /us-east-'$1'/{print $2}' $HOME/Manta/p | pbcopy
}
fi
56 changes: 56 additions & 0 deletions mkdotfile
@@ -0,0 +1,56 @@
#!/bin/bash

#
# mkdotfile DOTFILE_PATH TARGET_NAME GROUP_NAME1 ...: construct dotfile
# DOTFILE_PATH for target TARGET_NAME by concatenating the dotfiles from each of
# the named groups.
#

arg0=$(basename $0)

function fail
{
echo "$arg0: $@" >&2
exit 1
}

if [[ $# -lt 3 ]]; then
echo "usage: $arg0 DOTFILE_PATH TARGET_NAME GROUP_NAME1 ..." >&2
echo "construct a dotfile for TARGET_NAME from the given groups." >&2
exit 2
fi

md_dotfile="$1"
md_target="$2"
md_finalfile="$md_target/$md_dotfile"
md_tmpfile="$md_finalfile.tmp"
shift 2

mkdir -p "$(dirname "$md_finalfile")" || fail "mkdir failed"
cat >> $md_tmpfile << EOF || fail "failed to create \"$md_tmpfile\""
#
# file auto-generated by $arg0 on $(date)
EOF

for group in "$@"; do
groupfile="$group/$md_dotfile"
if ! [[ -f $groupfile ]]; then
echo "skip: $groupfile (not a file)" >&2
continue
fi

cat >> $md_tmpfile <<-EOF
# begin include from $groupfile
#
EOF

cat $groupfile >> $md_tmpfile

cat >> $md_tmpfile <<-EOF
#
# end include from $groupfile
EOF
done

echo "#" >> $md_tmpfile
mv $md_tmpfile $md_finalfile

0 comments on commit 3f04657

Please sign in to comment.