{"id":13541969,"url":"https://github.com/dlenski/wtf","last_synced_at":"2026-04-03T03:31:38.288Z","repository":{"id":49433740,"uuid":"23496893","full_name":"dlenski/wtf","owner":"dlenski","description":"Whitespace Total Fixer","archived":false,"fork":false,"pushed_at":"2022-10-29T23:37:41.000Z","size":73,"stargazers_count":100,"open_issues_count":10,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-02T21:02:56.336Z","etag":null,"topics":["git-hooks","text-file","utility","vcs","whitespace"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dlenski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-30T17:25:49.000Z","updated_at":"2025-01-01T22:46:46.000Z","dependencies_parsed_at":"2022-08-29T04:50:39.109Z","dependency_job_id":null,"html_url":"https://github.com/dlenski/wtf","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlenski%2Fwtf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlenski%2Fwtf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlenski%2Fwtf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlenski%2Fwtf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dlenski","download_url":"https://codeload.github.com/dlenski/wtf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254194837,"owners_count":22030432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git-hooks","text-file","utility","vcs","whitespace"],"created_at":"2024-08-01T10:00:59.510Z","updated_at":"2026-04-03T03:31:38.242Z","avatar_url":"https://github.com/dlenski.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"Whitespace Total Fixer\n======================\n\nIdentifies and/or fixes inconsistent whitespace and line endings in\ntext files, so that they don't clog up your commits to version control\nsystems like Git, Mercurial, or Subversion.\n\n[![Build Status](https://api.travis-ci.org/dlenski/wtf.png)](https://travis-ci.org/dlenski/wtf)\n\n  * [Whitespace Total Fixer](#whitespace-total-fixer)\n    * [Why you should use it](#why-you-should-use-it)\n    * [Quick Install](#quick-install)\n    * [How to use it](#how-to-use-it)\n    * [Git `pre-commit` hooks](#git-pre-commit-hooks)\n      * [Careful version](#careful-version)\n      * [Simple version](#simple-version)\n  * [Exciting origin story](#exciting-origin-story)\n  * [Whitespace issues addressed](#whitespace-issues-addressed)\n  * [Reporting](#reporting)\n  * [Todo](#todo)\n  * [Bugs](#bugs)\n    * [Bash completion](#bash-completion)\n  * [Author](#author)\n  * [License](#license)\n\n### Why you should use it:\n\n* It's like an incomprehensible shell-script one-liner (e.g. `sed -e 's/LINENOISE/'`), but way better\n* It's similar to [`git\n  stripspace`](https://www.kernel.org/pub/software/scm/git/docs/git-stripspace.html),\n  but more flexible and detailed.\n* `wtf.py` is a simple Python script with *no dependencies beyond the standard Python library*.\n  It should run correctly with either Python 2.7 or 3.x.\n\n\n### Quick Install\n```\ncurl https://raw.githubusercontent.com/dlenski/wtf/master/wtf.py \u003e ~/bin/wtf.py \u0026\u0026 chmod 0755 !#:3\n```\n\n### How to use it\n\n[See below](#options) for options to control exactly which\nwhitespace issues it fixes, but here are some examples:\n\n```bash\n# consistent whitespace from programs that generate text files\ndump_database_schema | wtf.py -o clean_output.sql\n\n# in-place editing\nwtf.py -i file1.txt file2.txt file3.txt\nwtf.py -I.bak file1.txt file2.txt file3.txt # ditto, with backups\n\n# summarize a bunch of files without actually editing them (-0)\nfind . -name \"*.txt\" -exec wtf.py -0 {} \\;\n\n# more advanced: find interesting text files. pass options and a directory\nwtf-find() {\n    find \"${@: -1}\" -not \\( -name .svn -prune -o -name .git -prune \\\n         -o -name .hg -prune \\) -type f -exec bash -c \\\n         'grep -Il \"\" \"$1\" \u0026\u003e/dev/null \u0026\u0026 wtf.py '\"${*:1:$#-1}\"' \"$1\"' _ {} \\;\n}\nwtf-find -0 .\n\n# exit status\nwtf.py file1.txt file2.txt file3.txt \u003e /dev/null\nif (( $? == 10 )); then\n  echo \"issues fixed\"\nelif (( $? == 20 )); then\n  echo \"unfixed issues!\"\nfi\n```\n\nGit `pre-commit` hooks\n----------------------\n\nYou can use [Git `pre-commit` hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)\nto automatically run `wtf` and cleanup whitespace in your repository\nprior to every commit.\n(You can bypass the hook, however, with `git commit [--no-verify|-n]`.)\n\n### Careful version\n\nThe [pre-commit.careful](https://github.com/dlenski/wtf/blob/HEAD/pre-commit.careful) hook\nwill run `wtf`, with the default options, on all the to-be-committed\ntext files. You can easily use it as-is by creating a symlink, for example\nby running the following in your repository's working directory:\n```sh\nln -s /path/to/wtf/source/pre-commit.careful .git/hooks/pre-commit\n```\n\nIf you want to modify it, create the file `.git/hooks/pre-commit` in your\nrepository's working directory, and ensure that it is executable (with\n`chmod +x .git/hooks/pre-commit`).\n\nFeatures:\n\n1. This hook _only_ modifies your commits, and does not touch Git's\n   working tree. If you understand and use Git's index (\"staging area\"),\n   this should make sense. It will play nicely with `git add --patch`.\n2. It skips over files marked as `binary` or non-text (`-text`)\n   according to your repository's  https://git-scm.com/docs/gitattributes\n3. Note that when a file changes in your commit but remains unchanged in\n   your working tree, the file will be marked `modified` by `git status`\n   immediately after the commit.\n\n### Simple version\n\nThis version modifies Git's working tree as well as your commits. **This version will not play nicely with\n`git add --patch`.**\n\nThis version will run `wtf -i`, with any other options you add to `wtf_options`, on all the\nto-be-committed text files. They will be cleaned up in the commit, as\nwell as in your working tree.\n\n```bash\n#!/bin/sh\nwtf_options=''\n\n# get a list of to-be-committed filepaths, EXCLUDING files considered\n# by Git to be binary\ncommittees=$(git diff --cached --numstat --diff-filter=ACMRTU|egrep -v ^-|cut -f3-)\n\n# Run Whitespace Total Fixer in-place, and re-add files modified by it\nfor committee in $committees\ndo\n\twtf -i $wtf_options \"$committee\" || git add \"$committee\"\ndone\n```\n\nExciting origin story\n---------------------\n\nOne day at work, I spent way too much time wrangling commits\nladen with whitespace issues generated by recalcitrant text-editing\ntools on multiple platforms.\n\nThat evening, I went home and spent way too much time writing this\nprogram instead!\n\n\u003ca name=\"options\"/\u003eWhitespace issues addressed\n----------------------------------------------\n\nWTF currently fixes, or simply reports, a few common types of whitespace\nissues. Most of these issues offer three possible command-line options\nenabling the user to fix, report, or ignore the issue.\n\n* Remove trailing spaces at the ends of lines (default is **fix**):\n\n        -t, --trail-space\n        -T, --report-trail-space\n        -It, --ignore-trail-space\n\n* Remove blank lines at the ends of files (default is **fix**):\n\n        -b, --eof-blanks\n        -B, --report-eof-blanks\n        -Ib, --ignore-eof-blanks\n\n* Ensure that a new-line character appears at the end of the file (default is **fix**):\n\n        -n, --eof-newl\n        -N, --report-eof-newl\n        -In, --ignore-eof-newl\n\n* Make sure that all lines have matching EOL markers (that is, no\n  mixing of lf/crlf). Default is to **fix** non-matching EOL\n  characters by making them all the same as the first line of the\n  file. The desired EOL markers can also be set to a specific value\n  (`lf`/`crlf`/`native`), in which case all lines will unconditionally\n  receive this marker.\n\n        -E ENDING, --coerce-eol ENDING\n        -e ENDING, --expect-eol ENDING\n        -Ie, --ignore-eol\n\n* Check for spaces followed by tabs in the whitespace at the beginning\n  of a line; fixing this condition requires setting either\n  `--change-tabs` or `--change-spaces`. The default is to report and\n  **warn**:\n\n        -s, --tab-space-mix\n        -S, --report-tab-space-mix\n        -Is, --ignore-tab-space-mix\n\n* Change tabs in the whitespace at the beginning of a line to the\n  specified number of spaces (default is not to change tabs at\n  all). This option will *not* touch leading tabs when they are mixed\n  with spaces, *unless* `--tab-space-mix` is also specified.\n\n        -x SPACES, --change-tabs SPACES\n\n* Change the specified number of consecutive spaces in the whitespace\n  at the beginning of a line to tabs (default is not to change spaces\n  at all). This option will *not* touch leading tabs when they are mixed\n  with spaces, *unless* `--tab-space-mix` is also specified.\n\n        -y SPACES, --change-spaces SPACES\n\nReporting\n---------\n\nUnless the `-q`/`--quiet` option is used, WTF will summarize each file\nprocessed in which any whitespace issues were found and/or fixed. With\n`-v` it will also report issue-free files.\n\n    $ wtf -0 nightmare.txt    # -0 is equivalent to \u003e /dev/null\n    nightmare.txt LINE 8: WARNING: spaces followed by tabs in whitespace at beginning of line\n    nightmare.txt:\n        CHOPPED 1 lines with trailing space\n        CHOPPED 0 blank lines at EOF\n        ADDED newline at EOF\n        CHANGED 1 line endings which didn't match crlf from first line\n        WARNED ABOUT 1 lines with tabs/spaces mix\n\nWTF will return the following exit codes on successful operation:\n\n* `0`: no issues seen (or `-X`/`--no-exit-codes` specified)\n* `10`: issues fixed\n* `20`: unfixed issues seen\n\nTodo\n----\n\n* Stability tests?\n* Unicode tests?\n\nBugs\n----\nCorrupts source code files written in the [Whitespace programming language](https://en.wikipedia.org/wiki/Whitespace_(programming_language)).\n\nAnything else?\n\n### Bash completion\n\nIf you are having problems with tab completion in Bash,\nit is probably because of default completion rules for the unrelated\nutility [`wtf(6)`](https://linux.die.net/man/6/wtf).\nYou can override this by adding the following to your `~/.bashrc`:\n\n```bash\ncomplete -o default -o bashdefault wtf\n```\n\nAuthor\n------\n\u0026copy; Daniel Lenski \u003c\u003cdlenski@gmail.com\u003e\u003e (2014-2020)\n\nLicense\n-------\n[GPL v3 or later](http://www.gnu.org/copyleft/gpl.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdlenski%2Fwtf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdlenski%2Fwtf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdlenski%2Fwtf/lists"}