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"; alias_str="$1"; cmd_prefix="$2"; cmd="$3";
if [ $# -gt 2 ]; then if [ $# -gt 2 ]; then
shift 3 2>/dev/null shift 3 2>/dev/null
cmd_args=$@ cmd_args=("$@")
fi fi
alias $alias_str="$cmd_prefix $cmd${cmd_args:+ }${cmd_args[*]}" 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 # Use ruby to inject numbers into ls output
ruby -e "$( cat <<EOF 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 line_count = output.lines.to_a.size
output.lines.each_with_index do |line, i| output.lines.each_with_index do |line, i|
spaces = (line_count > 9 && i < 9 ? " " : " ") 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 # Ignore branch if remote and merge is not configured
if [[ -n "$remote" ]] && [[ -n "$merge" ]]; then if [[ -n "$remote" ]] && [[ -n "$merge" ]]; then
branches=(${branches[@]} "$branch") branches=("${branches[@]}" "$branch")
remotes=(${remotes[@]} "$remote") remotes=("${remotes[@]}" "$remote")
# Get branch from merge ref (refs/heads/master => master) # Get branch from merge ref (refs/heads/master => master)
merges=(${merges[@]} "$(basename $merge)") merges=("${merges[@]}" "$(basename "$merge")")
else else
echo "=== Skipping $branch: remote and merge refs are not configured." echo "=== Skipping $branch: remote and merge refs are not configured."
fi fi
@@ -232,12 +232,12 @@ _git_index_update_all_branches() {
local index=0 local index=0
# Iterate over branches, and update those that can be fast-forwarded # 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)" branch_rev="$(git rev-parse $branch)"
# Local branch can be fast-forwarded if revision is ancestor of remote revision, and not the same. # Local branch can be fast-forwarded if revision is ancestor of remote revision, and not the same.
# (see http://stackoverflow.com/a/2934062/304706) # (see http://stackoverflow.com/a/2934062/304706)
if [[ "$branch_rev" != "$(git rev-parse ${remotes[$index]}/${merges[$index]})" ]] && \ if [[ "$branch_rev" != "$(git rev-parse "${remotes[$index]}/${merges[$index]}")" ]] && \
[[ "$(git merge-base $branch_rev ${remotes[$index]}/${merges[$index]})" = "$branch_rev" ]]; then [[ "$(git merge-base "$branch_rev" "${remotes[$index]}/${merges[$index]}")" = "$branch_rev" ]]; then
echo "=== Updating $branch branch in $base_path from ${remotes[$index]}/${merges[$index]}..." echo "=== Updating $branch branch in $base_path from ${remotes[$index]}/${merges[$index]}..."
# Checkout branch if we aren't already on it. # Checkout branch if we aren't already on it.
if [[ "$branch" != "$(parse_git_branch)" ]]; then git checkout $branch; fi if [[ "$branch" != "$(parse_git_branch)" ]]; then git checkout $branch; fi
@@ -272,7 +272,7 @@ function _git_index_batch_cmd() {
local base_path local base_path
for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do
builtin cd "$base_path" builtin cd "$base_path"
$@ "$@"
done done
else else
echo "Please give a command to run for all repos. (It may be useful to write your command as a function or script.)" 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 # Parse path from args
IFS=$'\n' IFS=$'\n'
for arg in $@; do for arg in "$@"; do
if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi
done done
unset IFS 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]}}" 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 fi
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then 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 zsh_compat # Ensure shwordsplit is on for zsh
git_clear_vars git_clear_vars
# Run ruby script, store output # 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" # Print debug information if $scmbDebug = "true"
if [ "${scmbDebug:-}" = "true" ]; then if [ "${scmbDebug:-}" = "true" ]; then
printf "status_shortcuts.rb output => \n$cmd_output\n------------------------\n" 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 fail_if_not_git_repo || return 1
f=0 # File count f=0 # File count
# Show colored revision and commit message # Show colored revision and commit message
echo -n "# "; git show --oneline --name-only $@ | head -n1; echo "# " echo -n "# "; git show --oneline --name-only "$@" | head -n1; echo "# "
for file in $(git show --pretty="format:" --name-only $@ | \grep -v '^$'); do for file in $(git show --pretty="format:" --name-only "$@" | \grep -v '^$'); do
let f++ let f++
export $git_env_char$f=$file # Export numbered variable. export $git_env_char$f=$file # Export numbered variable.
echo -e "# \033[2;37m[\033[0m$f\033[2;37m]\033[0m $file" echo -e "# \033[2;37m[\033[0m$f\033[2;37m]\033[0m $file"
@@ -210,7 +210,7 @@ git_commit_prompt() {
fi fi
if [ -n "$commit_msg" ]; then 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) # 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 if [ -n "$APPEND" ]; then commit_msg="$commit_msg $APPEND"; fi
echo $commit_msg | git commit -F - | tail -n +2 echo $commit_msg | git commit -F - | tail -n +2

View File

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

View File

@@ -38,7 +38,7 @@ oneTimeSetUp() {
alias rvm="test" # Ensure tests run if RVM isn't loaded but $HOME/.rvm is present alias rvm="test" # Ensure tests run if RVM isn't loaded but $HOME/.rvm is present
# Test functions # Test functions
function ln() { ln $@; } function ln() { ln "$@"; }
# Before aliasing, get original locations so we can compare them in the test # Before aliasing, get original locations so we can compare them in the test
unalias mv rm sed cat 2>/dev/null unalias mv rm sed cat 2>/dev/null

View File

@@ -25,9 +25,9 @@ SHUNIT_ERROR=2
# enable strict mode by default # enable strict mode by default
SHUNIT_STRICT=${SHUNIT_STRICT:-${SHUNIT_TRUE}} SHUNIT_STRICT=${SHUNIT_STRICT:-${SHUNIT_TRUE}}
_shunit_warn() { echo "shunit2:WARN $@" >&2; } _shunit_warn() { echo "shunit2:WARN $*" >&2; }
_shunit_error() { echo "shunit2:ERROR $@" >&2; } _shunit_error() { echo "shunit2:ERROR $*" >&2; }
_shunit_fatal() { echo "shunit2:FATAL $@" >&2; exit ${SHUNIT_ERROR}; } _shunit_fatal() { echo "shunit2:FATAL $*" >&2; exit ${SHUNIT_ERROR}; }
# specific shell checks # specific shell checks
if [ -n "${ZSH_VERSION:-}" ]; then if [ -n "${ZSH_VERSION:-}" ]; then