ZSH Support?

Is there any way to get the current directory stuff to work in ZSH? iTerm2, which I currently use as my shell (and ssh client) supports ZSH for its shell integration, but simply sourcing the installed script file for Core Shell in my ~/.zshrc doesn't seem to have worked. I don't necessarily do a whole lot of downloading or uploading via ssh, unless it's something I would use rsync for, so it isn't a deal breaker for me, but it would be nice to have that option if I want it.

There is no built-in shell integration for zsh, though we plan to support it eventually. If you're familiar with zsh programming, you can translate the Bash script:

I have submitted a pull request: https://github.com/codinn/core-shell-scripts/pull/1

I used some code from the iTerm2 shell integration code because one sever I worked on didn't set $HOSTNAME. I included a note about the copied code and the github file URL in the pull request and in a comment right above the copied code. You may want to make sure you're attributing properly, or adapt the code to handle missing $HOSTNAME values without the iTerm2-derived code.

The main issues with ZSH compatibility were that the ${PWD:i:1} needed to use $i (works in bash too, I checked), and that ZSH uses a different way to hook it in. I also switched the for loop to have spaces inside the parenthesis like I usually see in shell code, and to use i++ instead of ++i since they do the same thing in that case and I've never tried ++i in shell scripting before. Those were both changes I made while trying to diagnose issues, but I didn't see any reason to revert them. The script automatically detects ZSH and uses the ZSH version of the command prompt hook, using the bash hook otherwise.

Feel free to tweak my changes as desired. They do seem to work for me, showing the proper path in the "Shell" menu for both bash and zsh, but you may have different code style you want to use, or maybe a different name for the $cs_hostname variable I created based on iTerm 2.

1 Like

Hi Eric, thank you so much for the contribution, brilliant! :+1:

I will review the changes and incorporate ZSH support in version 1.8, thank you again for your help!