xxh / xxh-shell-fish

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

How to write the first xxh-plugin for xxh-shell-fish #1

Open frederickjh opened 4 years ago

frederickjh commented 4 years ago

Now that I have this working I am wondering how my shell config gets to the remote host.

From the README.md xxh/xxh

You chosen a command shell and spent months to stuffed it with shortcuts and colors. But when you move from local to remote host using ssh you lose it all. The mission of xxh is to bring your favorite shell wherever you go through the ssh.

I would take this to mean that some how my local shell configuration gets transferred to the remote hosts I connect to with xxh.

Also the link to the example plugin xxh/xxh-plugin-fish-sample is a broken link. I might take a crack at making a plugin if I knew how and for what.

frederickjh commented 4 years ago

OK, I just found the xxh/xxh-plugin-zsh-ohmyzsh plugin which brings the current zsh them to the ssh. So, I am guessing we first need a xxh/xxh-plugin-fish-ohmyfish plugin to do the same for the Fish shell.

anki-code commented 4 years ago

You're the first who writes xxh-plugin for fish and I'll help you to pass this path. I'll describe step by step and zsh will be an example (because I'm not the user of fish):

  1. In the xxh/xxh-shell-fish repo you should should create RC file for fish. It's the file which shell read when start. It's .bashrc for bash or .zshrc for zsh.
  2. In the RC file you should find pluginrc.fish files for plugins and "source" them. Example for zsh - https://github.com/xxh/xxh-shell-zsh/blob/master/.zshrc#L9
  3. Then you should create xxh-plugin-fish-yourname repo with pluginrc.fish file and build.sh file with what functions you need. For example https://github.com/xxh/xxh-plugin-zsh-powerlevel10k

How it works: When you xxhing to the host the xxh upload the shell and plugins and xxh-shell runs RC file which "source" the plugin RC files. As result you have your favorite shell with your plugins.

anki-code commented 4 years ago

Simple development workflow:

mkdir ~/xxh && cd ~/xxh
git clone https://github.com/xxh/xxh-shell-fish
mkdir xxh-plugin-fish-sample
echo 'echo Plugin works!' > xxh-plugin-fish-sample/pluginrc.fish

... add xxh-plugin-fish-sample/build.sh ...
... add xxh-shell-fish/fishrc

xxh myhost +if +RI xxh-shell-fish+path+/home/user/xxh/xxh-shell-fish +RI xxh-plugin-fish-sample+path+/home/user/xxh/xxh-plugin-fish-sample

The last command will be install the shell and plugin every before every connect.

When debugging of RC file is over you could remove +RI for shell and debug the plugin.

anki-code commented 4 years ago

I think more simpler example is bash:

Start here instead of zsh.

anki-code commented 4 years ago

I've updated xxh-shell-fish and it has all fish functionality now with reduced size of package. Recommend to update:

xxh +RI xxh-shell-fish
xxh myhost +if
anki-code commented 4 years ago

Also the link to the example plugin xxh/xxh-plugin-fish-sample is a broken link.

I've added the sample plugin repo: https://github.com/xxh/xxh-plugin-fish-sample

frederickjh commented 4 years ago
  1. In the xxh/xxh-shell-fish repo you should should create RC file for fish. It's the file which shell read when start. It's .bashrc for bash or .zshrc for zsh.

For Fish shell this is ~/.config/fish/config.fish.

OK since the the RC file is sourcing the pluginrc.fish files for plugins these should be written in Fish shell syntax. Correct? Is there a reason they are source and not run directly?

frederickjh commented 4 years ago

@anki-code Another question. On the xxh/xxh page it states:

Portable means clean. If you delete ~/.xxh directory from the remote host then xxh has never been on the host. Some temporary files of third party tools you use could be in the home directory after usage but we stand for moving them to the xxh home directory. Feel free to report about this cases.

Where is it expected that the shells that get installed store their configuration files, scripts, etc.? Is this in the normal locations where the shell expects to find them or in the .xxh directory?

I saw that when I ran the command above xxh myhost +if I saw that the ~/.xxh folder got removed with a forced install.

anki-code commented 4 years ago

By default:

Ordinary +if is using to update xxh to new version on host. And +iff rare use to make full cleaning.

If you want to save some files between xxh updating place it to ~/.xxh for example in ~/.xxh/.xxh-plugin-fish-name/. I think dot in the beginning is good because ~/.xxh could becomes $HOME. I think about this option.

anki-code commented 4 years ago

For Fish shell this is ~/.config/fish/config.fish.

We should find a way to change this for xxh-shell or ask fish shell developers.

OK since the the RC file is sourcing the pluginrc.fish files for plugins these should be written in Fish shell syntax. Correct?

Yes

Is there a reason they are source and not run directly?

Yes. Because environment variables should be shared from entrypoint to the shell and to the plugins at the end.

frederickjh commented 4 years ago

For Fish shell this is ~/.config/fish/config.fish.

We should find a way to change this for xxh-shell or ask fish shell developers.

I already asked in the Fish Shell gitter channel. The Fish shell config directory can be set by setting the XDG_CONFIG_HOME environmental variable. I have already tested this on a host that has my user locked out of ~/.config. I used the +e option to set this. From ~/.xxh/.xxhc:

  "hostname":
     +e: 'XDG_CONFIG_HOME="$HOME/.myconfig"'

Fish then places or looks for it config in the ~/.myconfig/fish/ directory, so the main Fish configuration file is located at ~/.myconfig/fish/config.fish.

If you want to save some files between xxh updating place it to ~/.xxh for example in ~/.xxh/.xxh-plugin-fish-name/. I think dot in the beginning is good because ~/.xxh could becomes $HOME. I think about this option.

Is a subdirectory of ~/.xxh/ where the Fish shell configuration should get saved? So something like ~/.xxh/.xxh-shell-fish/fish/config.fish or is this just for the plugins?

frederickjh commented 4 years ago

By default:

* `~/.xxh` - xxh "root" directory. It will be deleted when using `+iff` (install force full)

* `~/.xxh/xxh` - xxh packages directory. It will be deleted when using `+if` (install force)

Your right. I scrolled back through my shell and found that ~/.xxh/xxh was what got removed when running xxh myhost +if and not ~/.xxh.

anki-code commented 4 years ago

Is a subdirectory of ~/.xxh/ where the Fish shell configuration should get saved? So something like ~/.xxh/.xxh-shell-fish/fish/config.fish or is this just for the plugins?

Think about ~/.xxh as a home. Place there any you want to save between sessions or xxh updates.

frederickjh commented 4 years ago

I see a number pieces of information in this issue that should make it into the documentation.

anki-code commented 4 years ago

You're completely right. I'll do it a bit later.

anki-code commented 4 years ago

I've added xxh-plugin-bash-ohmybash plugin. So you can review the simplest Bash version of xxh packages ecosystem:

  1. Load bashrc file in entrypoint.sh
  2. Load pluginrc.sh in bashrc file
  3. Load ohmybash in pluginrc.sh
anki-code commented 4 years ago

@frederickjh I've added new type of plugins: prerun plugins in xxh 0.7.11. Prerun plugin is a bash script which will be run on entrypoint stage immediately before shell running. It can help to bring some config files before running shell.

xxh-plugin-prerun-mc - first prerun plugin for Midnight Commander which creates ~/.config/mc/ini file if it is not exists.

For your fish plugins you can just add pluginrc_prerun.sh script to create configs before running shell with fish plugins.

More info - https://github.com/xxh/xxh/wiki#what-is-xxh-prerun-plugin