Skip to content

How to handle shell and shell functions #277

@tommyalatalo

Description

@tommyalatalo

I'm trying to set up nvm and node using go-task, but the gosh the tasks are running in is giving me some trouble.

You can see the task I'm trying to run below, where the first command works fine, $SHELL is zsh in my case, and the scripts installs correctly. But nvm is installed as a shell function, not a binary, so the commands "which nvm" and "nvm install node" fail to find "nvm".

  setup:
    desc: setup common tools
    cmds:
      - "[ ! -d ~/.nvm ] && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | $SHELL || echo nvm installed, skipping..."
      - which nvm
      - nvm install node
    silent: no

nvm also adds some things to my .zshrc when the install script runs, and it requires to set some environment variables in order to immediately use nvm, or to restart your terminal to load those vars from .zshrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Is this possible to do with go-task or am I outside the scope of the application?
It would be really great to be able to set this task up so that I can install nvm and node (npm) so that I can install some common tools that we use in one task. Would putting these installation commands for nvm and node into a script be a better approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions