Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
frederickjh opened this issue Mar 25, 2020 · 17 comments
Open

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

frederickjh opened this issue Mar 25, 2020 · 17 comments

Comments

@frederickjh
Copy link
Contributor

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
Copy link
Contributor Author

frederickjh commented Mar 25, 2020

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
Copy link
Member

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
Copy link
Member

anki-code commented Mar 25, 2020

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 anki-code changed the title Shell configuration and plugins How to write first xxh-plugin for xxh-shell-fish Mar 25, 2020
@anki-code anki-code changed the title How to write first xxh-plugin for xxh-shell-fish How to write the first xxh-plugin for xxh-shell-fish Mar 25, 2020
@anki-code
Copy link
Member

anki-code commented Mar 25, 2020

I think more simpler example is bash:

Start here instead of zsh.

@anki-code
Copy link
Member

anki-code commented Mar 25, 2020

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
Copy link
Member

anki-code commented Mar 26, 2020

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
Copy link
Contributor Author

  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
Copy link
Contributor Author

frederickjh commented Mar 26, 2020

@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
Copy link
Member

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)

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
Copy link
Member

anki-code commented Mar 26, 2020

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Member

anki-code commented Mar 26, 2020

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
Copy link
Contributor Author

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

@anki-code
Copy link
Member

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

@anki-code
Copy link
Member

anki-code commented Mar 29, 2020

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
Copy link
Member

anki-code commented Apr 4, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants