Fix add/remove with spaces/special characters
This commit is contained in:
@@ -74,17 +74,21 @@ git_add_shortcuts() {
|
||||
# Does nothing if no args are given.
|
||||
git_silent_add_shortcuts() {
|
||||
if [ -n "$1" ]; then
|
||||
# Expand args and process resulting set of files.
|
||||
for file in $(git_expand_args "$@"); do
|
||||
|
||||
function process {
|
||||
file=$1
|
||||
# Use 'git rm' if file doesn't exist and 'ga_auto_remove' is enabled.
|
||||
if [[ $ga_auto_remove == "yes" ]] && ! [ -e $file ]; then
|
||||
if [[ $ga_auto_remove == "yes" ]] && ! [ -e "$file" ]; then
|
||||
echo -n "# "
|
||||
git rm $file
|
||||
git rm "$file"
|
||||
else
|
||||
git add $file
|
||||
git add "$file"
|
||||
echo -e "# add '$file'"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Expand args and process resulting set of files.
|
||||
eval for file in $(git_expand_args "$@")\; do process "\$file"\; done
|
||||
echo "#"
|
||||
fi
|
||||
}
|
||||
@@ -109,9 +113,10 @@ git_add_patch_shortcuts() {
|
||||
git_silent_add_patch_shortcuts() {
|
||||
if [ -n "$1" ]; then
|
||||
# Expand args and process resulting set of files.
|
||||
for file in $(git_expand_args "$@"); do
|
||||
git add -p $file
|
||||
echo -e "# add '$file'"
|
||||
local IFS=$'\n'
|
||||
eval for file in $(git_expand_args "$@")\; do\
|
||||
git add -p "\$file"\;\
|
||||
echo -e "# add '\$file'"\;\
|
||||
done
|
||||
echo "#"
|
||||
fi
|
||||
@@ -136,21 +141,36 @@ git_show_affected_files(){
|
||||
# * git_status_shortcuts() - git status implementation
|
||||
# * git_show_affected_files() - shows files affected by a given SHA1, etc.
|
||||
git_expand_args() {
|
||||
files=""
|
||||
first=1
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" =~ ^[0-9]+$ ]] ; then # Substitute $e{*} variables for any integers
|
||||
files="$files $(eval echo \$$git_env_char$arg)"
|
||||
elif [[ $arg =~ ^[0-9]+\.\.[0-9]+$ ]]; then # Expand ranges into $e{*} variables
|
||||
files="$files $(eval echo \$$git_env_char{$arg})"
|
||||
if [ "$first" -eq 1 ]; then
|
||||
first=0
|
||||
else
|
||||
echo -n " "
|
||||
fi
|
||||
eval printf '%q' "\$$git_env_char$arg"
|
||||
elif [[ "$arg" =~ ^[0-9]+\.\.[0-9]+$ ]]; then # Expand ranges into $e{*} variables
|
||||
for i in $(eval echo {$arg}); do
|
||||
if [ "$first" -eq 1 ]; then
|
||||
first=0
|
||||
else
|
||||
echo -n " "
|
||||
fi
|
||||
eval printf '%q' "\$$git_env_char$i"
|
||||
done
|
||||
else # Otherwise, treat $arg as a normal string.
|
||||
# If arg contains any spaces, (re)wrap it in double quotes
|
||||
if echo $arg | grep -q " "; then arg="\"$arg\""; fi
|
||||
files="$files $arg"
|
||||
if [ "$first" -eq 1 ]; then
|
||||
first=0
|
||||
else
|
||||
echo -n " "
|
||||
fi
|
||||
printf '%q' "$arg"
|
||||
fi
|
||||
done
|
||||
echo $files
|
||||
}
|
||||
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6..12
|
||||
# Fails if command is a number or range (probably not worth fixing)
|
||||
exec_git_expand_args() { $(git_expand_args "$@"); }
|
||||
|
||||
# Clear numbered env variables
|
||||
@@ -164,8 +184,8 @@ git_clear_vars() {
|
||||
|
||||
|
||||
# Shortcuts for resolving merge conflicts.
|
||||
ours(){ local files=$(git_expand_args "$@"); git checkout --ours $files; git add $files; }
|
||||
theirs(){ local files=$(git_expand_args "$@"); git checkout --theirs $files; git add $files; }
|
||||
ours(){ local files=$(git_expand_args "$@"); git checkout --ours "$files"; git add "$files"; }
|
||||
theirs(){ local files=$(git_expand_args "$@"); git checkout --theirs "$files"; git add "$files"; }
|
||||
|
||||
|
||||
# Git commit prompts
|
||||
|
||||
Reference in New Issue
Block a user