Skip to content

Commit

Permalink
prune and bin fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ponyspy committed Mar 20, 2017
1 parent cf8b323 commit 5415bb2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -26,7 +26,7 @@ Alternatively, you can clone this repo and

to install `n` to `bin/n` of the directory specified in the environment variable `$PREFIX`, which defaults to `/usr/local` (note that you will likely need to use `sudo`). To install `n` in a custom location (such as `$CUSTOM_LOCATION/bin/n`), run `PREFIX=$CUSTOM_LOCATION make install`.

Once installed, `n` installs `node` versions to subdirectory `n/versions` of the directory specified in environment variable `N_PREFIX`, which defaults to `/usr/local`; the _active_ `node`/`iojs` version is installed directly in `N_PREFIX`.
Once installed, `n` installs `node` versions to subdirectory `n/versions` of the directory specified in environment variable `N_PREFIX`, which defaults to `/usr/local`; the _active_ `node`/`iojs` version is installed directly in `N_PREFIX`.
To change the default to, say, `$HOME`, prefix later calls to `n` with `N_PREFIX=$HOME ` or add `export N_PREFIX=$HOME` to your shell initialization file.

Additionally, consider third-party installer [n-install](https://github.com/mklement0/n-install), which allows installation directly from GitHub; for instance,
Expand Down Expand Up @@ -123,6 +123,7 @@ Output can also be obtained from `n --help`.
n use <version> [args ...] Execute node <version> with [args ...]
n bin <version> Output bin path for <version>
n rm <version ...> Remove the given version(s)
n prune Remove all versions except the current version
n --latest Output the latest node version available
n --stable Output the latest stable node version available
n --lts Output the latest LTS node version available
Expand Down
35 changes: 35 additions & 0 deletions bin/n
Expand Up @@ -167,6 +167,7 @@ display_help() {
n use <version> [args ...] Execute node <version> with [args ...]
n bin <version> Output bin path for <version>
n rm <version ...> Remove the given version(s)
n prune Remove all versions except the current version
n --latest Output the latest node version available
n --stable Output the latest stable node version available
n --lts Output the latest LTS node version available
Expand Down Expand Up @@ -577,13 +578,42 @@ remove_versions() {
done
}

#
# Prune non-active versions
#

prune_versions() {
check_current_version
for version in $(versions_paths); do
if [ $version != $active ]
then
echo $version
rm -rf ${BASE_VERSIONS_DIR[$DEFAULT]}/$version
shift
fi
done
}

#
# Output bin path for <version>
#

display_bin_path_for_version() {
test -z $1 && abort "version required"
local version=${1#v}

if [ "$version" = "latest" ]; then
version=$(display_latest_version)
fi

if [ "$version" = "stable" ]; then
version=$(display_latest_stable_version)
fi

if [ "$version" = "lts" ]; then
version=$(display_latest_lts_version)
fi

local bin=${VERSIONS_DIR[$DEFAULT]}/$version/bin/node
if test -f $bin; then
printf "$bin \n"
Expand All @@ -608,6 +638,10 @@ execute_with_version() {
version=$(display_latest_stable_version)
fi

if [ "$version" = "lts" ]; then
version=$(display_latest_lts_version)
fi

local bin=${VERSIONS_DIR[$DEFAULT]}/$version/bin/node

shift # remove version
Expand Down Expand Up @@ -716,6 +750,7 @@ else
bin|which) display_bin_path_for_version $2; exit ;;
as|use) shift; execute_with_version $@; exit ;;
rm|-) shift; remove_versions $@; exit ;;
prune) prune_versions; exit ;;
latest) install_latest; exit ;;
stable) install_stable; exit ;;
lts) install_lts; exit ;;
Expand Down

0 comments on commit 5415bb2

Please sign in to comment.