File: source-bashrc

package info (click to toggle)
openfoam 1912.200626-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 238,956 kB
  • sloc: cpp: 1,159,641; sh: 15,902; ansic: 5,195; lex: 660; xml: 387; python: 282; awk: 212; makefile: 103; sed: 88; csh: 3
file content (97 lines) | stat: -rw-r--r-- 2,972 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#----------------------------------*-sh-*--------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | www.openfoam.com
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
#     Copyright (C) 2019-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# File
#     bin/tools/source-bashrc
#
# Description
#     Source user ~/.bashrc and OpenFOAM etc/bashrc.
#     Not normally sourced manually, but from bash with the --rcfile option.
#
#------------------------------------------------------------------------------
# Hard-coded directory path (eg, autoconfig)
projectDir="@PROJECT_DIR@"

if [ -z "$projectDir" ] || [ "${projectDir#@}" != "$projectDir" ]
then
    # Auto-detect location (as per OpenFOAM etc/bashrc)
    # --
    # Assuming this file is $WM_PROJECT_DIR/bin/tools/source-bashrc,
    # the next lines should work when sourced by BASH or ZSH shells.
    # --

    projectDir="${BASH_SOURCE:-${ZSH_NAME:+$0}}"
    if [ -n "$projectDir" ]
    then
        projectDir="$(\cd "$(dirname "$projectDir")"/../.. && \pwd -L)" || \
        unset projectDir
    fi
fi

#------------------------------------------------------------------------------

if [ -d "$projectDir" ]
then
    _foamSourceBashEnv="$projectDir/etc/bashrc"
else
    unset _foamSourceBashEnv
fi


# Source the user bashrc first.
# Simply hope that they don't unset/reset _foamSourceBashEnv !!

if [ -f "$HOME/.bashrc" ]
then
    . "$HOME/.bashrc"
fi


# Source the OpenFOAM etc/bashrc

if [ -f "$_foamSourceBashEnv" ]
then
    . "$_foamSourceBashEnv" $FOAM_SETTINGS

    # Avoid further inheritance
    unset FOAM_SETTINGS

    # Some feedback
    if [ -n "$PS1" ] && [ -d "$WM_PROJECT_DIR" ]
    then
        info="$("$WM_PROJECT_DIR"/bin/foamEtcFile -show-patch 2>/dev/null)"

        # echo "Using: OpenFOAM-$WM_PROJECT_VERSION ($FOAM_API${info:+ patch=$info}) - visit www.openfoam.com" 1>&2
        echo "Using: OpenFOAM-$WM_PROJECT_VERSION${info:+ (patch=$info)} - visit www.openfoam.com" 1>&2
        echo "Arch:  $WM_OPTIONS (mpi=$FOAM_MPI)" 1>&2

        ## echo "$WM_PROJECT_DIR" 1>&2
        ## echo 1>&2

        # Set prompt as reminder that this is a shell session

        # Chalmers likes this one:
        # PS1="OpenFOAM${FOAM_API:+-$FOAM_API}:"'$(foamPwd)\n\u\$ '

        PS1="OpenFOAM${FOAM_API:+-$FOAM_API}:"'\w/\n\u\$ '
    fi
else
    echo "Could not locate OpenFOAM etc/bashrc in '$projectDir'" 1>&2
fi

echo "OpenFOAM shell session - use exit to quit" 1>&2
echo 1>&2

# Cleanup variables (done as final statement for a clean exit code)
unset _foamSourceBashEnv projectDir

#------------------------------------------------------------------------------