2024-01-25

XONSH

Xonsh is a shell language and command prompt that is based on Python. It has extra features that make it easy to work with subprocesses, the environment, and the file system. The Xonsh command prompt lets users use the Xonsh language interactively.

Xonsh works on all major systems including Linux, OS X, and Windows. It is a superset of Python 3.6+ with additional shell primitives. Xonch lets you easily mix Python and shell commands in a powerful and simplified approach to the command line. You can use Python code and import modules in the Xonsh language, and combine Python with shell commands.

Installation

On Windows OS, it's possible to install Xonsh with Powershell/Pipx.

For the default python version:

   pipx install xonsh

will install the executables shown below.

    PS C:\Users\Seve> pipx list
    venvs are in C:\Users\Seve\AppData\Local\pipx\pipx\venvs
    apps are exposed on your $PATH at C:\Users\Seve\.local\bin
    manual pages are exposed at C:\Users\Seve\.local\share\man
       package pandas 2.1.4, installed using Python 3.10.9
        - f2py.exe
       package rich-cli 1.8.0, installed using Python 3.10.9
        - rich.exe
       package xonsh 0.14.4, installed using Python 3.10.9
        - xonsh-cat.exe
        - xonsh-uname.exe
        - xonsh-uptime.exe
        - xonsh.exe

Then, open the shell with the xonsh command and complete the installation with:

   xpip install -U 'xonsh[full]'

.xonshrc

The xonsh RC file is the run control file that is used to configure the shell environment. It is executed every time a new shell is started, and it can be used to set environment variables, define aliases, and run other shell scripts.

Xonsh customization can be obtained with a pip-installable RC created by forking xontrib-RC-awesome repository.

All the plugins will be installed automatically during pip install. After installing the RC repository with pip, you just need to edit the file ~/. xonshrc file as shown in the video below.

The shell command xontrib list allows you to list the installed plugins, which are extensions that enhance the functionality of the xonsh shell.

Customizing Xonsh Shell Prompts (Updated 2024-05-19)

If you've customized your Xonsh shell prompt (e.g., by modifying the $PROMPT variable), you might need to source the Xonsh configuration file to apply those changes. Sourcing the configuration file ensures that your specified prompt is correctly displayed.

    # filename: ~/.xonshrc
    xontrib load rc_seve
    xontrib load vox
    source ~\appdata\local\programs\python\python311\lib\site-packages\xontrib\rc_seve.xsh

Vim Terminal

To open a Xonsh shell in Vim, you can use Vim-Floaterm plugin.

First, install the plugin by following the instructions provided in the plugin's GitHub repository.

Once installed, you can open a new terminal window in Vim by running the command

   :FloatermNew xonsh 

Finally, you can customize the terminal window by creating a Vim script wrapper.

    "" filename:~/.vim/autoload/floaterm/wrapper/xonsh.vim
    function! floaterm#wrapper#xonsh#(cmd, jobopts, config) abort

      let g:floaterm_wintype = 'split'
      let g:floaterm_position = 'bottom'
      let g:floaterm_height = 0.4 
      return [v:false, 'xonsh.exe']
    endfunction