| 1 | #!/bin/bash |
| 2 | # This demonstrates the proper usage |
| 3 | |
| 4 | echo "==== FORTRESS CD-ON-EXIT TEST ====" |
| 5 | echo "" |
| 6 | echo "1. First, source the fortress function:" |
| 7 | echo " source ~/Documents/GithubOrgs/FortranGoingOnForty/fortress/fortress.sh" |
| 8 | echo "" |
| 9 | echo "2. Then run: fortress" |
| 10 | echo "" |
| 11 | echo "3. Navigate to a directory you want to cd to" |
| 12 | echo "" |
| 13 | echo "4. Press 'c' on that directory" |
| 14 | echo "" |
| 15 | echo "5. Your shell should cd to that directory" |
| 16 | echo "" |
| 17 | echo "==== TRY THIS IN YOUR TERMINAL ====" |
| 18 | echo "" |
| 19 | echo "Current directory: $(pwd)" |
| 20 | echo "" |
| 21 | |
| 22 | # Source fortress |
| 23 | source ~/Documents/GithubOrgs/FortranGoingOnForty/fortress/fortress.sh |
| 24 | |
| 25 | # Simulate what happens when you press 'c' in fortress |
| 26 | echo "Simulating: you pressed 'c' on the docs/ directory..." |
| 27 | mkdir -p ~/Documents/GithubOrgs/FortranGoingOnForty/fortress/docs |
| 28 | echo "~/Documents/GithubOrgs/FortranGoingOnForty/fortress/docs" > ~/.fortress_cd |
| 29 | |
| 30 | # This is what the fortress() function does after fortress exits |
| 31 | if [ -f "$HOME/.fortress_cd" ]; then |
| 32 | target_dir=$(cat "$HOME/.fortress_cd") |
| 33 | rm -f "$HOME/.fortress_cd" |
| 34 | cd "$target_dir" |
| 35 | echo "✓ Changed directory to: $(pwd)" |
| 36 | fi |