Merge branch 'master' of git://github.com/ndbroadbent/scm_breeze
This commit is contained in:
@@ -24,9 +24,9 @@ if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi
|
||||
|
||||
# Create 'git' function that calls hub if defined, and expands all numeric arguments
|
||||
function git(){
|
||||
# Only expand args for a subset of git commands
|
||||
# Only expand args for git commands that deal with paths or branches
|
||||
case $1 in
|
||||
checkout|commit|reset|rm|blame|diff|add|log)
|
||||
checkout|commit|rm|blame|diff|add|log|rebase)
|
||||
exec_scmb_expand_args "$_git_cmd" "$@";;
|
||||
branch)
|
||||
_scmb_git_branch_shortcuts "${@:2}";;
|
||||
@@ -94,6 +94,7 @@ if [ "$git_setup_aliases" = "yes" ]; then
|
||||
__git_alias "$git_rm_alias" "git" "rm"
|
||||
__git_alias "$git_blame_alias" "git" "blame"
|
||||
__git_alias "$git_diff_alias" "git" "diff"
|
||||
__git_alias "$git_diff_word_alias" "git" "diff" "--word-diff"
|
||||
__git_alias "$git_diff_cached_alias" "git" "diff" "--cached"
|
||||
__git_alias "$git_add_patch_alias" "git" "add" "-p"
|
||||
# Custom default format for git log
|
||||
@@ -106,6 +107,7 @@ if [ "$git_setup_aliases" = "yes" ]; then
|
||||
__git_alias "$git_checkout_branch_alias" "git" 'checkout' "-b"
|
||||
__git_alias "$git_pull_alias" "git" 'pull'
|
||||
__git_alias "$git_push_alias" "git" 'push'
|
||||
__git_alias "$git_push_force_alias" "git" 'push' '-f'
|
||||
__git_alias "$git_status_original_alias" "git" 'status' # (Standard git status)
|
||||
__git_alias "$git_status_short_alias" "git" 'status' '-s'
|
||||
__git_alias "$git_clean_alias" "git" "clean"
|
||||
@@ -119,6 +121,7 @@ if [ "$git_setup_aliases" = "yes" ]; then
|
||||
__git_alias "$git_cherry_pick_alias" "git" 'cherry-pick'
|
||||
__git_alias "$git_show_alias" "git" 'show'
|
||||
__git_alias "$git_show_summary" "git" 'show' '--summary'
|
||||
__git_alias "$git_tag_alias" "git" 'tag'
|
||||
|
||||
|
||||
# Compound/complex commands
|
||||
|
||||
@@ -39,10 +39,11 @@ EOF
|
||||
done
|
||||
}
|
||||
|
||||
alias "$git_branch_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts"
|
||||
alias "$git_branch_all_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -a"
|
||||
alias "$git_branch_move_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -m"
|
||||
alias "$git_branch_delete_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -D"
|
||||
__git_alias "$git_branch_alias" "_scmb_git_branch_shortcuts"
|
||||
__git_alias "$git_branch_all_alias" "_scmb_git_branch_shortcuts" "-a"
|
||||
__git_alias "$git_branch_move_alias" "_scmb_git_branch_shortcuts" "-m"
|
||||
__git_alias "$git_branch_delete_alias" "_scmb_git_branch_shortcuts" "-d"
|
||||
__git_alias "$git_branch_delete_force_alias" "_scmb_git_branch_shortcuts" "-D"
|
||||
|
||||
# Define completions for git branch shortcuts
|
||||
if [ "$shell" = "bash" ]; then
|
||||
@@ -50,4 +51,4 @@ if [ "$shell" = "bash" ]; then
|
||||
__define_git_completion $alias_str branch
|
||||
complete -o default -o nospace -F _git_"$alias_str"_shortcut $alias_str
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -27,11 +27,13 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then
|
||||
# Uses emacs style keybindings, so vi mode is not supported for now
|
||||
if ! set -o | grep -q '^vi .*on$'; then
|
||||
if [[ $shell == "zsh" ]]; then
|
||||
_bind "$git_commit_all_keys" " git_commit_all""\n"
|
||||
_bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n"
|
||||
_bind "$git_commit_all_keys" " git_commit_all""\n"
|
||||
_bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n"
|
||||
_bind "$git_commit_all_with_ci_skip_keys" " \033[1~ APPEND='[ci skip]' git_commit_all ""\n"
|
||||
else
|
||||
_bind "$git_commit_all_keys" "\" git_commit_all\n\""
|
||||
_bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\""
|
||||
_bind "$git_commit_all_keys" "\" git_commit_all\n\""
|
||||
_bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\""
|
||||
_bind "$git_commit_all_with_ci_skip_keys" "\"\033[1~ APPEND='[ci skip]' git_commit_all \n\""
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -217,10 +217,10 @@ _git_index_update_all_branches() {
|
||||
|
||||
# Ignore branch if remote and merge is not configured
|
||||
if [[ -n "$remote" ]] && [[ -n "$merge" ]]; then
|
||||
branches=("${branches[@]}" "$branch")
|
||||
remotes=("${remotes[@]}" "$remote")
|
||||
branches=(${branches[@]} "$branch")
|
||||
remotes=(${remotes[@]} "$remote")
|
||||
# Get branch from merge ref (refs/heads/master => master)
|
||||
merges=("${merges[@]}" "$(basename $merge)")
|
||||
merges=(${merges[@]} "$(basename $merge)")
|
||||
else
|
||||
echo "=== Skipping $branch: remote and merge refs are not configured."
|
||||
fi
|
||||
|
||||
@@ -11,11 +11,20 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
# Do it in a function so we don't bleed variables
|
||||
function _git_wrap_commands() {
|
||||
# Define 'whence' for bash, to get the value of an alias
|
||||
type whence > /dev/null 2>&1 || function whence() { type "$@" | sed -e "s/.*is aliased to \`//" -e "s/'$//"; }
|
||||
type whence > /dev/null 2>&1 || function whence() { type "$@" | sed -E -e "s/.*is aliased to \`//" -e "s/'$//"; }
|
||||
local cmd=''
|
||||
for cmd in $(echo $scmb_wrapped_shell_commands); do
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: Wrapping $cmd..."; fi
|
||||
|
||||
# Special check for 'cd', to make sure SCM Breeze is loaded after RVM
|
||||
if [ "$cmd" = 'cd' ]; then
|
||||
if [ -e "$HOME/.rvm" ] && ! type rvm > /dev/null 2>&1; then
|
||||
echo -e "\033[0;31mSCM Breeze must be loaded \033[1;31mafter\033[0;31m RVM, otherwise there will be a conflict when RVM wraps the 'cd' command.\033[0m"
|
||||
echo -e "\033[0;31mPlease move the line that loads SCM Breeze to the bottom of your ~/.bashrc\033[0m"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$(type $cmd 2>&1)" in
|
||||
|
||||
# Don't do anything if command already aliased, or not found.
|
||||
@@ -25,34 +34,34 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
*'not found'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi;;
|
||||
|
||||
*'is aliased to'*|*'is an alias for'*)
|
||||
*'aliased to'*|*'is an alias for'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an alias"; fi
|
||||
# Store original alias
|
||||
local original_alias="$(whence $cmd)"
|
||||
# Remove alias, so that which can return binary
|
||||
# Remove alias, so that we can find binary
|
||||
unalias $cmd
|
||||
|
||||
# Detect original $cmd type, and escape
|
||||
case "$(type $cmd 2>&1)" in
|
||||
# Escape shell builtins with 'builtin'
|
||||
*'is a shell builtin'*) local escaped_cmd="builtin $cmd";;
|
||||
# Get full path for files with 'which'
|
||||
*) local escaped_cmd="$(\which $cmd)";;
|
||||
# Get full path for files with 'find_binary' function
|
||||
*) local escaped_cmd="$(find_binary $cmd)";;
|
||||
esac
|
||||
|
||||
# Expand original command into full path, to avoid infinite loops
|
||||
local expanded_alias="$(echo $original_alias | sed "s%\(^\| \)$cmd\($\| \)%\\1$escaped_cmd\\2%")"
|
||||
local expanded_alias="$(echo $original_alias | sed -E "s%(^| )$cmd($| )%\\1$escaped_cmd\\2%")"
|
||||
# Wrap previous alias with escaped command
|
||||
alias $cmd="exec_scmb_expand_args $expanded_alias";;
|
||||
|
||||
*'is a'*'function'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a function"; fi
|
||||
# Copy old function into new name
|
||||
eval "$(declare -f $cmd | sed "s/^$cmd ()/__original_$cmd ()/")"
|
||||
eval "$(declare -f $cmd | sed -E "s/^$cmd \(\)/__original_$cmd ()/")"
|
||||
# Remove function
|
||||
unset -f $cmd
|
||||
# Create wrapped alias for old function
|
||||
alias "$cmd"="exec_scmb_expand_args __original_$cmd";;
|
||||
# Create function that wraps old function
|
||||
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }";;
|
||||
|
||||
*'is a shell builtin'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a shell builtin"; fi
|
||||
@@ -62,8 +71,8 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an executable file"; fi
|
||||
# Otherwise, command is a regular script or binary,
|
||||
# and the full path can be found from 'which'
|
||||
alias $cmd="exec_scmb_expand_args $(\which $cmd)";;
|
||||
# and the full path can be found with 'find_binary' function
|
||||
alias $cmd="exec_scmb_expand_args $(find_binary $cmd)";;
|
||||
esac
|
||||
done
|
||||
# Clean up
|
||||
@@ -122,7 +131,7 @@ function ls_with_file_shortcuts {
|
||||
puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}"
|
||||
}
|
||||
|
||||
ll_output=$(echo "$ll_output" | \sed "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns)
|
||||
ll_output=$(echo "$ll_output" | \sed -E "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns)
|
||||
fi
|
||||
|
||||
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
|
||||
|
||||
@@ -121,7 +121,11 @@ scmb_expand_args() {
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" =~ ^[0-9]+$ ]] ; then # Substitute $e{*} variables for any integers
|
||||
if [ "$first" -eq 1 ]; then first=0; else printf '\t'; fi
|
||||
eval printf '%s' "\"\$$git_env_char$arg\""
|
||||
if [ -e "$arg" ]; then
|
||||
printf '%s' "$arg"
|
||||
else
|
||||
eval printf '%s' "\"\$$git_env_char$arg\""
|
||||
fi
|
||||
elif [[ "$arg" =~ ^[0-9]+-[0-9]+$ ]]; then # Expand ranges into $e{*} variables
|
||||
|
||||
for i in $(eval echo {${arg/-/..}}); do
|
||||
@@ -185,6 +189,8 @@ git_commit_prompt() {
|
||||
|
||||
if [ -n "$commit_msg" ]; then
|
||||
eval $@ # run any prequisite commands
|
||||
# Add $APPEND to commit message, if given. (Used to append things like [ci skip] for Travis CI)
|
||||
if [ -n "$APPEND" ]; then commit_msg="$commit_msg $APPEND"; fi
|
||||
echo $commit_msg | git commit -F - | tail -n +2
|
||||
else
|
||||
echo -e "\033[0;31mAborting commit due to empty commit message.\033[0m"
|
||||
@@ -206,7 +212,10 @@ git_commit_all() {
|
||||
fail_if_not_git_repo || return 1
|
||||
changes=$(git status --porcelain | wc -l)
|
||||
if [ "$changes" -gt 0 ]; then
|
||||
echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m"
|
||||
if [ -n "$APPEND" ]; then
|
||||
local appending=" | \033[0;36mappending '\033[1;36m$APPEND\033[0;36m' to commit message.\033[0m"
|
||||
fi
|
||||
echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m$appending"
|
||||
git_commit_prompt "git add -A"
|
||||
else
|
||||
echo "# No changed files to commit."
|
||||
@@ -225,4 +234,3 @@ git_add_and_commit() {
|
||||
echo "# No staged changes to commit."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ __git_ignore() {
|
||||
}
|
||||
# Always expand args
|
||||
git_ignore() {
|
||||
exec_scmb_expand_args __git_ignore $@
|
||||
exec_scmb_expand_args __git_ignore "$@"
|
||||
}
|
||||
|
||||
# Add one git ignore rule, just for your machine
|
||||
@@ -61,10 +61,10 @@ git_exclude() {
|
||||
|
||||
# Exclude basename of file
|
||||
__git_exclude_basename() {
|
||||
__git_ignore $(basename "$1") ".git/info/exclude"
|
||||
__git_ignore "$(basename "$1")" ".git/info/exclude"
|
||||
}
|
||||
git_exclude_basename() {
|
||||
exec_scmb_expand_args __git_exclude_basename $@
|
||||
exec_scmb_expand_args __git_exclude_basename "$@"
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +129,14 @@ fi
|
||||
# Delete a git branch from local, cached remote and remote server
|
||||
git_branch_delete_all() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: git_branch_delete_all branch"
|
||||
echo "Usage: git_branch_delete_all branch (-f forces deletion of unmerged branches.)"
|
||||
return
|
||||
fi
|
||||
$_git_cmd branch -D $1
|
||||
$_git_cmd branch -D -r origin/$1
|
||||
local opt="-d"
|
||||
if [ "$2" = '-f' ] || [ "$2" = '--force' ]; then opt="-D"; fi
|
||||
|
||||
$_git_cmd branch $opt $1
|
||||
$_git_cmd branch $opt -r origin/$1
|
||||
$_git_cmd push origin :$1
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,15 @@ disable_nullglob() { if [ $shell = "zsh" ]; then unsetopt NULL_GLOB; else shopt
|
||||
# Alias wrapper that ignores errors if alias is not defined.
|
||||
_alias(){ alias "$@" 2> /dev/null; }
|
||||
|
||||
if [ $shell = "zsh" ]; then
|
||||
export GIT_BINARY=$(type -p git | sed 's/git is //' | head -1)
|
||||
else
|
||||
export GIT_BINARY=$(type -P git)
|
||||
fi
|
||||
find_binary(){
|
||||
if [ $shell = "zsh" ]; then
|
||||
builtin type -p "$1" | sed "s/$1 is //" | head -1
|
||||
else
|
||||
builtin type -P "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
export GIT_BINARY=$(find_binary git)
|
||||
|
||||
# Updates SCM Breeze from GitHub.
|
||||
update_scm_breeze() {
|
||||
|
||||
Reference in New Issue
Block a user