Quote arrays to avoid splitting by $IFS

This commit is contained in:
Tom "Ravi" Hale
2018-08-24 08:32:23 +07:00
parent 8a326c2505
commit 5f286eaaaa
8 changed files with 21 additions and 21 deletions

View File

@@ -71,7 +71,7 @@ __git_alias () {
alias_str="$1"; cmd_prefix="$2"; cmd="$3";
if [ $# -gt 2 ]; then
shift 3 2>/dev/null
cmd_args=$@
cmd_args=("$@")
fi
alias $alias_str="$cmd_prefix $cmd${cmd_args:+ }${cmd_args[*]}"

View File

@@ -22,7 +22,7 @@ function _scmb_git_branch_shortcuts {
# Use ruby to inject numbers into ls output
ruby -e "$( cat <<EOF
output = %x($_git_cmd branch --color=always $@)
output = %x($_git_cmd branch --color=always "$@")
line_count = output.lines.to_a.size
output.lines.each_with_index do |line, i|
spaces = (line_count > 9 && i < 9 ? " " : " ")

View File

@@ -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
@@ -232,12 +232,12 @@ _git_index_update_all_branches() {
local index=0
# Iterate over branches, and update those that can be fast-forwarded
for branch in ${branches[@]}; do
for branch in "${branches[@]}"; do
branch_rev="$(git rev-parse $branch)"
# Local branch can be fast-forwarded if revision is ancestor of remote revision, and not the same.
# (see http://stackoverflow.com/a/2934062/304706)
if [[ "$branch_rev" != "$(git rev-parse ${remotes[$index]}/${merges[$index]})" ]] && \
[[ "$(git merge-base $branch_rev ${remotes[$index]}/${merges[$index]})" = "$branch_rev" ]]; then
if [[ "$branch_rev" != "$(git rev-parse "${remotes[$index]}/${merges[$index]}")" ]] && \
[[ "$(git merge-base "$branch_rev" "${remotes[$index]}/${merges[$index]}")" = "$branch_rev" ]]; then
echo "=== Updating $branch branch in $base_path from ${remotes[$index]}/${merges[$index]}..."
# Checkout branch if we aren't already on it.
if [[ "$branch" != "$(parse_git_branch)" ]]; then git checkout $branch; fi
@@ -272,7 +272,7 @@ function _git_index_batch_cmd() {
local base_path
for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do
builtin cd "$base_path"
$@
"$@"
done
else
echo "Please give a command to run for all repos. (It may be useful to write your command as a function or script.)"

View File

@@ -126,7 +126,7 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && which ruby > /dev/null 2>&1; then
# Parse path from args
IFS=$'\n'
for arg in $@; do
for arg in "$@"; do
if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi
done
unset IFS
@@ -142,7 +142,7 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && which ruby > /dev/null 2>&1; then
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 -$SED_REGEX_ARG "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns)
ll_output=$(echo "$ll_output" | \sed -$SED_REGEX_ARG "s/ $USER/ $(/bin/cat "$HOME/.user_sym")/g" | rejustify_ls_columns)
fi
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then

View File

@@ -21,7 +21,7 @@ git_status_shortcuts() {
zsh_compat # Ensure shwordsplit is on for zsh
git_clear_vars
# Run ruby script, store output
local cmd_output="$(/usr/bin/env ruby "$scmbDir/lib/git/status_shortcuts.rb" $@)"
local cmd_output="$(/usr/bin/env ruby "$scmbDir/lib/git/status_shortcuts.rb" "$@")"
# Print debug information if $scmbDebug = "true"
if [ "${scmbDebug:-}" = "true" ]; then
printf "status_shortcuts.rb output => \n$cmd_output\n------------------------\n"
@@ -102,8 +102,8 @@ git_show_affected_files(){
fail_if_not_git_repo || return 1
f=0 # File count
# Show colored revision and commit message
echo -n "# "; git show --oneline --name-only $@ | head -n1; echo "# "
for file in $(git show --pretty="format:" --name-only $@ | \grep -v '^$'); do
echo -n "# "; git show --oneline --name-only "$@" | head -n1; echo "# "
for file in $(git show --pretty="format:" --name-only "$@" | \grep -v '^$'); do
let f++
export $git_env_char$f=$file # Export numbered variable.
echo -e "# \033[2;37m[\033[0m$f\033[2;37m]\033[0m $file"
@@ -210,7 +210,7 @@ git_commit_prompt() {
fi
if [ -n "$commit_msg" ]; then
eval $@ # run any prequisite commands
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

View File

@@ -23,8 +23,8 @@ git_remove_history() {
return
fi
# Remove all paths passed as arguments from the history of the repo
files=$@
$_git_cmd filter-branch --index-filter "$_git_cmd rm -rf --cached --ignore-unmatch $files" HEAD
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
rm -rf .git/refs/original/ && $_git_cmd reflog expire --all && $_git_cmd gc --aggressive --prune
}