facundoolano / rpg-cli

Your filesystem as a dungeon!
MIT License
1.37k stars 32 forks source link

Probably overkill example for fish shell #42

Closed cowboy closed 3 years ago

cowboy commented 3 years ago

I feel like this function added to ~/.config/fish/config.fish should be self-explanatory. Just throwing it out there in case it "helps" anyone:

function rpg
    if string match -qr RPG (functions cd)
        echo 'Setting cd to normal mode'
        functions --erase cd
        functions --copy cd_orig cd
    else
        echo 'Setting cd to RPG mode'
        functions --erase cd_orig
        functions --copy cd cd_orig
        function cd --description 'Change directory, RPG-style'
            cd_orig $argv
            and rpg-cli $PWD
        end
    end
end

And then, of course, right after the function definition, you can silently enable rpg mode:

rpg >/dev/null
facundoolano commented 3 years ago

One note, you're changing the intended usage here (if that's your intention it's ok):

cd_orig $argv
and rpg-cli $PWD

rpg-cli works assuming that you can encounter enemies in intermediate dirs to the destination you provide, and if you do then it stops at that directory (regardless of the outcome of the battle). This is because you may change your strategy after a battle (e.g. go back home or use a potion before moving on).

So to preserve that you should use something like in the README example:

rpg-cli $argv
cd_orig (rpg-cli --pwd)

Regarding the usefulness of this example, it may be too verbose to add it to the current README, but I'm planning to have a separate shell examples doc after we add new alias capabilities, so that could be a good place to add this.

cowboy commented 3 years ago

I didn't realize that rpg-cli considered intermediary dirs as separate rooms. Was this mentioned in the readme? If so, I missed it!

While that's an interesting idea, it would be nice to have a way to disable this feature to allow it to only consider the final dir when battling. Maybe intermediary rooms can contain nothing, or treasure, but no dangers. That way, it would work better as a cd replacement.

I'm personally interested in exactly this, using rpg-cli as a cd replacement, to make moving around the shell more fun. As such, it can't ever land me in a different place than I had expected; it needs to behave exactly like cd. Which means, ideally, it would cd first, and then if the directory was successfully changed, run. I mean, maybe if the directory wasn't successfully changed, it could do something amusing, like spring a trap. That'll show you for not using tab completion!

facundoolano commented 3 years ago

That's a fair point. See the discussion in #25. The behavior you are looking for could probably be achieved by using the --alias command I mention there, basically "maybe start a battle at current dir before/after some command".

For now I think I'm going to keep the stop at intermediate dirs as the default behavior, considering you can achieve the other via alias (once that becomes available, which should be pretty soon). I'll try to make the assumptions more clear on the next version of the README.

Also I'll keep thinking about this since this has arised several times already.

cowboy commented 3 years ago

Note that one thing not covered in #25 is the ability to disable intermediary directory battles.

facundoolano commented 3 years ago

Note that one thing not covered in #25 is the ability to disable intermediary directory battles.

true, but what I'm thinking is that this --alias (actually I'm thinking in calling it --battle now) would initiate a battle in whatever current dir it's being called. So you could essentially cd and then call rpg --battle in your alias, after changing directories. The downside with this is that the location as perceived by rpg-cli wouldn't be the same as your current shell location (i.e. the output of rpg-cli commands would show the hero is still at its previous location), that's something I haven't figured out yet.

facundoolano commented 3 years ago

On further thought, I think there's no harm* in adding a lower level command, say rpg --mv <dir> that just sets the hero location without forcing a fights or stops. That, along with the --battle should provide enough flexibility to implement whatever shell integration the user wants, while preserving the default cd behavior that I prefer.

*it does open a window for cheating, but who cares

facundoolano commented 3 years ago

I just pushed a couple of changes with the --battle and --mv commands as mentioned above. Let me know if they simplify the workflow you were aiming for, and I can include your example when I rearrange the doc in the next few days.