Commit d8ea41e7 authored by Haakan Nilsson's avatar Haakan Nilsson Committed by Mark Olesen
Browse files

STYLE: foamPwd (posix) function with some env replacements (issue #844)

- the current working path with replacements for base-level
  OpenFOAM env variables such as FOAM_RUN, WM_PROJECT_DIR,
  WM_PROJECT_USER_DIR etc

  Can be used directly from the command-line or embedded into a
  command prompt. For example,

      PS1='$(foamPwd)\n\u\$ '

- aliases for user solver/utilities located under "$WM_PROJECT_USER_DIR":
  (ufoam, uapp, usol, uutil)
parent 26bb05d6
......@@ -49,6 +49,11 @@ alias util 'cd $FOAM_UTILITIES'
alias tut 'cd $FOAM_TUTORIALS'
alias run 'cd $FOAM_RUN'
alias ufoam 'cd $WM_PROJECT_USER_DIR'
alias uapp 'cd $WM_PROJECT_USER_DIR/applications'
alias usol 'cd $WM_PROJECT_USER_DIR/applications/solvers'
alias uutil 'cd $WM_PROJECT_USER_DIR/applications/utilities'
# Refresh the environment
# ~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -175,6 +175,11 @@ unalias util
unalias tut
unalias run
unalias ufoam
unalias uapp
unalias usol
unalias uutil
unalias wmRefresh
unalias foamVersion
unalias foamPV
......
......@@ -47,6 +47,11 @@ alias util='cd $FOAM_UTILITIES'
alias tut='cd $FOAM_TUTORIALS'
alias run='cd $FOAM_RUN'
alias ufoam='cd $WM_PROJECT_USER_DIR'
alias uapp='cd $WM_PROJECT_USER_DIR/applications'
alias usol='cd $WM_PROJECT_USER_DIR/applications/solvers'
alias uutil='cd $WM_PROJECT_USER_DIR/applications/utilities'
# Refresh the environment
# ~~~~~~~~~~~~~~~~~~~~~~~
......@@ -106,4 +111,22 @@ foamPV()
}
# OpenFOAM working directory with basic env replacements
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
unset -f foamPwd 2>/dev/null
foamPwd()
{
if [ -d "$WM_PROJECT_DIR" ]
then
echo $PWD | sed \
-e "s#^${FOAM_RUN}#\$FOAM_RUN#;" \
-e "s#^${WM_PROJECT_DIR}#\$WM_PROJECT_DIR#;" \
-e "s#^${WM_PROJECT_USER_DIR}#\$WM_PROJECT_USER_DIR#;" \
-e "s#^${HOME}#\$HOME#";
else
echo $PWD | sed -e "s#^${HOME}#\$HOME#;"
fi
}
#------------------------------------------------------------------------------
......@@ -170,10 +170,19 @@ unalias util 2>/dev/null
unalias tut 2>/dev/null
unalias run 2>/dev/null
unalias ufoam 2>/dev/null
unalias uapp 2>/dev/null
unalias usol 2>/dev/null
unalias uutil 2>/dev/null
unset -f wmRefresh 2>/dev/null
unset -f foamPwd 2>/dev/null
unset -f foamVersion 2>/dev/null
unset -f foamPV 2>/dev/null
# NB: no good way to remove foamPwd reference in PS1.
# Remove old completions, which look like
# "complete ... -F _of_complete_ APPNAME
# For economy, obtain list first
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment