Created
April 3, 2014 17:48
-
-
Save dbb/9959235 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env zsh | |
# Options ################################################################### | |
cp_options='-iv' | |
editor="$EDITOR" | |
push_options="-u origin master" | |
commit_message="Update $gitfile" | |
# End Options ############################################################### | |
# Vars ###################################################################### | |
action="$1" | |
file="$2" | |
# Files | |
if [[ -f $file ]]; then | |
fullpath=$( readlink -f $file ) | |
gitfile="${fullpath#${HOME}/}" | |
else | |
print "Error: Must supply valid filename." | |
action="help" | |
fi | |
# Directory | |
if [[ -n $GITHOME ]]; then | |
dest="$GITHOME" | |
else | |
dest="~/githome" | |
fi | |
[[ ! -d $dest ]] && mkdir -pv $dest | |
# End Vars ################################################################## | |
# Functions ################################################################# | |
gitadd () { | |
print "cd $dest" | |
print "git add $gitfile" | |
print "git commit -m \"Update $gitfile\"" | |
print "git push $push_options" | |
} | |
help () { | |
print "Usage: githome [action] [file]" | |
print "\nActions:" | |
print "add\tCopy local file to git repo" | |
print "ed\tEdit local file, then add to git" | |
print "in\tInstall file from git to ~" | |
} | |
# End Functions ############################################################## | |
case "$action" in | |
add) | |
print "cp $cp_options \"$file\" \"${dest}/${gitfile}\"" | |
gitadd | |
;; | |
ed) | |
if [[ ! -f $( which $editor ) ]]; then | |
print "Error: must supply valid editor." | |
which $editor | |
action="help" | |
fi | |
print "$editor $file && cp -v \"$file\" \"${GITHOME}/${gitfile}\"" | |
;; | |
*) | |
help | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment