xxh / xxh-shell-fish

Use the fish shell wherever you go through the SSH without installation on the host.
BSD 2-Clause "Simplified" License
18 stars 12 forks source link

Set $XDG_DATA_HOME so that it is inside $XXH_HOME , to not polute the user's home folder with with this data. #6

Closed frederickjh closed 4 years ago

frederickjh commented 4 years ago

The Fish shell package manager Fisher and others, use $XDG_DATA_HOME which by default is set to ~/.local/share.

anki-code commented 4 years ago

I'm going to change the logic from:

export XDG_CONFIG_HOME=$XXH_HOME/.config

if [[ $HOMEPATH != '' ]]; then
# setting $HOME
fi

To:

if [[ $HOMEPATH != '' ]]; then
# setting $HOME
fi

export XDG_CONFIG_HOME=$HOME/.config

It looks more natural and expected.

frederickjh commented 4 years ago

I'm going to change the logic from:

export XDG_CONFIG_HOME=$XXH_HOME/.config

if [[ $HOMEPATH != '' ]]; then
# setting $HOME
fi

To:

if [[ $HOMEPATH != '' ]]; then
# setting $HOME
fi

export XDG_CONFIG_HOME=$HOME/.config

It looks more natural and expected.

Sorry I don't understand this change.

Why did you switch from using $XXH_HOME to $HOME to set the XDG directories?

If you do this what is the point of setting them at all?

The configuration files, data files and cache you want to all be in the $XXH_HOME so it is "hermetic".

I do not want $HOME to be the same as $XXH_HOME, which is what you have done with this code.

So with this change whatever is set with +hhh for $HOME is also set for the XDG directories.

I am going to make a pull request to change setting the XDG directories back to using $XXH_HOME.

frederickjh commented 4 years ago

Ah, I just figured out that this broke long before your change from $XXH_HOME to $HOME. It was when you switched from using dirname to readlink. See the reference below to 0.6.22

anki-code commented 4 years ago

The configuration files, data files and cache you want to all be in the $XXH_HOME so it is "hermetic".

Let's think step by step. Validate my logic please.

For example user has Midnight Commander (mc) on the host and user set the "dark" theme for mc. This means that in ~/.config/mc we have dark theme settings and in ~/.local/cache/mc we have temporary mc data. Right?

User xxh to the host with default settings. What happened when he run mc? It will be run as "first run" because ~/.xxh/.config/ and ~/.xxh/.local/ is empty. Right?

The user set the light theme and we have the light theme settings in ~/.xxh/.config/mc. Right?

As result user has "dark mc" when he do ssh and the "light mc" when he do xxh. Right?

After time user thinks "it's not bad if I'll use my home as xxh home to avoid difference" and he add +hhh "~" argument to config.xxhc. After this when he xxh to the host he will be in "dark mc" forever. Right?

This looks as expected logic. Right?

Let's read the code:

export XXH_HOME=`readlink -f $CURRENT_DIR/../../../..`
export PATH=$CURRENT_DIR/fish-portable/bin:$PATH

if [[ $HOMEPATH != '' ]]; then
  homerealpath=`readlink -f $HOMEPATH`
  if [[ -d $homerealpath ]]; then
    export HOME=$homerealpath
  else
    echo "Home path not found: $homerealpath"
    echo "Set HOME to $XXH_HOME"
    export HOME=$XXH_HOME
  fi
else
  export HOME=$XXH_HOME
fi

export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CACHE_HOME=$HOME/.cache

Here we see that if $HOMEPATH is set (from entrypoint argumet -H) it will change the $HOME (to ~ for example). Otherwise the $HOME will be $XXH_HOME.

frederickjh commented 4 years ago

All what you are saying is true.

However you are binding $HOME and the XDG directories together, which I do not believe is the point of the XDG directories. The point of the XDG directories is so the user can choose where this data gets placed if they do not want it in default of $HOME.

When I work on a server I mainly work out of $HOME. I don't want to start or be brought back to $HOME/.xxh. On the other hand it would be nice if I can do rm -rf ~/.xxh and xxh is cleaned up and gone when I am finished. With the current code this is not possible.

I believe this is a design decision, however as the code is now, this is not to my liking nor to my way of working.

anki-code commented 4 years ago

I think you try to say that $HOME, XDG and $XXH_HOME is three different places and them should be customizable.

Could you please give me your real life example?

  1. What is the $HOME, what is the $XDG_...?
  2. Why you don't use +hhh "~"?
  3. If we add new +hhx argument for XDG paths is it will work for you?
anki-code commented 4 years ago

When I work on a server I mainly work out of $HOME. I don't want to start or be brought back to $HOME/.xxh. On the other hand it would be nice if I can do rm -rf ~/.xxh and xxh is cleaned up and gone when I am finished. With the current code this is not possible.

May be you not clearly understand what +hhh "~" means? It means that xxh place xxh packages to ~/.xxh and $HOME will be ordinary /home/user directory. This is the behavior of xxh<0.7.0 and it should work for you. Doesn't it? If no, why?

anki-code commented 4 years ago
  1. If we add new +hhx argument for XDG paths is it will work for you?

This means this logic:

  1. xxh myhost:

    $XXH_HOME=/home/user/.xxh
    $HOME=/home/user/.xxh
    $XDG_...=/home/user/.xxh/...
  2. xxh myhost +hhh "~":

    $XXH_HOME=/home/user/.xxh
    $HOME=/home/user
    $XDG_...=/home/user/.xxh/...
  3. xxh myhost +hhh "~" +hhx "~":

    $XXH_HOME=/home/user/.xxh
    $HOME=/home/user
    $XDG_...=/home/user/...

    Is it working for you?

anki-code commented 4 years ago

I've added the logic above - https://github.com/xxh/xxh-shell-fish/commit/b56b1bad40e17c32b322407ffd3447c7edbb8724

anki-code commented 4 years ago

So I've released xxh 0.7.6 with support of this logic - https://github.com/xxh/xxh-shell-fish/pull/6#issuecomment-606160402

@frederickjh it should works for you.

frederickjh commented 4 years ago

From the README.md

Hermetic. If you delete ~/.xxh directory from the remote host then xxh has never been on the host. If files appears outside xxh home directory feel free to report about this cases.

How can you make this claim about xxh if you allow the user to set $HOME with at least a warning that their data will then no longer be contained in the ~/.xxh directory?

I think this project has strayed from sensible default settings. I think that they should be the following:

$HOME should be left alone. Why are we messing with it when we have the XDG directories? $XXH_HOME = $HOME/.xxh This is one thing I think that we agree on.

XDG Directories $XDG_CONFIG_HOME="$HOME/.xxh/.config" $XDG_DATA_HOME="$HOME/.xxh/.local/share" $XDG_CACHE_HOME="$HOME/.xxh/.cache"

I didn't complain much when you decided to set $HOME to /home/username/.xxh by default as you added a setting for it. I would just set the three XDG directories using the +e option but only one of the environmental variable seems to get set from config.xxhc.

So no, I do not agree with the logic above. xxh should leave $HOME alone and the XDG directories by default should be inside the $XXH_HOME. The XDG directories should NOT be connected the $HOME setting.

anki-code commented 4 years ago

So no, I do not agree with the logic above. xxh should leave $HOME alone and the XDG directories by default should be inside the $XXH_HOME. The XDG directories should NOT be connected the $HOME setting.

Got it! Please update to xxh 0.7.6, update xxh-shell-fish and try xxh myhost +s fish +hhh "~" +if. After this command it will work as you need:

$XXH_HOME=/home/user/.xxh
$HOME=/home/user
$XDG_...=/home/user/.xxh/...

Is it the solution? :)

frederickjh commented 4 years ago

OK, looking at the code it looks like it will work but sub-optimal defaults for on-boarding new users.

anki-code commented 4 years ago

OK, looking at the code it looks like it will work but sub-optimal defaults for on-boarding new users.

I understand what you want to say. My logic is:

I'm going to add the clarifications to README.

anki-code commented 4 years ago

Done - https://github.com/xxh/xxh#how-to-set-homeuser-as-home-instead-of-homeuserxxh

Will look to feedback. @frederickjh thank you! I hope I helped you and the time will show what is the best default values.

frederickjh commented 4 years ago

OK, looking at the code it looks like it will work but sub-optimal defaults for on-boarding new users.

I believe I owe you an apology. For some reason I think I misread your new code handling the XDG directories. I have taken another look at the code and tested and I believe that this is now working correctly. Sorry.

anki-code commented 4 years ago

No problem! We made the review and as result the logic looks more consistent.