0

I have a shell script with various functions defined and all accessible via the terminal by including the following line in bash_profile: source ~/hcom-env/conf/sys/hcom-profile

However when I try to use one of these functions within a sublime build system I get the error [Errno 2] No such file or directory

I've tried using the advice in this article http://robdodson.me/blog/2012/05/14/hacking-the-path-variable-in-sublime-text/ (including installing shell turtlestein and adding /Users/me/hcom-env/conf/sys/hcom-profile/ to the PATH I use in my path.py file) but still doesn't work.

1
  • If hack the path doesn't work, then there is probably an overriding existing build system that you can modify to add your path. I'll post the Turtlestein modification in an answer so I can indent 4 spaces. Commented Jun 14, 2013 at 7:02

3 Answers 3

1

Shell variables and functions, including those defined in .bash_profile and other places, are not available to ST2 because it doesn't run inside bash. It's its own independent program - analogous to how Firefox (for example) can't read your $PATH variable.

To have your custom functions, variables, etc. available to your build system, you'll have to create a separate build script to run as your build system:

{
    "cmd": ["ST2_build.sh", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

then within ST2_build.sh have the following at the top:

#!/bin/bash

if [ -f ~/hcom-env/conf/sys/hcom-profile]; then
    source ~/hcom-env/conf/sys/hcom-profile
fi

# now I can use my cool functions...
myfunc($1)
Sign up to request clarification or add additional context in comments.

2 Comments

Does this mean I would have to have a separate .sh file for each build?
Well, it depends on how different your builds are. If you can set up a generic build system using command-line options, then you'd only need one .sh file, but if your build logic is very different from system to system then you'll probably need customized files for each.
1

Modification of path for shell turtelstein -- Shell Turtlestein.sublime-settings

{
    // Override these in your own
    // `Packages/User/Shell Turtlestein.sublime-settings` file.
    "surround_cmd": ["", ""],
    "exec_args": {"path": "/usr/texbin:/usr/local/bin:$PATH"},
    "cmd_settings": [],
    "input_widget": {
        // overridden for silly non-unixy OSes
        "syntax": "Packages/ShellScript/Shell-Unix-Generic.tmLanguage"
    }
}

Comments

0

I have used this one and it worked fine.

{
    "cmd"       : ["bash", "$file"],
    "selector"  : "source.shell"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.