Merge remote branch 'beef/master'

Conflicts:
	install.sh
	lib/scm_breeze.sh
This commit is contained in:
Nathan Broadbent
2011-10-21 08:38:54 +08:00
5 changed files with 15 additions and 14 deletions

View File

@@ -1,6 +1,9 @@
#!/bin/sh #!/bin/sh
#locate the dir where this script is stored
export scmbDir="$(dirname "$0")"
# This loads SCM Breeze into the shell session. # This loads SCM Breeze into the shell session.
exec_string='[ -s "$HOME/.scm_breeze/scm_breeze.sh" ] && . "$HOME/.scm_breeze/scm_breeze.sh"' exec_string="[ -s \"$scmbDir/scm_breeze.sh\" ]] && . \"$scmbDir/scm_breeze.sh\""
# Add line to bashrc and zshrc if not already present. # Add line to bashrc and zshrc if not already present.
for rc in bashrc zshrc; do for rc in bashrc zshrc; do
@@ -11,7 +14,7 @@ for rc in bashrc zshrc; do
done done
# Load SCM Breeze update scripts # Load SCM Breeze update scripts
. "$HOME/.scm_breeze/lib/scm_breeze.sh" . "$scmbDir/lib/scm_breeze.sh"
# Create '~/.*.scmbrc' files from example files # Create '~/.*.scmbrc' files from example files
_create_or_patch_scmbrc _create_or_patch_scmbrc

View File

@@ -7,7 +7,7 @@ _alias $git_alias='git'
# SCM Breeze functions # SCM Breeze functions
_alias $git_status_shortcuts_alias="git_status_shortcuts" _alias $git_status_shortcuts_alias="git_status_shortcuts"
_alias $git_add_shortcuts_alias="git_add_shorcuts" _alias $git_add_shortcuts_alias="git_add_shortcuts"
_alias $exec_git_expand_args_alias="exec_git_expand_args" _alias $exec_git_expand_args_alias="exec_git_expand_args"
_alias $git_show_files_alias="git_show_affected_files" _alias $git_show_files_alias="git_show_affected_files"
_alias $git_commit_all_alias='git_commit_all' _alias $git_commit_all_alias='git_commit_all'

View File

@@ -44,7 +44,7 @@ git_status_shortcuts() {
# Should be used in conjunction with the git_status_shortcuts() function for 'git status'. # Should be used in conjunction with the git_status_shortcuts() function for 'git status'.
# - 'auto git rm' behaviour can be turned off # - 'auto git rm' behaviour can be turned off
# ------------------------------------------------------------------------------- # -------------------------------------------------------------------------------
git_add_shorcuts() { git_add_shortcuts() {
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Usage: ga <file> => git add <file>" echo "Usage: ga <file> => git add <file>"
echo " ga 1 => git add \$e1" echo " ga 1 => git add \$e1"
@@ -55,13 +55,13 @@ git_add_shorcuts() {
echo " To turn off this behaviour, change the 'auto_remove' option." echo " To turn off this behaviour, change the 'auto_remove' option."
fi fi
else else
git_silent_add_shorcuts "$@" git_silent_add_shortcuts "$@"
# Makes sense to run 'git status' after this command. # Makes sense to run 'git status' after this command.
git_status_shortcuts git_status_shortcuts
fi fi
} }
# Does nothing if no args are given. # Does nothing if no args are given.
git_silent_add_shorcuts() { git_silent_add_shortcuts() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
# Expand args and process resulting set of files. # Expand args and process resulting set of files.
for file in $(git_expand_args "$@"); do for file in $(git_expand_args "$@"); do
@@ -103,9 +103,7 @@ git_expand_args() {
if [[ "$arg" =~ ^[0-9]+$ ]] ; then # Substitute $e{*} variables for any integers if [[ "$arg" =~ ^[0-9]+$ ]] ; then # Substitute $e{*} variables for any integers
files="$files $(eval echo \$$git_env_char$arg)" files="$files $(eval echo \$$git_env_char$arg)"
elif [[ $arg =~ ^[0-9]+\.\.[0-9]+$ ]]; then # Expand ranges into $e{*} variables elif [[ $arg =~ ^[0-9]+\.\.[0-9]+$ ]]; then # Expand ranges into $e{*} variables
for i in $(seq $(echo $arg | tr ".." " ")); do files="$files $(eval echo \$$git_env_char{$arg})"
files="$files $(eval echo \$$git_env_char$i)"
done
else # Otherwise, treat $arg as a normal string. else # Otherwise, treat $arg as a normal string.
# If arg contains any spaces, (re)wrap it in double quotes # If arg contains any spaces, (re)wrap it in double quotes
if echo $arg | grep -q " "; then arg="\"$arg\""; fi if echo $arg | grep -q " "; then arg="\"$arg\""; fi
@@ -180,7 +178,7 @@ git_commit_all() {
# Add paths or expanded args if any given, then commit all staged changes. # Add paths or expanded args if any given, then commit all staged changes.
git_add_and_commit() { git_add_and_commit() {
git_silent_add_shorcuts "$@" git_silent_add_shortcuts "$@"
changes=$(git diff --cached --numstat | wc -l) changes=$(git diff --cached --numstat | wc -l)
if [ "$changes" -gt 0 ]; then if [ "$changes" -gt 0 ]; then
git_status_shortcuts 1 # only show staged changes git_status_shortcuts 1 # only show staged changes

View File

@@ -30,7 +30,7 @@ _create_or_patch_scmbrc() {
for scm in git; do for scm in git; do
# Create file from example if it doesn't already exist # Create file from example if it doesn't already exist
if ! [ -e "$HOME/.$scm.scmbrc" ]; then if ! [ -e "$HOME/.$scm.scmbrc" ]; then
cp "$HOME/.scm_breeze/$scm.scmbrc.example" "$HOME/.$scm.scmbrc" cp "$scmbDir/$scm.scmbrc.example" "$HOME/.$scm.scmbrc"
printf "== '~/.$scm.scmbrc' has been created. Please edit this file to change SCM Breeze settings for '$scm'.\n" printf "== '~/.$scm.scmbrc' has been created. Please edit this file to change SCM Breeze settings for '$scm'.\n"
# If file exists, attempt to update it with any new settings # If file exists, attempt to update it with any new settings
elif [ -n "$1" ]; then elif [ -n "$1" ]; then

View File

@@ -199,7 +199,7 @@ test_git_status_shortcuts_max_changes() {
# Add 5 untracked files # Add 5 untracked files
touch a b c d e touch a b c d e
git_status=$(git_status_shortcuts | strip_colors) git_status=$(git_status_shortcuts | strip_colors)
for i in $(seq 1 5); do for i in {1..5}; do
assertIncludes "$git_status" "\[$i\]" || return assertIncludes "$git_status" "\[$i\]" || return
done done
@@ -212,13 +212,13 @@ test_git_status_shortcuts_max_changes() {
} }
test_git_add_shorcuts() { test_git_add_shortcuts() {
setupTestRepo setupTestRepo
touch a b c d e f g h i j touch a b c d e f g h i j
# Show git status, which sets up env variables # Show git status, which sets up env variables
git_status_shortcuts > /dev/null git_status_shortcuts > /dev/null
git_add_shorcuts 2..4 7 8 > /dev/null git_add_shortcuts 2..4 7 8 > /dev/null
git_status=$(git_status_shortcuts 1 | strip_colors) git_status=$(git_status_shortcuts 1 | strip_colors)
for c in b c d g h; do for c in b c d g h; do