Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Created April 4, 2025 08:01
Show Gist options
  • Save sandcastle/1167e0c8a4471423ba46dd288eb304b1 to your computer and use it in GitHub Desktop.
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
# 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