├── CODE_OF_CONDUCT.md ├── README.md └── nvm.fish /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. 12 | 13 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 14 | 15 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.1.0, available at [http://contributor-covenant.org/version/1/1/0/](http://contributor-covenant.org/version/1/1/0/) 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NVM fish wrapper 2 | 3 | [![GitHub tag](https://img.shields.io/github/tag/passcod/nvm-fish-wrapper.svg?style=flat-square)](https://github.com/passcod/nvm-fish-wrapper)[![License](https://img.shields.io/badge/license-CC0--1.0-blue.svg?style=flat-square)](https://creativecommons.org/publicdomain/zero/1.0/)[![Code of Conduct](https://img.shields.io/badge/contributor-covenant-123456.svg?style=flat-square)](http://contributor-covenant.org/version/1/1/0/) 4 | 5 | A heads-up that [someone](https://github.com/edc) has gone and created a 6 | generic fish wrapper for bash utilities, which probably works much better 7 | than this. It's called [bass](https://github.com/edc/bass) and it's everything 8 | I wanted to do with this project, but done right. I think that's the end of 9 | nvm-fish-wrapper. It's been a good ride! [Thank you all](https://github.com/passcod/nvm-fish-wrapper/commit/69198) 10 | and go have wonderful further adventures with fish, Node.js, and nvm! 11 | 12 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 13 | 14 | _NVM wrapper for the fish shell._ 15 | 16 | > All nvm really does to the shell is modify `$PATH`, `$MANPATH`, and a bunch of `$NVM_*` vars. No binstubs afaics. 17 | — https://twitter.com/passcod/status/563948458382331905 18 | 19 | > So creating a fish wrapper for it is really simple and will work forever. Why did people do anything else. Github incoming. 20 | — https://twitter.com/passcod/status/563948749395742721 21 | 22 | ## Installing 23 | 24 | You need bash, fish, git, grep, cut, env, mktemp, and test. Unless you have a 25 | weird environment, the last five should be there already. If you don't have 26 | fish then I'm not sure what you're doing here. Git is required for installing 27 | and updating, but you could conceivably copy things in place, whatever. Bash 28 | is required for running, but you'll never need to touch it. 29 | 30 | Start by installing [nvm](https://github.com/creationix/nvm) the manual way: 31 | 32 | ```bash 33 | ~> git clone https://github.com/creationix/nvm.git ~/.nvm 34 | ~> cd ~/.nvm 35 | ~/.nvm> git checkout (git describe --abbrev=0 --tags) 36 | ``` 37 | 38 | If you're on OS X, you can also install nvm using [Homebrew](http://brew.sh): 39 | 40 | ```bash 41 | ~> brew install nvm 42 | ~> mkdir ~/.nvm 43 | ~> ln -s (brew --prefix nvm)/nvm.sh ~/.nvm/nvm.sh 44 | ``` 45 | 46 | You'll need to add `set -x NVM_DIR ~/.nvm` before sourcing nvm.fish (below) for the 47 | wrapper to work with the brew-installed nvm [[1]]. 48 | 49 | __Note__: I can't test on OS X, so there are [several open bugs][OSX] at the moment 50 | I cannot address by myself. These bugs seem to only be Homebrew-related, so if you 51 | don't use Homebrew or don't have Homebrew coreutils or didn't install nvm using 52 | Homebrew or some combination of the three, chances are pretty good that it works! 53 | 54 | [1]: https://github.com/passcod/nvm-fish-wrapper/issues/8#issuecomment-94372226 55 | [OSX]: https://github.com/passcod/nvm-fish-wrapper/labels/OS%20X 56 | 57 | You don't need to source anything or add stuff to `.bashrc`. 58 | 59 | Then install the wrapper: 60 | 61 | ```bash 62 | ~> cd ~/.config/fish 63 | ~/.c/fish> git clone git://github.com/passcod/nvm-fish-wrapper.git nvm-wrapper 64 | ``` 65 | 66 | Finally edit your `config.fish` and add this line: 67 | 68 | ```bash 69 | source ~/.config/fish/nvm-wrapper/nvm.fish 70 | ``` 71 | 72 | And reload your shells. 73 | 74 | ## Using 75 | 76 | Just use `nvm` as you would in other shells, e.g. 77 | 78 | ```bash 79 | ~> nvm install iojs 80 | ################################################### 100.0% 81 | WARNING: checksums are currently disabled for io.js 82 | Now using io.js v2.3.1 83 | 84 | ~> node -v 85 | v2.3.1 86 | 87 | ~> nvm use stable 88 | Now using node v0.12.5 89 | 90 | ~> node -v 91 | v0.12.5 92 | ``` 93 | 94 | ## Etc 95 | 96 | Made by Félix Saparelli, released in the Public Domain (or CC0-1.0 if Public 97 | Domain dedications are disallowed or limited in your jurisdiction). 98 | 99 | Also made possible by the [contributors] and the [many more][stargazers] [people] using it. 100 | 101 | [contributors]: https://github.com/passcod/nvm-fish-wrapper/graphs/contributors 102 | [stargazers]: https://github.com/passcod/nvm-fish-wrapper/stargazers 103 | [people]: https://twitter.com/wraithgar/status/588382384925450240 104 | -------------------------------------------------------------------------------- /nvm.fish: -------------------------------------------------------------------------------- 1 | #? NVM wrapper. Félix Saparelli. Public Domain 2 | #> https://github.com/passcod/nvm-fish-wrapper 3 | #v 1.2.2 4 | 5 | function nvm_set 6 | if test (count $argv) -gt 1 7 | #echo set: k: $argv[1] v: $argv[2..-1] 8 | set -gx $argv[1] $argv[2..-1] 9 | else 10 | #echo unset: k: $argv[1] 11 | set -egx $argv[1] 12 | end 13 | end 14 | 15 | function nvm_split_env 16 | set k (echo $argv | cut -d\= -f1) 17 | set v (echo $argv | cut -d\= -f2-) 18 | echo $k 19 | echo $v 20 | end 21 | 22 | function nvm_find_paths 23 | echo $argv | grep -oE '[^:]+' | grep -w '.nvm' 24 | end 25 | 26 | function nvm_set_path 27 | set k $argv[1] 28 | set r $argv[2..-1] 29 | 30 | set newpath 31 | for o in $$k 32 | if echo $o | grep -qvw '.nvm' 33 | set newpath $newpath $o 34 | end 35 | end 36 | 37 | set p (nvm_find_paths $r | head -n1) 38 | set newpath $p $newpath 39 | nvm_set $k $newpath 40 | end 41 | 42 | function nvm_mod_env 43 | set tmpnew $tmpdir/newenv 44 | 45 | bash -c "source ~/.nvm/nvm.sh && source $tmpold && nvm $argv && export status=\$? && env > $tmpnew && exit \$status" 46 | 47 | set nvmstat $status 48 | if test $nvmstat -gt 0 49 | return $nvmstat 50 | end 51 | 52 | for e in (cat $tmpnew) 53 | set p (nvm_split_env $e) 54 | 55 | if test (echo $p[1] | cut -d_ -f1) = NVM 56 | if test (count $p) -lt 2 57 | nvm_set $p[1] '' 58 | continue 59 | end 60 | 61 | nvm_set $p[1] $p[2..-1] 62 | continue 63 | end 64 | 65 | if test $p[1] = PATH 66 | nvm_set_path PATH $p[2..-1] 67 | else if test $p[1] = MANPATH 68 | set -l t (echo $p[2..-1] | cut -sd\: -f2-) 69 | if test '' = "$t" 70 | # We're assuming that if there's only one path 71 | # in the MANPATH, we should append the default 72 | # value. That may be wrong in some edge-cases. 73 | set -l m $p[2..-1]:(manpath -g) 74 | nvm_set MANPATH $m 75 | else 76 | nvm_set MANPATH $p[2..-1] 77 | end 78 | end 79 | end 80 | 81 | return $nvmstat 82 | end 83 | 84 | function nvm 85 | set -g tmpdir (mktemp -d 2>/dev/null; or mktemp -d -t 'nvm-wrapper') # Linux || OS X 86 | set -g tmpold $tmpdir/oldenv 87 | env | grep -E '^((NVM|NODE)_|(MAN)?PATH=)' > $tmpold 88 | 89 | set -l arg1 $argv[1] 90 | if echo $arg1 | grep -qE '^(use|install|deactivate)$' 91 | nvm_mod_env $argv 92 | set s $status 93 | else if test $arg1 = 'unload' 94 | functions -e (functions | grep -E '^nvm(_|$)') 95 | else 96 | bash -c "source ~/.nvm/nvm.sh && source $tmpold && nvm $argv" 97 | set s $status 98 | end 99 | 100 | command rm -r $tmpdir 101 | return $s 102 | end 103 | --------------------------------------------------------------------------------