bash-cache icon indicating copy to clipboard operation
bash-cache copied to clipboard

Support zsh and other shells

Open dimo414 opened this issue 5 years ago • 3 comments

Original report by Michael Diamond (Bitbucket: dimo414).


@bedge asked for zsh support in #15. Supporting other shells would be nice, but would require user contributions as it's not a priority for me personally. If anyone's interested in contributing feel free to reach out here.

dimo414 avatar May 25 '19 21:05 dimo414

Just switched to zsh from bash because I'm using MacOS and didn't want to keep using an outdated version of bash. I'm really sad to be losing bash-cache functionality it's quite helpful in my tmux status bar scripts which hit external APIs.

What steps would be necessary to make bash-cache work for zsh?

KTSCode avatar Aug 05 '21 00:08 KTSCode

FWIW it's pretty easy to get a modern bash running on macOS; with homebrew it's just brew install bash.

I really don't know how much work would be involved. As I don't use zsh I'm not sure exactly which bash-isms would need to be redesigned (or the best way to do it). But I wouldn't be surprised if it's non-trivial, since bash-cache does some distinctly power-user things. Some potential issues that stand out:

  • bc::copy_function enables the decorator pattern bash-cache uses
  • The function-template pattern isn't strictly necessary but I'd be disappointed to have to remove it
  • This descriptor juggling is important for safe reads
  • bc::locked_cache requires Bash 4.1's anonymous descriptor support

dimo414 avatar Aug 05 '21 07:08 dimo414

I'm in the process of publishing bkt, a standalone binary that's spiritually similar to bash-cache but intended for subprocesses instead of shell functions. Although it fits a slightly different niche than caching shell functions it may still be useful for zsh et al. users. If you'd like to try it out I'd welcome any feedback.

dimo414 avatar Oct 07 '21 22:10 dimo414