Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -120,11 +120,12 @@ if [ "$git_setup_aliases" = "yes" ]; then
|
||||
__git_alias "$git_restore_alias" 'git' 'restore'
|
||||
|
||||
# Custom default format for git log
|
||||
git_log_command="log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
||||
__git_alias "$git_log_alias" 'git' "$git_log_command"
|
||||
git_log_command=('log' '--graph' "--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
|
||||
'--abbrev-commit')
|
||||
__git_alias "$git_log_alias" 'git' "${git_log_command[@]}"
|
||||
|
||||
# Same as the above, but displays all the branches and remotes
|
||||
__git_alias "$git_log_all_alias" 'git' "$git_log_command" '--branches' '--remotes'
|
||||
__git_alias "$git_log_all_alias" 'git' "${git_log_command[@]}" '--branches' '--remotes'
|
||||
|
||||
# Standard commands
|
||||
__git_alias "$git_clone_alias" 'git' 'clone'
|
||||
@@ -176,8 +177,8 @@ if [ "$git_setup_aliases" = "yes" ]; then
|
||||
_alias "$git_log_graph_all_alias" 'git log --all --graph --oneline --decorate --date-order'
|
||||
_alias "$git_add_all_alias" 'git add --all .'
|
||||
|
||||
# Hub aliases (https://github.com/github/hub)
|
||||
_alias "$git_pull_request_alias" 'git pull-request'
|
||||
# GitHub CLI aliases (https://github.com/cli/cli)
|
||||
_alias "$git_pull_request_alias" 'gh pr'
|
||||
fi
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ function _scmb_git_branch_shortcuts {
|
||||
# Fall back to normal git branch, if any unknown args given
|
||||
if [[ "$($_git_cmd branch | wc -l)" -gt 300 ]] || ([[ -n "$@" ]] && [[ "$@" != "-a" ]]); then
|
||||
exec_scmb_expand_args $_git_cmd branch "$@"
|
||||
return 1
|
||||
return $?
|
||||
fi
|
||||
|
||||
# Use ruby to inject numbers into git branch output
|
||||
|
||||
@@ -140,7 +140,7 @@ $pad$c_dark [$c_rst$e$c_dark] $c_group$relative$c_rst"
|
||||
# Export numbered variables in the order they are displayed.
|
||||
# (Exports full path, but displays relative path)
|
||||
# fetch first file (in the case of oldFile -> newFile) and remove quotes
|
||||
local filename=$(eval echo $(echo ${stat_file[$i]} | egrep -o '^"([^\\"]*(\\.[^"]*)*)"|^[^ ]+'))
|
||||
local filename=$(eval echo $(echo ${stat_file[$i]} | grep -E -o '^"([^\\"]*(\\.[^"]*)*)"|^[^ ]+'))
|
||||
export $git_env_char$e="$project_root/$filename"
|
||||
let e++
|
||||
done
|
||||
|
||||
@@ -171,7 +171,7 @@ function is_git_dirty {
|
||||
[[ $($GIT_BINARY status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
|
||||
}
|
||||
function parse_git_branch {
|
||||
$GIT_BINARY branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
|
||||
git rev-parse --abbrev-ref HEAD 2> /dev/null
|
||||
}
|
||||
|
||||
# If the working directory is clean, update the git repository. Otherwise, show changes.
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
# Released under the LGPL (GNU Lesser General Public License)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
if sed -E 's///g' </dev/null &>/dev/null; then
|
||||
SED_REGEX_ARG="E"
|
||||
elif sed -r 's///g' </dev/null &>/dev/null; then
|
||||
@@ -13,7 +12,6 @@ else
|
||||
echo "Cannot determine extended regex argument for sed! (Doesn't respond to either -E or -r)"
|
||||
fi
|
||||
|
||||
|
||||
# Wrap common commands with numeric argument expansion.
|
||||
# Prepends everything with exec_scmb_expand_args,
|
||||
# even if commands are already aliases or functions
|
||||
@@ -21,14 +19,14 @@ 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() { LC_MESSAGES="C" type "$@" | sed -$SED_REGEX_ARG -e "s/.*is aliased to \`//" -e "s/'$//"; }
|
||||
type whence >/dev/null 2>&1 || function whence() { LC_MESSAGES="C" type "$@" | sed -$SED_REGEX_ARG -e "s/.*is aliased to \`//" -e "s/'$//"; }
|
||||
local cmd=''
|
||||
for cmd in $scmb_wrapped_shell_commands; do
|
||||
for cmd in "${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
|
||||
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
|
||||
@@ -39,12 +37,14 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
|
||||
# Don't do anything if command already aliased, or not found.
|
||||
*'exec_scmb_expand_args'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is already wrapped"; fi;;
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is already wrapped"; fi
|
||||
;;
|
||||
|
||||
*'not found'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi;;
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi
|
||||
;;
|
||||
|
||||
*'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)"
|
||||
@@ -53,16 +53,17 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
|
||||
# Detect original $cmd type, and escape
|
||||
case "$(LC_MESSAGES="C" 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 'find_binary' function
|
||||
*) local escaped_cmd="$(find_binary $cmd)";;
|
||||
# Escape shell builtins with 'builtin'
|
||||
*'is a shell builtin'*) local escaped_cmd="builtin $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 -$SED_REGEX_ARG "s%(^| )$cmd($| )%\\1$escaped_cmd\\2%")"
|
||||
# Wrap previous alias with escaped command
|
||||
alias $cmd="exec_scmb_expand_args $expanded_alias";;
|
||||
alias $cmd="exec_scmb_expand_args $expanded_alias"
|
||||
;;
|
||||
|
||||
*'is a'*'function'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a function"; fi
|
||||
@@ -71,50 +72,53 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
# Remove function
|
||||
unset -f "$cmd"
|
||||
# Create function that wraps old function
|
||||
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }";;
|
||||
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }"
|
||||
;;
|
||||
|
||||
*'is a shell builtin'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a shell builtin"; fi
|
||||
# Handle shell builtin commands
|
||||
alias $cmd="exec_scmb_expand_args builtin $cmd";;
|
||||
alias $cmd="exec_scmb_expand_args builtin $cmd"
|
||||
;;
|
||||
|
||||
*)
|
||||
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 with 'find_binary' function
|
||||
alias $cmd="exec_scmb_expand_args $(find_binary $cmd)";;
|
||||
alias $cmd="exec_scmb_expand_args '$(find_binary $cmd)'"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# Clean up
|
||||
declare -f whence > /dev/null && unset -f whence
|
||||
declare -f whence >/dev/null && unset -f whence
|
||||
}
|
||||
_git_wrap_commands
|
||||
fi
|
||||
|
||||
|
||||
# Function wrapper around 'll'
|
||||
# Adds numbered shortcuts to output of ls -l, just like 'git status'
|
||||
if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/null 2>&1; then
|
||||
if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby >/dev/null 2>&1; then
|
||||
# BSD ls is different to Linux (GNU) ls
|
||||
# Test for BSD ls
|
||||
if ! ls --color=auto > /dev/null 2>&1; then
|
||||
if ! (ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then
|
||||
# ls is BSD
|
||||
_ls_bsd="BSD"
|
||||
fi
|
||||
|
||||
# Test if readlink supports -f option, test for greadlink on Mac, then fallback to perl
|
||||
if \readlink -f / > /dev/null 2>&1; then
|
||||
if \readlink -f / >/dev/null 2>&1; then
|
||||
_abs_path_command=(readlink -f)
|
||||
elif greadlink -f / > /dev/null 2>&1; then
|
||||
elif greadlink -f / >/dev/null 2>&1; then
|
||||
_abs_path_command=(greadlink -f)
|
||||
else
|
||||
_abs_path_command=(perl -e 'use Cwd abs_path; print abs_path(shift)')
|
||||
fi
|
||||
|
||||
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
|
||||
unalias ll >/dev/null 2>&1
|
||||
unset -f ll >/dev/null 2>&1
|
||||
function ls_with_file_shortcuts {
|
||||
local ll_output
|
||||
local ll_command # Ensure sort ordering of the two invocations is the same
|
||||
local ll_command # Ensure sort ordering of the two invocations is the same
|
||||
if [ "$_ls_bsd" != "BSD" ]; then
|
||||
ll_command=(\ls -hv --group-directories-first)
|
||||
ll_output="$("${ll_command[@]}" -l --color "$@")"
|
||||
@@ -139,11 +143,11 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
if [[ -z $rel_path ]]; then # We are seeing our first pathname
|
||||
if [[ -d $arg ]]; then # It's a directory
|
||||
rel_path=$arg
|
||||
else # It's a file, expand the current directory
|
||||
else # It's a file, expand the current directory
|
||||
rel_path=.
|
||||
fi
|
||||
elif [[ -d $arg || ( -f $arg && $rel_path != . ) ]]; then
|
||||
if [[ -f $arg ]]; then arg=$PWD; fi # Get directory for current argument
|
||||
elif [[ -d $arg || (-f $arg && $rel_path != .) ]]; then
|
||||
if [[ -f $arg ]]; then arg=$PWD; fi # Get directory for current argument
|
||||
# We've already seen a different directory. Quit to avoid damage (issue #274)
|
||||
printf 'scm_breeze: Cannot list relative to both directories:\n %s\n %s\n' "$arg" "$rel_path" >&2
|
||||
printf 'Currently only listing a single directory is supported. See issue #274.\n' >&2
|
||||
@@ -159,7 +163,7 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
if [ -e "$HOME"/.user_sym ]; then
|
||||
# Little bit of ruby golf to rejustify the user/group/size columns after replacement
|
||||
# TODO(ghthor): Convert this to a cat <<EOF to improve readibility
|
||||
function rejustify_ls_columns(){
|
||||
function rejustify_ls_columns() {
|
||||
ruby -e "o=STDIN.read;re=/^(([^ ]* +){2})(([^ ]* +){3})/;\
|
||||
u,g,s=o.lines.map{|l|l[re,3]}.compact.map(&:split).transpose.map{|a|a.map(&:size).max+1};\
|
||||
puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}"
|
||||
@@ -168,12 +172,12 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
local USER_SYM=$(/bin/cat $HOME/.user_sym)
|
||||
if [ -f "$HOME/.staff_sym" ]; then
|
||||
local STAFF_SYM=$(/bin/cat $HOME/.staff_sym)
|
||||
ll_output=$(echo "$ll_output" | \
|
||||
\sed -$SED_REGEX_ARG "s/ $USER staff/ $USER_SYM $STAFF_SYM /g" | \
|
||||
ll_output=$(echo "$ll_output" |
|
||||
\sed -$SED_REGEX_ARG "s/ $USER staff/ $USER_SYM $STAFF_SYM /g" |
|
||||
rejustify_ls_columns)
|
||||
else
|
||||
ll_output=$(echo "$ll_output" | \
|
||||
\sed -$SED_REGEX_ARG "s/ $USER/ $USER_SYM /g" | \
|
||||
ll_output=$(echo "$ll_output" |
|
||||
\sed -$SED_REGEX_ARG "s/ $USER/ $USER_SYM /g" |
|
||||
rejustify_ls_columns)
|
||||
fi
|
||||
fi
|
||||
@@ -186,7 +190,8 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
fi
|
||||
|
||||
# Use ruby to inject numbers into ls output
|
||||
echo "$ll_output" | ruby -e "$( \cat <<EOF
|
||||
echo "$ll_output" | ruby -e "$(
|
||||
\cat <<EOF
|
||||
output = STDIN.read
|
||||
e = 1
|
||||
re = /^(([^ ]* +){8})/
|
||||
@@ -196,7 +201,7 @@ output.lines.each do |line|
|
||||
e += 1
|
||||
end
|
||||
EOF
|
||||
)"
|
||||
)"
|
||||
|
||||
# Set numbered file shortcut in variable
|
||||
local e=1
|
||||
|
||||
@@ -88,7 +88,7 @@ puts "%s#%s On branch: %s#{@branch}#{difference}%s %s| [%s*%s]%s => $#{ENV["gi
|
||||
]
|
||||
|
||||
def has_modules?
|
||||
@has_modules ||= File.exists?(File.join(@project_root, '.gitmodules'))
|
||||
@has_modules ||= File.exist?(File.join(@project_root, '.gitmodules'))
|
||||
end
|
||||
|
||||
# Index modification states
|
||||
|
||||
@@ -209,7 +209,7 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
|
||||
# * Execute prerequisite commands if message given, abort if not
|
||||
# * Pipe commit message to 'git commit'
|
||||
# * Add escaped commit command and unescaped message to bash history.
|
||||
git_commit_prompt() {
|
||||
git_commit_prompt() (
|
||||
local commit_msg
|
||||
local saved_commit_msg
|
||||
if [ -f "/tmp/.git_commit_message~" ]; then
|
||||
@@ -268,10 +268,10 @@ git_commit_prompt() {
|
||||
# Delete saved commit message if commit was successful
|
||||
rm -f "/tmp/.git_commit_message~"
|
||||
fi
|
||||
}
|
||||
)
|
||||
|
||||
# Prompt for commit message, then commit all modified and untracked files.
|
||||
git_commit_all() {
|
||||
git_commit_all() (
|
||||
fail_if_not_git_repo || return 1
|
||||
changes=$(git status --porcelain | wc -l | tr -d ' ')
|
||||
if [ "$changes" -gt 0 ]; then
|
||||
@@ -283,10 +283,10 @@ git_commit_all() {
|
||||
else
|
||||
echo "# No changed files to commit."
|
||||
fi
|
||||
}
|
||||
)
|
||||
|
||||
# Add paths or expanded args if any given, then commit all staged changes.
|
||||
git_add_and_commit() {
|
||||
git_add_and_commit() (
|
||||
fail_if_not_git_repo || return 1
|
||||
git_silent_add_shortcuts "$@"
|
||||
changes=$(git diff --cached --numstat | wc -l)
|
||||
@@ -296,4 +296,4 @@ git_add_and_commit() {
|
||||
else
|
||||
echo "# No staged changes to commit."
|
||||
fi
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user