Class: Mnenv::Shells::BashShell

Inherits:
BaseShell show all
Defined in:
lib/mnenv/shells/bash.rb

Overview

Bash shell implementation (also works for sh, dash, zsh)

Instance Method Summary collapse

Methods inherited from BaseShell

#windows?

Instance Method Details

#config_fileObject



67
68
69
# File 'lib/mnenv/shells/bash.rb', line 67

def config_file
  File.expand_path('~/.bashrc')
end

#nameObject



9
10
11
# File 'lib/mnenv/shells/bash.rb', line 9

def name
  'bash'
end

#shim_content(executable_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mnenv/shells/bash.rb', line 17

def shim_content(executable_name)
  <<~SHIM
    #!/bin/bash
    set -e

    export MNENV_ROOT="${MNENV_ROOT:-$HOME/.mnenv}"

    # Resolve version and source using mnenv resolver
    VERSION="$("$MNENV_ROOT/lib/mnenv/resolver" "version")"
    SOURCE="$("$MNENV_ROOT/lib/mnenv/resolver" "source")"

    if [ -z "$VERSION" ]; then
      echo "mnenv: version not set or invalid" >&2
      echo "Set a version with: mnenv global <version> or mnenv local <version>" >&2
      exit 1
    fi

    if [ -z "$SOURCE" ]; then
      echo "mnenv: source not set or invalid" >&2
      exit 1
    fi

    # Determine executable path based on source
    # Installed versions are in $MNENV_ROOT/installed/<version>-<source>/
    if [ "$SOURCE" = "binary" ]; then
      # Binary: single self-contained binary
      EXECUTABLE="$MNENV_ROOT/installed/$VERSION-$SOURCE/metanorma"
    else
      # Gemfile: binstub from bundle install
      EXECUTABLE="$MNENV_ROOT/installed/$VERSION-$SOURCE/bin/#{executable_name}"
    fi

    if [ ! -f "$EXECUTABLE" ]; then
      echo "mnenv: #{executable_name} not installed for version $VERSION (source: $SOURCE)" >&2
      echo "Install it with: mnenv install $VERSION --source $SOURCE" >&2
      exit 1
    fi

    exec "$EXECUTABLE" "$@"
  SHIM
end

#shim_extensionObject



13
14
15
# File 'lib/mnenv/shells/bash.rb', line 13

def shim_extension
  '' # No extension for bash scripts
end

#use_output(version, source) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/mnenv/shells/bash.rb', line 59

def use_output(version, source)
  lines = []
  lines << "export METANORMA_VERSION=#{version}"
  lines << "export METANORMA_SOURCE=#{source}" if source
  lines << "# Run this in your shell, or use: eval \"$(mnenv use #{version}#{" --source #{source}" if source})\""
  lines.join("\n")
end