zsh-dwim: Simple chmod and chattr Transforms Are Too Simple

| Comments

Late last year, my friends and I were playing quite a bit of Borderlands 2. If you only have a finite amount of time, multiplayer Borderlands 2 involves a bit of cheating. Instead of farming the same items over and over again for all your friends every time you level up, it is much easier to just duplicate the items.

Duplicating items is very easy, and it involves switching your profile.bin file back and forth between read-write and read-only. That involves a lot of alternating chmod -w and chmod +w` commands. I must have done this hundreds of times before realizing that this would be an excellent fit for zsh-dwim!

What should zsh-dwim do with chmod?

This is a much harder question to answer than I had anticipated. I ended up choosing the most simple option—just flipping the state of the plus and minus signs. I had some other ideas, but I couldn’t decide what was actually appropriate.

I thought about making zsh-dwim check the current permissions of the files on the command line. Then it might just be a simple matter of setting the permission options on the command line to match the inverse of the actual permissions of the file. This seemed like an excellent idea at first, but the more I thought about it, the more complicated things became.

What if there are multiple files on the command line? What if the permissions on all of those files don’t match? What is the correct assumption to make in this case? Should zsh-dwim just check the first file? I don’t know if there is a good choice to make here.

There are other interesting options besides checking out the current permissions of the files on the command line. It might be interesting to have zsh-dwim toggle one +/- sign each time you press the key. If zsh-dwim could maintain a bit more state information, they could flip in a nice, predictable order.

This would probably work out alright if there were only two + or - signs on the command line. Any more than that, and the number of key presses required to reach the state you’re looking for could get pretty high.

Should zsh-dwim be stateful?

I am tempted to add some state information to zsh-dwim. It would be neat to even be able to better cycle through a sequence of related transforms. I want to be able to just hit a single key and have zsh-dwim just “do what I mean.” I don’t really want to be banging on the key over and over again, and I most definitely don’t want to be stuck cycling through any extra useless transforms while looking for the right one.

These new transforms may be a little too simple, but they are handy enough as they are, and I think they’re good enough for now.

What do you think? Leave a comment and let me know. I’m interested in hearing you opinion!

Comments