Skip to content

Instantly share code, notes, and snippets.

@vrinek
Created May 23, 2012 07:29
Show Gist options
  • Select an option

  • Save vrinek/2773707 to your computer and use it in GitHub Desktop.

Select an option

Save vrinek/2773707 to your computer and use it in GitHub Desktop.
Add encoding line to all spec files
enc = '# -*- encoding : utf-8 -*-'
`git ls-files -- spec | xargs head -1 | grep -v encoding`.
split("\n\n").
reject{|l| l !~ /\n/}.
map{|l| l.split("\n").first}.
map{|f| f[/^==> (.*) <==$/, 1]}.
each{|f|
system "echo '#{enc}' > tempfile && cat #{f} >> tempfile && mv tempfile #{f}"
}
@alup
Copy link

alup commented May 23, 2012

Better use this for bash command:

system "echo '#{enc}' | cat - #{f} > tempfile && mv tempfile #{f}"

@vrinek
Copy link
Author

vrinek commented May 25, 2012

@alup yeah, but we need to reject first the files that already have the encoding header.

@alup
Copy link

alup commented May 25, 2012

@vrinek I mean use it in the last each block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment