From d5c60b2cc542b337ccae1435b5c1e99291949edf Mon Sep 17 00:00:00 2001 From: "Tom \"Ravi\" Hale" Date: Fri, 24 Aug 2018 18:12:07 +0700 Subject: [PATCH] git_status_shortcuts: don't clobber $IFS --- lib/design.sh | 3 +-- lib/git/branch_shortcuts.sh | 4 +--- lib/git/fallback/status_shortcuts_shell.sh | 5 ++--- lib/git/repo_index.sh | 22 ++++++++-------------- lib/git/shell_shortcuts.sh | 6 ++---- lib/git/status_shortcuts.sh | 3 +-- test/lib/git/repo_index_test.sh | 6 ++---- 7 files changed, 17 insertions(+), 32 deletions(-) diff --git a/lib/design.sh b/lib/design.sh index 125175e..cd48cdb 100644 --- a/lib/design.sh +++ b/lib/design.sh @@ -34,7 +34,7 @@ design() { local project=`basename $(pwd)` local all_project_dirs="$design_base_dirs $design_av_dirs" # Ensure design dir contains all subdirectories - IFS=$' \t\n' + local IFS=$' \t\n' # Create root design dirs for dir in $design_ext_dirs; do mkdir -p "$root_design_dir/$dir"; done # Create project design dirs @@ -102,6 +102,5 @@ 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 7157339..27b0ce8 100644 --- a/lib/git/branch_shortcuts.sh +++ b/lib/git/branch_shortcuts.sh @@ -32,14 +32,12 @@ EOF )" # Set numbered file shortcut in variable - local e=1 - IFS=$'\n' + local e=1 IFS=$'\n' for branch in $($_git_cmd branch "$@" | sed "s/^[* ]\{2\}//"); do export $git_env_char$e="$branch" 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 9368588..406da56 100755 --- a/lib/git/fallback/status_shortcuts_shell.sh +++ b/lib/git/fallback/status_shortcuts_shell.sh @@ -16,7 +16,7 @@ # -------------------------------------------------------------------- git_status_shortcuts() { zsh_compat # Ensure shwordsplit is on for zsh - IFS=$'\n' + local IFS=$'\n' local git_status="$(git status --porcelain 2> /dev/null)" local i @@ -95,7 +95,7 @@ git_status_shortcuts() { fi done - IFS=" " + local IFS=" " grp_num=1 for heading in 'Changes to be committed' 'Unmerged paths' 'Changes not staged for commit' 'Untracked files'; do # If no group specified as param, or specified group is current group @@ -114,7 +114,6 @@ git_status_shortcuts() { # so just use plain 'git status' git status fi - 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 9fc2b44..b3f4005 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -51,7 +51,7 @@ function git_index() { - IFS=$'\n' + local IFS=$'\n' if [ -z "$1" ]; then # Just change to $GIT_REPO_DIR if no params given. "cd" $GIT_REPO_DIR @@ -103,7 +103,7 @@ function git_index() { # -------------------- # Go to our base path if [ -n "$base_path" ]; then - IFS=$' \t\n' + local IFS=$' \t\n' # evaluate ~ if necessary if [[ "$base_path" == "~"* ]]; then base_path=$(eval echo ${base_path%%/*})/${base_path#*/} @@ -116,7 +116,6 @@ function git_index() { fi fi fi - unset IFS } _git_index_dirs_without_home() { @@ -126,12 +125,11 @@ _git_index_dirs_without_home() { # Recursively searches for git repos in $GIT_REPO_DIR function _find_git_repos() { # Find all unarchived projects - IFS=$'\n' + local IFS=$'\n' for repo in $(find -L "$GIT_REPO_DIR" -maxdepth 5 -name ".git" -type d \! -wholename '*/archive/*'); do echo ${repo%/.git} # Return project folder, with trailing ':' _find_git_submodules $repo # Detect any submodules done - unset IFS } # List all submodules for a git repo, if any. @@ -146,11 +144,10 @@ function _find_git_submodules() { function _rebuild_git_index() { if [ "$1" != "--silent" ]; then echo -e "== Scanning $GIT_REPO_DIR for git repos & submodules..."; fi # Get repos from src dir and custom dirs, then sort by basename - IFS=$'\n' + local IFS=$'\n' 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 -t ":" -k1,1 | cut -d ":" -f2- >| "$GIT_REPO_DIR/.git_index" - unset IFS if [ "$1" != "--silent" ]; then echo -e "===== Indexed $_bld_col$(_git_index_count)$_txt_col repos in $GIT_REPO_DIR/.git_index" @@ -207,7 +204,7 @@ _git_index_update_all_branches() { local remotes merges branches # Get branch configuration from .git/config - IFS=$'\n' + 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 @@ -225,7 +222,6 @@ _git_index_update_all_branches() { echo "=== Skipping $branch: remote and merge refs are not configured." fi done - 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 +264,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" - unset IFS + local IFS=$'\n' local base_path for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do builtin cd "$base_path" @@ -285,8 +281,7 @@ if [ $shell = 'bash' ]; then # Bash tab completion function for git_index() function _git_index_tab_completion() { _check_git_index - local curw - IFS=$'\n' + local curw IFS=$'\n' COMPREPLY=() curw=${COMP_WORDS[COMP_CWORD]} @@ -313,10 +308,9 @@ if [ $shell = 'bash' ]; then else COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)' -- $curw)) fi - unset IFS return 0 } -else +else # Zsh tab completion function for git_index() function _git_index_tab_completion() { typeset -A opt_args local state state_descr context line diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 2cadc24..6c4a972 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -125,11 +125,10 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && which ruby > /dev/null 2>&1; then fi # Parse path from args - IFS=$'\n' + local IFS=$'\n' for arg in "$@"; do if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi done - 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 +174,13 @@ EOF ll_files="$(\ls "$@")" fi - IFS=$'\n' + local 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 - 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 eb81eaf..69410a2 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -36,14 +36,13 @@ git_status_shortcuts() { files="$(echo "$cmd_output" | \grep '@@filelist@@::' | sed 's%@@filelist@@::%%g')" if [ "${scmbDebug:-}" = "true" ]; then echo "filelist => $files"; fi # Export numbered env variables for each file - IFS="|" + local IFS="|" local e=1 for file in $files; do export $git_env_char$e="$file" if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi let e++ done - unset IFS if [ "${scmbDebug:-}" = "true" ]; then echo "------------------------"; fi # Print status diff --git a/test/lib/git/repo_index_test.sh b/test/lib/git/repo_index_test.sh index c866ec4..eb98334 100755 --- a/test/lib/git/repo_index_test.sh +++ b/test/lib/git/repo_index_test.sh @@ -68,13 +68,12 @@ EOF done # Setup some custom repos outside the main repo dir - IFS=":" + local IFS=":" for dir in $GIT_REPOS; do mkdir -p $dir cd $dir git init done - unset IFS verboseGitCommands @@ -83,9 +82,8 @@ EOF oneTimeTearDown() { rm -rf "${GIT_REPO_DIR}" - IFS=":" + local IFS=":" for dir in $GIT_REPOS; do rm -rf $dir; done - unset IFS } ensureIndex() {