Hacker News new | ask | show | jobs
by tedmiston 1552 days ago
I just make bash functions in my dotfiles for use cases like these, particularly good CLI arg combinations from Stack Overflow answers, etc.

Example:

    # 2022-02-07
    # because `poetry show --outdated` includes *all* packages (!), not just top-level dependencies
    function poetry-show-outdated {
            poetry show --outdated | grep --file=<(poetry show --tree | grep '^\w' | cut -d' ' -f1)
    }
Or:

    function disk-usage-summary () {
            # output high-level disk usage stats
            set -x
            du --human-readable --summarize
            du --human-readable --max-depth=1
            df --human-readable --total
            set +x
    }
1 comments

That actually runs the commands right? How do you deal with commands that perform some action that maybe couldn't be reverted easily?
Correct.

If I don't necessarily want to run all of the commands, I make a "do-nothing script" [1][2] that just echoes them out instead.

I don't have a generalized example of undo / redo in bash commands, since I don't believe it's possible, but for example, if I'm running a destructive command, I prefer to run the dry run version first, then have a confirmation prompt [3] before running the destructive action.

[1]: https://news.ycombinator.com/item?id=20495739

[2]: https://news.ycombinator.com/item?id=29083367

[3]: https://stackoverflow.com/q/1885525/149428