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