Guest User

Untitled

a guest
May 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #!/usr/bin/env zsh
  2.  
  3. # UIB-290708 DOUBLE SPACE TEXT FILES
  4.  
  5. for file in **/*(.); do
  6.  
  7. # Check if file is text.
  8.  
  9. if file -b $file | grep -q "text"; then
  10.  
  11. # Double space.
  12.  
  13. sed -i '' 's/^$/d;G' $file
  14.  
  15. # Insert a blank line on top, unless there's a shebang or DOCTYPE declaration.
  16.  
  17. read line < $file;
  18.  
  19. if ! [[ $line = ['#<']!* ]]; then
  20.  
  21. sed -i '' '1{x;p;x}' $file
  22.  
  23. fi
  24.  
  25. # Remove excess whitespace after indents.
  26.  
  27. sed -i '' 's/\([^ ]\) +/\1 /' $file
  28.  
  29. echo "$file"
  30.  
  31. fi
  32.  
  33. done
Add Comment
Please, Sign In to add comment