Fish · 2057 bytes Raw Blame History
1 # FORTRESS shell integration for Fish
2 # This file should be placed in:
3 # ~/.config/fish/functions/fortress.fish
4 # or
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.
9
10 function fortress --description "Navigate filesystem with FORTRESS and cd on exit"
11 set -l fortress_exe
12
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)
20 set fortress_exe fortress-bin
21 else if set -q FORTRESS_BIN
22 # Allow override via environment variable
23 set fortress_exe $FORTRESS_BIN
24 else if set -q FORTRESS_DIR
25 # Development: FORTRESS_DIR points to repo root
26 set fortress_exe $FORTRESS_DIR/build/gfortran_*/app/fortress
27 else
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
36 end
37
38 # Run fortress
39 eval $fortress_exe $argv
40 set -l exit_code $status
41
42 # Check if fortress wants us to cd somewhere
43 if test -f $HOME/.fortress_cd
44 set -l target_dir (cat $HOME/.fortress_cd)
45 rm -f $HOME/.fortress_cd
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
52 end
53 end
54
55 return $exit_code
56 end