romkatv/zsh-bin

Single entrypoint

anki-code opened this issue · 5 comments

Hello! Great work!

What about zsh.sh as single entrypoint?

#!/bin/sh

CDIR="$(cd "$(dirname "$0")" && pwd)"

if [ -f $CDIR/.zsh_dir ]; then
  zsh_dir=`cat $CDIR/.zsh_dir`
else
  zsh_dir=$CDIR
  echo $zsh_dir > $CDIR/.zsh_dir
fi

if [ $CDIR != $zsh_dir ]; then
  $CDIR/../share/zsh/5.8/scripts/relocate
  echo $CDIR > $CDIR/.zsh_dir
fi

$CDIR/zsh "$@"

Thanks!

I'm not sure I understand the question/suggestion. Could you describe the problem you want to address?

I want to avoid running relocate manually.

Now:

apps/zsh-5.8-linux-x86_64-static/share/zsh/5.8/scripts/relocate
apps/zsh-5.8-linux-x86_64-static/bin/zsh # run zsh
mv apps apps2
apps2/zsh-5.8-linux-x86_64-static/share/zsh/5.8/scripts/relocate
apps2/zsh-5.8-linux-x86_64-static/bin/zsh # run zsh

I suggest:

apps/zsh-5.8-linux-x86_64-static/bin/zsh.sh # run zsh
mv apps apps2
apps2/zsh-5.8-linux-x86_64-static/bin/zsh.sh # run zsh

I agree that having to run relocate after moving the installation directory of zsh is a nuisance. My assumption has been that no one actually needs to do that. Do you have a use case for doing this? Could you share what it is?

The script you suggested unfortunately introduces several issues of its own. It'll slow down every zsh invocation, will cause unpredictable behavior due to race conditions, will fail when the installation directory isn't writable, and will misbehave in a few obscure cases. I think for most users it's more important to have zsh that works flawlessly after installation than to have an ability to move zsh directory seamlessly. I might be wrong though. Luckily, it's possible to add a script you suggest inside the zsh directory after installation, so users who care about this can do this. If xxh cares about this, it can also do this, given that it controls the installation process.

My assumption has been that no one actually needs to do that.

You added relocate as required step after install. I just think that this kind of logic are good to place in code, not in readme. If you don't like distinct file may be just compare the magic path in zsh binary with current path and if it differ do relocation.

If xxh cares about this, it can also do this, given that it controls the installation process.

Already done it. Feel free to close this issue.

My assumption has been that no one actually needs to do that.

You added relocate as required step after install. I just think that this kind of logic are good to place in code, not in readme.

Currently installation instructions consist of 6 commands. Reducing that number to 5 doesn't seem like a sizable improvement. As I mentioned earlier, starting zsh via zsh.sh would introduce issue (a.k.a. bugs). It's not worth having these issues for the sake of saving one line in installation instructions.

Users are free to put all 6 commands in a single script and use it. They can also add download step and whatnot.

If you don't like distinct file may be just compare the magic path in zsh binary with current path and if it differ do relocation.

There is no reliable way to get the path to the currently executing binary. If there way, zsh wouldn't be hard-coding paths in the first place.

If xxh cares about this, it can also do this, given that it controls the installation process.

Already done it. Feel free to close this issue.

Great! Closing then.