abmon-align.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # Ensure ls output is aligned when using abbreviated months from the locale
  3. # Copyright (C) 2009-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ ls
  16. mid_month="$(date +%Y-%m-15)" || framework_failure_
  17. for mon in $(seq -w 12); do
  18. touch -d"$mid_month +$mon month" $mon.ts || framework_failure_
  19. done
  20. # Note some of the following locales may be missing but if so
  21. # we should fail back to the C locale which should be aligned
  22. for format in "%b" "[%b" "%b]" "[%b]"; do
  23. for LOC in C gv_GB ga_IE fi_FI.utf8 zh_CN ar_SY $LOCALE_FR_UTF8; do
  24. # The sed usage here is slightly different from the original,
  25. # removing the \(.*\), to avoid triggering misbehavior in at least
  26. # GNU sed 4.2 (possibly miscompiled) on Mac OS X (Darwin 9.8.0).
  27. months="$(
  28. LC_ALL=$LOC TIME_STYLE=+"$format" ls -lgG *.ts |
  29. LC_ALL=C sed 's/.\{15\}//;s/ ..\.ts$//;s/ /./g')"
  30. n_widths=$(echo "$months" |
  31. while read mon; do echo "$mon" | LC_ALL=$LOC wc -L; done |
  32. uniq | wc -l
  33. )
  34. n_dupes=$(echo "$months" | sort | uniq -d | wc -l)
  35. test "$n_widths" = "1" || { fail=1; break 2; }
  36. test "$n_dupes" = "0" || { fail=1; break 2; }
  37. done
  38. done
  39. if test "$fail" = "1"; then
  40. echo "misalignment or ambiguous output in $LOC locale:"
  41. LC_ALL=$LOC TIME_STYLE=+%b ls -lgG *.ts
  42. fi
  43. Exit $fail