diff --git a/bulker/_version.py b/bulker/_version.py index a5f830a..bc8c296 100644 --- a/bulker/_version.py +++ b/bulker/_version.py @@ -1 +1 @@ -__version__ = "0.7.1" +__version__ = "0.7.2" diff --git a/bulker/bulker.py b/bulker/bulker.py index ef0b532..9e548f2 100644 --- a/bulker/bulker.py +++ b/bulker/bulker.py @@ -443,7 +443,7 @@ def bulker_load(manifest, cratevars, bcfg, exe_jinja2_template, manifest_name, cratevars['tag']) if not os.path.isabs(crate_path): - crate_path = os.path.join(os.path.dirname(bcfg._file_path), crate_path) + crate_path = os.path.join(os.path.dirname(bcfg["__internal"].file_path), crate_path) _LOGGER.debug("Crate path: {}".format(crate_path)) _LOGGER.debug("cratevars: {}".format(cratevars)) @@ -483,7 +483,7 @@ def bulker_load(manifest, cratevars, bcfg, exe_jinja2_template, imp_cratevars['crate'], imp_cratevars['tag']) if not os.path.isabs(imp_crate_path): - imp_crate_path = os.path.join(os.path.dirname(bcfg._file_path), imp_crate_path) + imp_crate_path = os.path.join(os.path.dirname(bcfg["__internal"].file_path), imp_crate_path) if not os.path.exists(imp_crate_path): _LOGGER.error("Nonexistent crate: '{}' from '{}'. Reloading...".format(imp, imp_crate_path)) reload_import = True @@ -533,7 +533,7 @@ def host_tool_specific_args(bcfg, pkg, hosttool_arg_key): if os.path.isabs(pkg["singularity_image_folder"]): sif = pkg["singularity_image_folder"] else: - sif = os.path.join(os.path.dirname(bcfg._file_path), + sif = os.path.join(os.path.dirname(bcfg["__internal"].file_path), pkg["singularity_image_folder"]) pkg["singularity_fullpath"] = os.path.join( @@ -756,10 +756,10 @@ def bulker_activate(bulker_config, cratelist, echo=False, strict=False, prompt=T if os.path.basename(shellpath) == "bash": if strict: rcfile = mkabs(bulker_config.bulker.rcfile_strict, - os.path.dirname(bulker_config._file_path)) + os.path.dirname(bulker_config["__internal"].file_path)) else: rcfile = mkabs(bulker_config.bulker.rcfile, - os.path.dirname(bulker_config._file_path)) + os.path.dirname(bulker_config["__internal"].file_path)) shell_list.append("--rcfile") shell_list.append(rcfile) @@ -770,11 +770,11 @@ def bulker_activate(bulker_config, cratelist, echo=False, strict=False, prompt=T if strict: rcfolder = mkabs(os.path.join( os.path.dirname(bulker_config.bulker.rcfile_strict), - "zsh_start_strict"), os.path.dirname(bulker_config._file_path)) + "zsh_start_strict"), os.path.dirname(bulker_config["__internal"].file_path)) else: rcfolder = mkabs(os.path.join( os.path.dirname(bulker_config.bulker.rcfile_strict), - "zsh_start"), os.path.dirname(bulker_config._file_path)) + "zsh_start"), os.path.dirname(bulker_config["__internal"].file_path)) new_env["ZDOTDIR"] = rcfolder _LOGGER.debug("ZDOTDIR: {}".format(new_env["ZDOTDIR"])) @@ -844,6 +844,7 @@ def maybe_quote(item): global PROC PROC = psutil.Popen(merged_command, shell=True, preexec_fn=os.setsid) PROC.communicate() + sys.exit(PROC.returncode) #command[0:0] = ["export", "PATH=\"{}\"".format(newpath)] #subprocess.call(merged_command) @@ -1047,12 +1048,12 @@ def prep_load(bulker_config, crate_registry_paths, manifest=None, build=False): shell_template_jinja = None exe_template = mkabs(bulker_config.bulker.executable_template, - os.path.dirname(bulker_config._file_path)) + os.path.dirname(bulker_config["__internal"].file_path)) build_template = mkabs(bulker_config.bulker.build_template, - os.path.dirname(bulker_config._file_path)) + os.path.dirname(bulker_config["__internal"].file_path)) try: shell_template = mkabs(bulker_config.bulker.shell_template, - os.path.dirname(bulker_config._file_path)) + os.path.dirname(bulker_config["__internal"].file_path)) except AttributeError: _LOGGER.error("You need to re-initialize your bulker config or add a 'shell_template' attribute.") sys.exit(1) @@ -1289,7 +1290,7 @@ def main(): manifest_name, cratevars['tag']) if not os.path.isabs(crate_path): - crate_path = os.path.join(os.path.dirname(bcfg._file_path), crate_path) + crate_path = os.path.join(os.path.dirname(bulker_config["__internal"].file_path), crate_path) print("Crate path: {}".format(crate_path)) @@ -1359,13 +1360,18 @@ def main(): manifest, cratevars, exe_template_jinja, shell_template_jinja, build_template_jinja = prep_load( bulker_config, args.crate_registry_paths, args.manifest, args.build) - bulker_load(manifest, cratevars, bulker_config, + try: + bulker_load(manifest, cratevars, bulker_config, exe_jinja2_template=exe_template_jinja, shell_jinja2_template=shell_template_jinja, crate_path=args.path, build=build_template_jinja, force=args.force, recurse=args.recurse) + except Exception as e: + print(f'Bulker load failed: {e}') + sys.exit(1) + if args.command == "reload": bulker_config.make_writable() diff --git a/bulker/templates/start.sh b/bulker/templates/start.sh index 986f2fa..de36c6f 100755 --- a/bulker/templates/start.sh +++ b/bulker/templates/start.sh @@ -1,4 +1,3 @@ source "${BULKERSHELLRC}" -echo $BULKERPROMPT if [ -z ${BULKERPROMPT+x} ]; then echo "No prompt change"; else PS1="${BULKERPROMPT}"; fi export PATH="${BULKERPATH}:${PATH}" diff --git a/docs/changelog.md b/docs/changelog.md index 12024d2..cf942d2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,7 +1,12 @@ # Changelog +## [0.7.2] -- 2021-06-24 +- Update to yacman 0.8.0, fixing references to internal config attributes. +- Add documentation and clarity for the `shell_prompt` option +- Fixed bug with relative crate root folders. + ## [0.7.1] -- 2021-03-03 --- Fixed bug in bulker reload. +- Fixed bug in bulker reload. ## [0.7.0] -- 2021-03-02 - EXPERIMENTAL: Added `bulker cwl2man` to create a bulker manifest from a CWL file. diff --git a/docs/custom_prompts.md b/docs/custom_prompts.md new file mode 100644 index 0000000..e59918c --- /dev/null +++ b/docs/custom_prompts.md @@ -0,0 +1,71 @@ +# Customizing bulker prompts + +By default, when you activate a crate, bulker will change your prompt. You can customize it by specifying the `shell_prompt` attribute in your bulker config. *Make sure you enclose the value in single quotes*; if you use double-quotes the parser will re-escape your prompt escape sequences and break stuff. Here are some examples: + +In these examples we'll activate the crate like this: + +```console +bulker activate databio/lab +``` + +The variables that could be displayed are these: + +- namespace: `databio` +- crate name: `lab` +- username: `nsheff` +- host: `zither` +- working directory: `code` + +# Default prompt + +The default bulker prompt shows you the name of the crate you've activated, colored in yellow. Bulker uses `\b` to indicate the name of the bulker namespace and crate. The default prompt is the equivalent of putting this in your config: + +```yaml + shell_prompt: '\[\033[01;93m\]\b|\[\033[00m\]\[\033[01;34m\]\w\[\033[00m\]\$ ' +``` + +![](img/prompts/default.png) + + +## Include username and hostname + +In addition the bulker-provided `\b`, there are lots of other shell-provided variables you can use, like `\u` for username and `\h` for hostname, and `\W` for working directory path. You can look up lists of these by searching for *customizing bash PS1 prompt*. Here's a simple sample using *username* and *hostname*: + +```yaml + shell_prompt: '[\u@\h(\b) \W] $ ' +``` + +![](img/prompts/prompt1.png) + +## Change colors + +You can al;so use any terminal colors compatible with your terminal. + + +```yaml + shell_prompt: '\u@\h|\e[94m\b\[\e[00m\]:\e[90m\W\e[39m $ ' +``` + +![](img/prompts/prompt2.png) + + +## Emoji + +Yes, you can even put emoji in your prompt, if that's your thing: + +```yaml + shell_prompt: '⚓ \e[94m\b\[\e[00m\]:\e[90m\W\e[39m $ ' +``` + +![](img/prompts/prompt3.png) + + +## Date/time + +This example uses a custom date/time format along with 256-color codes: + +```yaml + shell_prompt: '\D{%y/%m/%d %H:%M}⚓ \e[38;5;141m\b\[\e[00m\]:\e[38;5;29m\W\e[39m $ ' +``` + +![](img/prompts/prompt4.png) diff --git a/docs/img/prompts/default.png b/docs/img/prompts/default.png new file mode 100644 index 0000000..85287b8 Binary files /dev/null and b/docs/img/prompts/default.png differ diff --git a/docs/img/prompts/prompt1.png b/docs/img/prompts/prompt1.png new file mode 100644 index 0000000..bb26a6b Binary files /dev/null and b/docs/img/prompts/prompt1.png differ diff --git a/docs/img/prompts/prompt2.png b/docs/img/prompts/prompt2.png new file mode 100644 index 0000000..7e6c4f2 Binary files /dev/null and b/docs/img/prompts/prompt2.png differ diff --git a/docs/img/prompts/prompt3.png b/docs/img/prompts/prompt3.png new file mode 100644 index 0000000..f81b11e Binary files /dev/null and b/docs/img/prompts/prompt3.png differ diff --git a/docs/img/prompts/prompt4.png b/docs/img/prompts/prompt4.png new file mode 100644 index 0000000..693d416 Binary files /dev/null and b/docs/img/prompts/prompt4.png differ diff --git a/mkdocs.yml b/mkdocs.yml index 0a68d03..b599b8b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -22,6 +22,7 @@ nav: - Start an exploratory shell: shell.md - Use bulker in a multi-user environment: multi_user_environment.md - Host- and tool-specific settings: settings.md + - Custom prompts: custom_prompts.md - Use a bulker registry: registry.md - Use images with entrypoints: entrypoint.md - Disable user or network map: advanced_templates.md diff --git a/requirements/requirements-all.txt b/requirements/requirements-all.txt index bcc8626..645664a 100644 --- a/requirements/requirements-all.txt +++ b/requirements/requirements-all.txt @@ -1,4 +1,4 @@ -yacman>=0.6.6 +yacman>=0.8.1 pyyaml>=5.1 logmuse>=0.2.0 jinja2