How to Create a Custom Terminal Command to Launch the Cursor AppImage and Open Files or Directories in Linux
Introduction
Cursor is a popular code editor distributed as an AppImage, making it highly portable and easy to use across Linux systems. However, manually navigating to the file and running it each time can be inconvenient. In this article, we’ll walk you through setting up a custom terminal command called cursor
that will launch the Cursor AppImage, and we'll add functionality to open files or directories directly in Cursor.
Prerequisites
You have the Cursor AppImage stored locally (
cursor-0.39.6-build-240819ih4ta2fye-x86_64.AppImage
), get the latest one.You're comfortable using the terminal and editing configuration files.
Step 1: Ensure the Cursor AppImage is Executable
The first step is to make sure that the Cursor AppImage is executable. The following command will grant the necessary permissions:
chmod +x /complete/path/to/cursor-0.39.6-build-240819ih4ta2fye-x86_64.AppImage
Replace /complete/path/to/
with the actual path where the Cursor AppImage is located, such as /home/username/
.
Step 2: Create a cursor
Function in Your Shell Configuration File
We will now create a function that allows you to open the Cursor AppImage by typing cursor
in the terminal. This function will also allow you to open specific files or directories by passing them as arguments.
Open your shell configuration file:
For
bash
users, edit your.bashrc
file:nano ~/.bashrc
For
zsh
users, edit.zshrc
instead:nano ~/.zshrc
Add the following function to your file:
Scroll to the bottom of the file and add this function:
function cursor { if [[ $# -eq 0 ]] then /complete/path/to/cursor-0.39.6-build-240819ih4ta2fye-x86_64.AppImage & else local argPath="$1" [[ $1 = /* ]] && argPath="$1" || argPath="$PWD/${1#./}" /complete/path/to/cursor-0.39.6-build-240819ih4ta2fye-x86_64.AppImage "$argPath" & fi }
Explanation:
Replace
/complete/path/to/
with the actual path to the Cursor AppImage (e.g.,/home/username/
).The function checks if any arguments are passed. If no arguments are given, it launches Cursor. If a file or directory is provided, it opens that file or directory directly in Cursor.
Save and close the file:
After adding the function, press
CTRL + X
, thenY
, and hitEnter
to save and exit.
Step 3: Reload Your Shell
To apply the changes to your shell configuration, reload your .bashrc
or .zshrc
file by running:
source ~/.bashrc
For zsh
, use:
source ~/.zshrc
Step 4: Use the cursor
Command
Now that your cursor
command is ready, you can use it in the terminal:
To open the Cursor AppImage:
Simply type:
cursor
To open a specific file or directory in Cursor:
Use the
cursor
command followed by the path to the file or directory:cursor /path/to/file
Conclusion
You’ve successfully created a custom terminal command to quickly open the Cursor AppImage, with the added ability to open specific files or directories. This setup can be extended to other AppImages if needed, but for Cursor, this will make your workflow much smoother!
Now you can code with ease by typing cursor
in the terminal, making the Cursor code editor always a simple command away.