Git Product home page Git Product logo

zsh-nix-shell's Introduction

zsh in nix-shell

This oh-my-zsh plugin lets you use zsh as the default shell in a nix-shell environment. It's recommended to use this in conjunction with nix-zsh-completions.

Motivation

In theory all you need to do to use zsh in nix-shell is to set NIX_BUILD_SHELL to zsh. Unfortunatly nix assumes that the NIX_BUILD_SHELL is a bash variant and passes bash specific arguments to the shell. To fix this we need a shim that translates these arguments.

The information that nix-shell exposes to the environment is also pretty sparse. It would be nice to know what derivations are included in the current environment for example to display them in the shells prompt.

Installation

Oh-My-ZSH

git clone https://github.com/chisui/zsh-nix-shell.git $ZSH_CUSTOM/plugins/nix-shell

Then add nix-shell to the plugins list in ~/.zshrc.

Plain ZSH

Clone this repository and add the following to your ~/.zshrc.

source /path/to/zsh-nix-shell/nix-shell.plugin.zsh

Plugin managers

It should be possible to install this plugin through most zsh plugin managers. If the one of your choice is not supported feel free to open an issue or even better create a pull request.

MacOS

On MacOS you have to have a bash with version 4 or greater. See Issue 14

Usage

Use nix-shell as you did before.

Commands run with --run or --command argument are executed in nix-shells default shell. In the case of --command you are put into a zsh shell afterwords.

--pure

If you use the --pure flag the interactive shell will be the default shell.

Environment info

If you are inside a nix-shell environment IN_NIX_SHELL will be set. The value will be impure or pure if you specified --pure.

The packages argument is passed through as NIX_SHELL_PACKAGES to the shell.

If this Variable is empty nix-shell was called for a specific nix expression which is stored in the name environment variable.

These variables can now be used inside a theme to customize the prompt. Take a look at this variant of the agnoster theme for an example of how this might look.

example prompt

example prompt for projects

Limitations

Shell hooks

Shell hooks are supported in general. Since they are executed inside of bash before the zsh shell is spawned they aren't executed in the same environment. This means that things like aliases wont work.

Contributing

Please do. Pull requests welcome.

zsh-nix-shell's People

Contributors

chisui avatar lrworth avatar alyssais avatar ptival avatar ysndr avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.