├── LICENSE.md ├── README.md └── good-cat /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Andrew Lilley Brinker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `good-cat` 2 | 3 | __This cat hates pipes.__ 4 | 5 | `good-cat` is a `cat` that can't be piped. If you try, it refuses and exits with an error code. This way, no uses of `good-cat` are unnecessary [citation needed]. 6 | 7 | ## Explanation 8 | 9 | Some people think all `cat`s should hate pipes, but the `cat`s on any 10 | platform you find will go through pipes just fine. For people that can't stand 11 | `cat`s in pipes, they can use `good-cat` instead. 12 | 13 | Antipipeists will tell you that it creates a unneeded process, it stops the 14 | piped-to process from getting random access to the contents of the file, and it 15 | abuses the original purpose of `cat`. To those people I say: who cares? 16 | 17 | If the random access vs. stream-of-bytes problem is measured as an actual issue, 18 | then sure, change it. If your platform is actually having issues related to too 19 | many processes because of excess of `cat`-into-pipe, then yeah stop doing that. 20 | I wager that neither of these problems happen often. 21 | 22 | But hey, if someone's really set on complaining, you can show them a `good-cat` 23 | they'll love. 24 | 25 | ## Usage 26 | 27 | For best results, set `alias cat="good-cat"` in your shell configuration file. 28 | 29 | ```sh 30 | $ # A bad cat 31 | $ cat /var/log/apache2/access.log | awk '{print $1}' 32 | $ # A good cat 33 | $ good-cat /var/log/apache2/access.log | awk '{print $1}' 34 | $ # DOESN'T WORK! 35 | $ # So you do this instead. 36 | $ awk '{print $1}' /var/log/apache2/access.log 37 | ``` 38 | 39 | ## Contributing 40 | 41 | `good-cat` is maximally good and feature-complete [citation needed]. 42 | 43 | ## License 44 | 45 | `good-cat` is MIT licensed. See the `LICENSE.md` file for the license text. 46 | -------------------------------------------------------------------------------- /good-cat: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # This cat hates pipes. 4 | 5 | # Exit with an error if output is piped and there's only one positional 6 | # parameter. 7 | [ -t 1 -o $# -ne 1 ] || exit 1 8 | 9 | # Exit with an error if 'cat' doesn't exist 10 | command -v cat >/dev/null 2>&1 || exit 1 11 | 12 | # Otherwise, run 'cat' 13 | exec cat "$@" 14 | --------------------------------------------------------------------------------