Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commands/config-edit
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function config_edit() (
esac
done

if is-vscode; then
if is-vscode-like ; then
# https://github.com/Microsoft/vscode/issues/29523
if [[ $option_line == *' '* ]]; then
option_line="${option_line/ / }"
Expand Down
3 changes: 2 additions & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,8 @@ function dorothy_() (
echo-style --h1='Edit Dorothy'
# ensure_minimal_dependencies <-- if they are editing, then we assume they are already setup
ensure_permissions_configured
if [[ "$(edit --dry --only-editor)" == 'code' ]]; then
local editor="$(edit --dry --only-editor)"
if [[ "$editor" == 'code' || "$editor" == 'cursor' ]]; then
edit -- "$DOROTHY/.vscode/workspace.code-workspace"
else
edit -- "$DOROTHY"
Expand Down
6 changes: 5 additions & 1 deletion commands/edit
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ function edit_() (
local editors=()
if [[ -z $terminal && -z $gui ]]; then
# no terminal or gui preference, determine sensible defaults
if is-vscode; then
if is-cursor; then
editors+=(cursor)
gui='yes'
terminal='yes'
elif is-vscode; then
# if running within vscode, add vscode as first preference
editors+=(code)
gui='yes'
Expand Down
2 changes: 1 addition & 1 deletion commands/get-terminal-title-support
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function get_terminal_title_support() (
# Action

function __check {
is-ci || is-vscode
is-ci || is-vscode-like
}

if [[ $option_quiet == 'yes' ]]; then
Expand Down
64 changes: 64 additions & 0 deletions commands/is-cursor
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

# It has been checked and developed on window platform wsl

function is_cursor() (
source "$DOROTHY/sources/bash.bash"

# =====================================
# Arguments

function help {
cat <<-EOF >/dev/stderr
ABOUT:
Checks if the environment is running within Cursor editor.

USAGE:
is-cursor

RETURNS:
[0] if the environment is within Cursor editor
[1] if the environment is not within Cursor editor
EOF
if [[ $# -ne 0 ]]; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}

# process
local item
while [[ $# -ne 0 ]]; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done

# =====================================
# Action

# Check for Cursor-specific environment variables
if [[ ${NAME-} == "Cursor" ]]; then
return 0
fi

# Also check if we're in VSCode with Cursor-specific environment variables
if [[ ${TERM_PROGRAM-} == 'vscode' ]]; then
# Check for Cursor in environment variables
if env | grep -q "NAME=Cursor"; then
return 0
fi
fi

# If none of the above conditions are met, we're not in Cursor
return 1
)

# fire if invoked standalone
if [[ $0 == "${BASH_SOURCE[0]}" ]]; then
is_cursor "$@"
fi
2 changes: 1 addition & 1 deletion commands/is-vscode
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function is_vscode() (
# =====================================
# Action

if [[ ${TERM_PROGRAM-} == 'vscode' ]]; then
if [[ ${TERM_PROGRAM-} == 'vscode' && ! is-cursor ]]; then
return 0
else
return 1
Expand Down
53 changes: 53 additions & 0 deletions commands/is-vscode-like
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

function is_vscode_like() (
source "$DOROTHY/sources/bash.bash"

# =====================================
# Arguments

function help {
cat <<-EOF >/dev/stderr
ABOUT:
Checks if the environment is running within a VSCode-like editor.
Currently supports VSCode, Cursor, and VSCode Insiders.

USAGE:
is-vscode-like

RETURNS:
[0] if the environment is within a VSCode-like editor
[1] if the environment is not within a VSCode-like editor
EOF
if [[ $# -ne 0 ]]; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}

# process
local item
while [[ $# -ne 0 ]]; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done

# =====================================
# Action

if [[ ${TERM_PROGRAM-} == 'vscode']]; then
return 0
else
return 1
fi
)

# fire if invoked standalone
if [[ $0 == "${BASH_SOURCE[0]}" ]]; then
is_vscode_like "$@"
fi