Fish · 1586 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 # Note: fish_postexec receives the command as $argv[1]
18 function parrot_postexec --on-event fish_postexec
19 set -l exit_code $status
20 set -l last_cmd $argv[1]
21
22 # Only mock if command failed and we have a command
23 if test $exit_code -ne 0; and test -n "$last_cmd"; and parrot_check
24 # Run parrot in background to avoid blocking shell if PARROT_ASYNC is set
25 if test "$PARROT_ASYNC" = "true"
26 $PARROT_BIN mock "$last_cmd" "$exit_code" &
27 else
28 $PARROT_BIN mock "$last_cmd" "$exit_code"
29 end
30 end
31 end
32
33 # Setup hook (only show messages if not already initialized and in interactive mode)
34 if not set -q PARROT_INITIALIZED
35 # Only show messages in interactive shells
36 if status is-interactive
37 echo "🦜 Parrot is now watching your fish commands..."
38
39 # Show performance tip
40 if test "$PARROT_ASYNC" != "true"
41 echo "💡 Tip: Set PARROT_ASYNC=true to prevent terminal hangs on slow networks"
42 end
43 end
44
45 # Mark as initialized for this shell session
46 set -gx PARROT_INITIALIZED 1
47 end