Fish · 1538 bytes Raw Blame History
1 # Parrot shell hook for fish - source this in your fish config
2 # Typically installed to ~/.config/fish/conf.d/parrot.fish
3
4 # Path to parrot binary - update this if needed
5 set -g PARROT_BIN "parrot"
6
7 # Function to check if parrot binary exists
8 function parrot_check
9 if not command -v $PARROT_BIN >/dev/null 2>&1
10 echo "⚠️ Parrot binary not found. Make sure 'parrot' is in your PATH."
11 return 1
12 end
13 return 0
14 end
15
16 # Function called after each command completes
17 function parrot_postexec --on-event fish_postexec
18 set -l exit_code $status
19 set -l last_cmd (history max 1)
20
21 # Only mock if command failed and we have a command
22 if test $exit_code -ne 0; and test -n "$last_cmd"; and parrot_check
23 # Run parrot in background to avoid blocking shell if PARROT_ASYNC is set
24 if test "$PARROT_ASYNC" = "true"
25 $PARROT_BIN mock "$last_cmd" "$exit_code" &
26 else
27 $PARROT_BIN mock "$last_cmd" "$exit_code"
28 end
29 end
30 end
31
32 # Setup hook (only show messages if not already initialized and in interactive mode)
33 if not set -q PARROT_INITIALIZED
34 # Only show messages in interactive shells
35 if status is-interactive
36 echo "🦜 Parrot is now watching your fish commands..."
37
38 # Show performance tip
39 if test "$PARROT_ASYNC" != "true"
40 echo "💡 Tip: Set PARROT_ASYNC=true to prevent terminal hangs on slow networks"
41 end
42 end
43
44 # Mark as initialized for this shell session
45 set -gx PARROT_INITIALIZED 1
46 end