diff --git a/project-template/{{ project_repo_name }}/.gitattributes b/project-template/{{ project_repo_name }}/.gitattributes index 2537ef8..5fc52ef 100644 --- a/project-template/{{ project_repo_name }}/.gitattributes +++ b/project-template/{{ project_repo_name }}/.gitattributes @@ -1 +1,2 @@ -*.xsh text linguist-language=Python +*.xsh* text linguist-language=Python +*.py* text linguist-language=Python diff --git a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} similarity index 60% rename from project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} rename to project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} index 26480a9..133c71b 100644 --- a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} +++ b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} @@ -20,10 +20,14 @@ print('This is {{ project_repo_name }}!') # Note! If you want to create new env variables please name it with the beginning of the xontrib name # i.e. if the xontrib called xontrib-hello-world name the variables as XONTRIB_HELLO_WORLD_NEW_VARIABLE {% if pure_py %} -# Some code in Using Python API: -var = XSH.env.get("VAR", "default") -result = XSH.subproc_captured_stdout(['echo', '1']) +# If your xontrib was made only for interactive mode it's good practice to check this before executing. +if XSH.env.get("XONSH_INTERACTIVE"): + # Some code in Using Python API: + var = XSH.env.get("VAR", "default") + result = XSH.subproc_captured_stdout(['echo', '1']) {% else %} -var = ${...}.get('VAR', 'default') -result = $(echo 1) +# If your xontrib was made only for interactive mode it's good practice to check this before executing. +if $XONSH_INTERACTIVE: + var = XSH.env.get('VAR', 'default') + result = $(echo 1) {% endif %} diff --git a/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py b/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py index a3b2ccb..c043567 100644 --- a/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py +++ b/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py @@ -2,16 +2,17 @@ def _load_xontrib_(xsh: XonshSession, **_): - # getting environment variable - var = xsh.env.get("VAR", "default") - print("Autoloading xontrib: {{ project_repo_name }}") + # If your xontrib was made only for interactive mode it's good practice to check this before executing. + if XSH.env.get("XONSH_INTERACTIVE"): + var = xsh.env.get("VAR", "default") + print("Autoloading xontrib: {{ project_repo_name }}") - {% if has_events %} - from .event_hooks import listen_cd - xsh.builtins.events.on_chdir(listen_cd) - {% endif %} - {% if has_aliases %} - from .aliases import git_log - xsh.aliases["gl"] = git_log - {% endif %} + {% if has_events %} + from .event_hooks import listen_cd + xsh.builtins.events.on_chdir(listen_cd) + {% endif %} + {% if has_aliases %} + from .aliases import git_log + xsh.aliases["gl"] = git_log + {% endif %}