mirror of
https://github.com/lilyball/nix-env.fish.git
synced 2024-10-03 23:17:07 +03:00
Initial commit
This commit is contained in:
commit
d048a70c38
24
LICENSE
Normal file
24
LICENSE
Normal file
@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
15
README.md
Normal file
15
README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# nix-env.fish
|
||||
|
||||
Sets up the Nix environment for a non-Nix-installed [Fish shell](http://fishshell.com).
|
||||
|
||||
Beyond just setting up `$PATH` and the various `$NIX_*` environment variables, this also sets up `$fish_function_path` and `$fish_complete_path` to include any Nix-installed Fish functions/completions, and sources any Nix-installed Fish `conf.d`
|
||||
|
||||
## Install
|
||||
|
||||
Any Fish package manager should be able to install this.
|
||||
|
||||
### [Fisher](https://github.com/jorgebucaran/fisher)
|
||||
|
||||
```fish
|
||||
fisher add lilyball/nix-env.fish
|
||||
```
|
56
conf.d/nix-env.fish
Normal file
56
conf.d/nix-env.fish
Normal file
@ -0,0 +1,56 @@
|
||||
# Setup Nix
|
||||
set -l nix_profile_path ~/.nix-profile/etc/profile.d/nix.sh
|
||||
if test -e $nix_profile_path
|
||||
# Source the nix setup script
|
||||
# We're going to run the regular Nix profile under bash and then print out a few variables
|
||||
for line in (env -u BASH_ENV bash -c '. "$0"; for name in PATH "${!NIX_@}"; do printf "%s=%s\0" "$name" "${!name}"; done' $nix_profile_path | string split0)
|
||||
set -xg (string split -m 1 = $line)
|
||||
end
|
||||
|
||||
# Insert Nix's fish share directories into fish's special variables
|
||||
set -l nix_share ~/.nix-profile/share/fish
|
||||
set -l nix_vendor_functions $nix_share/vendor_functions.d
|
||||
if set -l idx (contains --index -- $__fish_data_dir/functions $fish_function_path)
|
||||
# Fish has no way to simply insert into the middle of an array
|
||||
set -l new_path $fish_function_path[1..$idx]
|
||||
set new_path[$idx] $nix_vendor_functions
|
||||
set fish_function_path $new_path $fish_function_path[$idx..-1]
|
||||
else
|
||||
set -a fish_function_path $nix_vendor_functions
|
||||
end
|
||||
|
||||
set -l nix_vendor_comp $nix_share/vendor_completions.d
|
||||
if set -l idx (contains --index -- $__fish_data_dir/completions $fish_complete_path)
|
||||
set -l new_path $fish_complete_path[1..$idx]
|
||||
set new_path[$idx] $nix_vendor_comp
|
||||
set fish_complete_path $new_path $fish_complete_path[$idx..-1]
|
||||
else
|
||||
set -a fish_complete_path $nix_vendor_comp
|
||||
end
|
||||
|
||||
set -l nix_conf $nix_share/vendor_conf.d
|
||||
# In order to simulate being the extra conf, we need to make sure it hasn't been "overridden" yet
|
||||
# we're not going to actually check for our actual extra confdir. And we're technically sourcing
|
||||
# these files out of order, and can't stop anything in the real extra confdir from sourcing.
|
||||
# This is cribbed from $__fish_data_dir/config.fish
|
||||
set -l sourcelist
|
||||
set -l configdir ~/.config
|
||||
if set -q XDG_CONFIG_HOME
|
||||
set configdir $XDG_CONFIG_HOME
|
||||
end
|
||||
for file in $configdir/fish/conf.d/*.fish $__fish_sysconf_dir/conf.d/*.fish
|
||||
set -l basename (string replace -r '^.*/' '' -- $file)
|
||||
contains -- $basename $sourcelist
|
||||
and continue
|
||||
set -a sourcelist $basename
|
||||
# Don't source, these files have already been sourced by Fish's global setup
|
||||
end
|
||||
for file in $nix_conf/*.fish
|
||||
set -l basename (string replace -r '^.*/' '' -- $file)
|
||||
contains -- $basename $sourcelist
|
||||
and continue
|
||||
# Source the file
|
||||
[ -f $file -a -r $file ]
|
||||
and source $file
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user