git_status_shortcuts: don't clobber $IFS

This commit is contained in:
Tom "Ravi" Hale
2018-08-24 18:12:07 +07:00
parent 3a5b7a685a
commit d5c60b2cc5
7 changed files with 17 additions and 32 deletions

View File

@@ -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
}

View File

@@ -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" ""

View File

@@ -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'.

View File

@@ -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

View File

@@ -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

View File

@@ -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