@@ -3,42 +3,54 @@ |
| 3 | 3 | # ~/.config/fish/functions/fortress.fish |
| 4 | 4 | # or |
| 5 | 5 | # /usr/share/fish/vendor_functions.d/fortress.fish (system-wide) |
| 6 | +# |
| 7 | +# This provides the cd-on-exit feature. Without this function, |
| 8 | +# you can still run fortress but 'c' won't change your shell's directory. |
| 6 | 9 | |
| 7 | 10 | function fortress --description "Navigate filesystem with FORTRESS and cd on exit" |
| 8 | | - # Set fortress directory - prefer system install, fallback to FORTRESS_DIR env var |
| 9 | | - set -l fortress_dir |
| 10 | 11 | set -l fortress_exe |
| 11 | 12 | |
| 12 | | - # Check for fortress-bin in PATH first (works for all package managers including Homebrew) |
| 13 | | - if command -v fortress-bin &> /dev/null |
| 13 | + # Check standard install locations (lib path first, then legacy bin path) |
| 14 | + if test -x /usr/lib/fortress/fortress |
| 15 | + set fortress_exe /usr/lib/fortress/fortress |
| 16 | + else if test -x /usr/lib64/fortress/fortress |
| 17 | + set fortress_exe /usr/lib64/fortress/fortress |
| 18 | + else if command -v fortress-bin &> /dev/null |
| 19 | + # Legacy: fortress-bin in PATH (Homebrew, older packages) |
| 14 | 20 | set fortress_exe fortress-bin |
| 15 | | - else if test -x /usr/bin/fortress-bin |
| 16 | | - # Use system-installed binary (RPM/AUR) |
| 17 | | - set fortress_exe /usr/bin/fortress-bin |
| 21 | + else if set -q FORTRESS_BIN |
| 22 | + # Allow override via environment variable |
| 23 | + set fortress_exe $FORTRESS_BIN |
| 18 | 24 | else if set -q FORTRESS_DIR |
| 19 | | - set fortress_dir $FORTRESS_DIR |
| 20 | | - set fortress_exe $fortress_dir/build/gfortran_*/app/fortress |
| 25 | + # Development: FORTRESS_DIR points to repo root |
| 26 | + set fortress_exe $FORTRESS_DIR/build/gfortran_*/app/fortress |
| 21 | 27 | else |
| 22 | | - # Fallback to local development path |
| 23 | | - set fortress_dir $HOME/Documents/GithubOrgs/FortranGoingOnForty/fortress |
| 24 | | - set fortress_exe $fortress_dir/build/gfortran_*/app/fortress |
| 28 | + # Fallback: look for any fortress executable (NixOS, custom installs) |
| 29 | + set -l found (type -P fortress 2>/dev/null) |
| 30 | + if test -n "$found" -a -x "$found" |
| 31 | + set fortress_exe $found |
| 32 | + else |
| 33 | + echo "fortress: binary not found. Set FORTRESS_BIN or FORTRESS_DIR." >&2 |
| 34 | + return 1 |
| 35 | + end |
| 25 | 36 | end |
| 26 | 37 | |
| 27 | 38 | # Run fortress |
| 28 | | - if test -n "$fortress_exe" |
| 29 | | - eval $fortress_exe |
| 30 | | - else |
| 31 | | - $fortress_dir/build/gfortran_*/app/fortress |
| 32 | | - end |
| 39 | + eval $fortress_exe $argv |
| 40 | + set -l exit_code $status |
| 33 | 41 | |
| 34 | 42 | # Check if fortress wants us to cd somewhere |
| 35 | 43 | if test -f $HOME/.fortress_cd |
| 36 | 44 | set -l target_dir (cat $HOME/.fortress_cd) |
| 37 | 45 | rm -f $HOME/.fortress_cd |
| 38 | | - if cd $target_dir 2>/dev/null |
| 39 | | - echo "fortress: changed directory to "(pwd) |
| 40 | | - else |
| 41 | | - echo "fortress: failed to change directory to $target_dir" >&2 |
| 46 | + if test -n "$target_dir" -a -d "$target_dir" |
| 47 | + if cd $target_dir 2>/dev/null |
| 48 | + echo "fortress: changed directory to "(pwd) |
| 49 | + else |
| 50 | + echo "fortress: failed to change directory to $target_dir" >&2 |
| 51 | + end |
| 42 | 52 | end |
| 43 | 53 | end |
| 54 | + |
| 55 | + return $exit_code |
| 44 | 56 | end |