From 67458229530e66b0223ffeb99e55e3a44c64b77f Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sun, 19 Feb 2017 20:05:59 +0700 Subject: [PATCH] Fix IFS issues - have to always unset after use --- lib/design.sh | 1 + lib/git/branch_shortcuts.sh | 1 + lib/git/fallback/status_shortcuts_shell.sh | 2 +- lib/git/repo_index.sh | 12 ++++++------ lib/git/shell_shortcuts.sh | 8 ++++---- lib/git/status_shortcuts.sh | 6 +++--- test/lib/git/repo_index_test.sh | 4 ++-- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/design.sh b/lib/design.sh index 5106247..e0e2091 100644 --- a/lib/design.sh +++ b/lib/design.sh @@ -102,5 +102,6 @@ design() { printf "Invalid command.\n\n" design fi + unset IFS } diff --git a/lib/git/branch_shortcuts.sh b/lib/git/branch_shortcuts.sh index ddea8dc..61012e2 100644 --- a/lib/git/branch_shortcuts.sh +++ b/lib/git/branch_shortcuts.sh @@ -39,6 +39,7 @@ EOF if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi let e++ done + unset IFS } __git_alias "$git_branch_alias" "_scmb_git_branch_shortcuts" "" diff --git a/lib/git/fallback/status_shortcuts_shell.sh b/lib/git/fallback/status_shortcuts_shell.sh index e7cce4b..9368588 100755 --- a/lib/git/fallback/status_shortcuts_shell.sh +++ b/lib/git/fallback/status_shortcuts_shell.sh @@ -114,7 +114,7 @@ git_status_shortcuts() { # so just use plain 'git status' git status fi - IFS=$' \t\n' + unset IFS zsh_reset # Reset zsh environment to default } # Template function for 'git_status_shortcuts'. diff --git a/lib/git/repo_index.sh b/lib/git/repo_index.sh index c77d115..b197d49 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -116,7 +116,7 @@ function git_index() { fi fi fi - IFS=$' \t\n' + unset IFS } _git_index_dirs_without_home() { @@ -131,7 +131,7 @@ function _find_git_repos() { echo ${repo%/.git} # Return project folder, with trailing ':' _find_git_submodules $repo # Detect any submodules done - IFS=$' \t\n' + unset IFS } # List all submodules for a git repo, if any. @@ -150,7 +150,7 @@ function _rebuild_git_index() { for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do echo $(basename $repo | sed "s/ /_/g") $repo done | sort | cut -d " " -f2- >| "$GIT_REPO_DIR/.git_index" - IFS=$' \t\n' + unset IFS if [ "$1" != "--silent" ]; then echo -e "===== Indexed $_bld_col$(_git_index_count)$_txt_col repos in $GIT_REPO_DIR/.git_index" @@ -225,7 +225,7 @@ _git_index_update_all_branches() { echo "=== Skipping $branch: remote and merge refs are not configured." fi done - IFS=$' \t\n' + unset IFS # Update all remotes if there are any branches to update if [ -n "${branches[*]}" ]; then git fetch --all 2> /dev/null; fi @@ -268,7 +268,7 @@ function _git_index_batch_cmd() { cwd="$PWD" if [ -n "$1" ]; then echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n" - IFS=$' \t\n' + unset IFS local base_path for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do builtin cd "$base_path" @@ -313,7 +313,7 @@ if [ $shell = 'bash' ]; then else COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)' -- $curw)) fi - IFS=$' \t\n' + unset IFS return 0 } else diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 26a9ff4..6299537 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -125,11 +125,11 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && which ruby > /dev/null 2>&1; then fi # Parse path from args - OLDIFS="$IFS"; IFS=$'\n' + IFS=$'\n' for arg in $@; do if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi done - IFS="$OLDIFS" + unset IFS # Replace user/group with user symbol, if defined at ~/.user_sym # Before : -rw-rw-r-- 1 ndbroadbent ndbroadbent 1.1K Sep 19 21:39 scm_breeze.sh @@ -175,14 +175,14 @@ EOF ll_files="$(\ls "$@")" fi - OLDIFS="$IFS"; IFS=$'\n' + IFS=$'\n' for file in $ll_files; do if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi export $git_env_char$e="$(eval $_abs_path_command \"${file//\"/\\\"}\")" if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi let e++ done - IFS="$OLDIFS" + unset IFS # Turn off shwordsplit unless it was on previously if [[ $shell == "zsh" ]] && [ -z "$SHWORDSPLIT_ON" ]; then unsetopt shwordsplit; fi diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index a2e20e4..d63bb0c 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -43,7 +43,7 @@ git_status_shortcuts() { if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi let e++ done - IFS=$' \t\n' + unset IFS if [ "${scmbDebug:-}" = "true" ]; then echo "------------------------"; fi # Print status @@ -91,7 +91,7 @@ git_silent_add_shortcuts() { echo -e "# Added '$file'" fi done - IFS=$' \t\n' + unset IFS echo "#" fi } @@ -186,7 +186,7 @@ _git_resolve_merge_conflict() { git add "$file" echo -e "# Added $1 version of '$file'" done - IFS=$' \t\n' + unset IFS echo -e "# -- If you have finished resolving conflicts, commit the resolutions with 'git commit'" fi } diff --git a/test/lib/git/repo_index_test.sh b/test/lib/git/repo_index_test.sh index d2afa8e..f7006ed 100755 --- a/test/lib/git/repo_index_test.sh +++ b/test/lib/git/repo_index_test.sh @@ -63,7 +63,7 @@ EOF for dir in $GIT_REPOS; do mkdir -p $dir; cd $dir; git init; done - IFS=$' \t\n' + unset IFS verboseGitCommands @@ -74,7 +74,7 @@ oneTimeTearDown() { rm -rf "${GIT_REPO_DIR}" IFS=":" for dir in $GIT_REPOS; do rm -rf $dir; done - IFS=$' \t\n' + unset IFS } ensureIndex() {