| 1 | # FORTRESS shell integration |
| 2 | # Add this to your .bashrc or .zshrc: |
| 3 | # source ~/Documents/GithubOrgs/FortranGoingOnForty/fortress/fortress.sh |
| 4 | # |
| 5 | # Then use: fortress |
| 6 | |
| 7 | fortress() { |
| 8 | # Determine which fortress binary to use |
| 9 | local fortress_exe |
| 10 | |
| 11 | # Check for fortress-bin in PATH first (works for all package managers including Homebrew) |
| 12 | if command -v fortress-bin &> /dev/null; then |
| 13 | fortress_exe="fortress-bin" |
| 14 | elif [ -x "/usr/bin/fortress-bin" ]; then |
| 15 | # Use system-installed binary (via package manager like RPM/AUR) |
| 16 | fortress_exe="/usr/bin/fortress-bin" |
| 17 | elif [ -n "$FORTRESS_DIR" ]; then |
| 18 | # Use FORTRESS_DIR if set |
| 19 | fortress_exe="$FORTRESS_DIR/build/gfortran_"*"/app/fortress" |
| 20 | else |
| 21 | # Fallback to local development path |
| 22 | fortress_exe="$HOME/Documents/GithubOrgs/FortranGoingOnForty/fortress/build/gfortran_"*"/app/fortress" |
| 23 | fi |
| 24 | |
| 25 | # Run fortress |
| 26 | $fortress_exe |
| 27 | |
| 28 | # Check if fortress wants us to cd somewhere |
| 29 | if [ -f "$HOME/.fortress_cd" ]; then |
| 30 | local target_dir |
| 31 | target_dir=$(cat "$HOME/.fortress_cd") |
| 32 | rm -f "$HOME/.fortress_cd" |
| 33 | cd "$target_dir" || return 1 |
| 34 | echo "fortress: changed directory to $(pwd)" |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | # For zsh compatibility |
| 39 | if [ -n "$ZSH_VERSION" ]; then |
| 40 | # Nothing special needed for zsh |
| 41 | : |
| 42 | fi |
| 43 | |
| 44 | # Export for subshells if needed (bash only) |
| 45 | if [ -n "$BASH_VERSION" ]; then |
| 46 | export -f fortress 2>/dev/null || true |
| 47 | fi |