Created
April 4, 2025 08:01
-
-
Save sandcastle/1167e0c8a4471423ba46dd288eb304b1 to your computer and use it in GitHub Desktop.
Detect if Cursor or VSCode agent (shell and non-interactive) and don't run interactive commands like bat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helper function to detect if running in VSCode or Cursor | |
is_agent_context() { | |
# Multiple detection methods for Cursor context | |
# 1. Check if its vscode or cursor (both have the same TERM_PROGRAM) | |
# 2. Check if this is being executed from a non-interactive shell (common in agents) | |
if [[ "$TERM_PROGRAM" == "vscode" ]] && | |
[[ ! -o interactive ]]; then | |
return 0 # true in shell logic | |
else | |
return 1 # false in shell logic | |
fi | |
} | |
if (( $+commands[bat] )); then | |
# bat: cat clone with syntax highlighting and Git integration | |
# Smart wrapper that disables paging when called from VSCode/Cursor | |
bat_wrapper() { | |
if is_agent_context; then | |
# Dont use paging or style this can break AI agents | |
bat --paging=never --style=plain "$@" | |
else | |
bat "$@" # Default behavior with auto paging, which is interactive | |
fi | |
} | |
alias cat='bat_wrapper' | |
alias cats='bat' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment