Be compatible with shells of Ubuntu 14.04
This commit is contained in:
@@ -202,15 +202,16 @@ _git_index_update_all_branches() {
|
||||
return
|
||||
fi
|
||||
|
||||
local remotes merges branches
|
||||
# zsh 5.0.2 requires local separate to assignment for arrays
|
||||
local remote merge remotes merges branches
|
||||
# Get branch configuration from .git/config
|
||||
local IFS=$'\n'
|
||||
for branch in $($GIT_BINARY branch 2> /dev/null | sed -e 's/.\{2\}\(.*\)/\1/'); do
|
||||
# Skip '(no branch)'
|
||||
if [[ "$branch" = "(no branch)" ]]; then continue; fi
|
||||
|
||||
local remote=$(git config --get branch.$branch.remote)
|
||||
local merge=$(git config --get branch.$branch.merge)
|
||||
remote=$(git config --get "branch.$branch.remote")
|
||||
merge=$(git config --get "branch.$branch.merge")
|
||||
|
||||
# Ignore branch if remote and merge is not configured
|
||||
if [[ -n "$remote" ]] && [[ -n "$merge" ]]; then
|
||||
|
||||
@@ -79,7 +79,8 @@ git_add_shortcuts() {
|
||||
git_silent_add_shortcuts() {
|
||||
if [ -n "$1" ]; then
|
||||
# Expand args and process resulting set of files.
|
||||
eval "args=$(scmb_expand_args "$@")" # create $args array
|
||||
local args
|
||||
eval args="$(scmb_expand_args "$@")" # populate $args array
|
||||
for file in "${args[@]}"; do
|
||||
# Use 'git rm' if file doesn't exist and 'ga_auto_remove' is enabled.
|
||||
if [[ $ga_auto_remove = yes && ! -e $file ]]; then
|
||||
@@ -108,8 +109,8 @@ git_show_affected_files(){
|
||||
done; echo "# "
|
||||
}
|
||||
|
||||
|
||||
# Allows expansion of numbered shortcuts, ranges of shortcuts, or standard paths.
|
||||
# Return a string which can be `eval`ed like: eval args="$(scmb_expand_args "$@")"
|
||||
# Numbered shortcut variables are produced by various commands, such as:
|
||||
# * git_status_shortcuts() - git status implementation
|
||||
# * git_show_affected_files() - shows files affected by a given SHA1, etc.
|
||||
@@ -120,7 +121,8 @@ scmb_expand_args() {
|
||||
shift
|
||||
fi
|
||||
|
||||
local -a args=() # initially empty array
|
||||
local args
|
||||
args=() # initially empty array. zsh 5.0.2 from Ubuntu 14.04 requires this to be separated
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" =~ ^[0-9]{0,4}$ ]] ; then # Substitute $e{*} variables for any integers
|
||||
if [ -e "$arg" ]; then
|
||||
@@ -137,14 +139,22 @@ scmb_expand_args() {
|
||||
args+=("$arg")
|
||||
fi
|
||||
done
|
||||
args=$(declare -p args) # Get $args array as a string which can be `eval`-ed to recreate itself
|
||||
args=${args#*=} # Remove `typeset -a args=` from beginning of string to allow caller to name variable
|
||||
echo "$args"
|
||||
|
||||
# "declare -p" with zsh 5.0.2 on Ubuntu 14.04 creates a string that it cannot process:
|
||||
# typeset -a args args=(one three six)
|
||||
# There should be a ; between the two "args" tokens
|
||||
# "declare -p" with bash 4.3.11(1) on Ubuntu 14.04 creates a string like:
|
||||
# declare -a a='([0]="a" [1]="b c" [2]="d")'
|
||||
# The RHS of this string is incompatible with zsh 5.0.2 and "eval args="
|
||||
|
||||
# Generate a quoted array string to assign to "eval args="
|
||||
echo "( $(token_quote "${args[@]}") )"
|
||||
}
|
||||
|
||||
# Expand a variable (named by $2) into a (possibly relative) pathname
|
||||
_print_path() {
|
||||
local pathname=$(eval printf '%s' "\"\${$2}\"")
|
||||
local pathname
|
||||
pathname=$(eval printf '%s' "\"\${$2}\"")
|
||||
if [ "$1" = 1 ]; then # print relative
|
||||
pathname=${pathname#$PWD/} # Remove $PWD from beginning of the path
|
||||
fi
|
||||
@@ -154,7 +164,8 @@ _print_path() {
|
||||
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12
|
||||
# Fails if command is a number or range (probably not worth fixing)
|
||||
exec_scmb_expand_args() {
|
||||
eval "args=$(scmb_expand_args "$@")" # create $args array
|
||||
local args
|
||||
eval "args=$(scmb_expand_args "$@")" # populate $args array
|
||||
_safe_eval "${args[@]}"
|
||||
}
|
||||
|
||||
@@ -177,7 +188,8 @@ git_clear_vars() {
|
||||
_git_resolve_merge_conflict() {
|
||||
if [ -n "$2" ]; then
|
||||
# Expand args and process resulting set of files.
|
||||
eval "args=$(scmb_expand_args "$@")" # create $args array
|
||||
local args
|
||||
eval "args=$(scmb_expand_args "$@")" # populate $args array
|
||||
for file in "${args[@]:2}"; do
|
||||
git checkout "--$1""s" "$file" # "--$1""s" is expanded to --ours or --theirs
|
||||
git add "$file"
|
||||
|
||||
@@ -23,6 +23,7 @@ git_remove_history() {
|
||||
return
|
||||
fi
|
||||
# Remove all paths passed as arguments from the history of the repo
|
||||
local files
|
||||
files=("$@")
|
||||
$_git_cmd filter-branch --index-filter "$_git_cmd rm -rf --cached --ignore-unmatch ${files[*]}" HEAD
|
||||
# Remove the temporary history git-filter-branch otherwise leaves behind for a long time
|
||||
@@ -142,4 +143,4 @@ git_branch_delete_all() {
|
||||
|
||||
commit_docs() {
|
||||
git commit -m "Update README / Documentation [ci skip]"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ _alias() {
|
||||
# Quote the contents of "$@"
|
||||
function token_quote {
|
||||
# Older versions of {ba,z}sh don't support the built-in quoting, so fall back to printf %q
|
||||
local quoted=()
|
||||
local quoted
|
||||
quoted=() # Assign separately for zsh 5.0.2 of Ubuntu 14.04
|
||||
for token; do
|
||||
quoted+=( "$(printf '%q' "$token")" )
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user