Skip to content

Commit

Permalink
Updating grm alias to support rm of resources where path contains s…
Browse files Browse the repository at this point in the history
…paces

`awk '{print $3}'` will give us the path following `deleted:` in the git status
output, but not the full path if it contains spaces.
`awk '{$1=$2=""; print $0}'` effectively removes `#` and `deleted:` from the
grepped line, allowing us to retrieve the remainder with `$0`. Following this
we filter out spaces at the beginning of the line and escape all remaining
spaces with `awk` and `sed`.

I suppose this could be done more elegantly (maybe
`awk '{print substr($0, 0, N)}'` where `N` is equal to the number of characters
preceding our desired path), but I honestly can't be certain of git's behavior
to expect it to work the same all the time (i.e. is it always 14 characters?
what about tabs?). Probably a noob issue...
  • Loading branch information
Gibson Starkweather committed Jun 5, 2013
1 parent dee1088 commit 3d2a856
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion git/aliases.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ alias gca='git commit -a'
alias gco='git checkout'
alias gb='git branch'
alias gs='git status -sb' # upgrade your git if -sb breaks for you. it's fun.
alias grm="git status | grep deleted | awk '{print \$3}' | xargs git rm"
alias grm="git status | grep deleted | awk '{\$1=\$2=\"\"; print \$0}' | \
sed 's/^[ \t]*//' | sed 's/ /\\\\ /g' | xargs git rm"

0 comments on commit 3d2a856

Please sign in to comment.