Quick Commander / 快速命令
目录
简介
Quick Commander 是一个 VS Code 扩展,可以帮助您快速执行常用命令、代码片段和宏。通过简单的界面,您可以管理和执行各种命令,提高您的工作效率。
功能特点
- 🚀 自定义命令管理:添加、编辑和分类您的命令
- ⚡ 快速执行:通过简单点击执行常用命令
- 📁 分类管理:将命令整理到不同的分类中
- ⌨️ 快捷键绑定:为常用命令绑定自定义快捷键
- 🔄 两种执行模式:
- 自动执行:点击命令后立即执行
- 手动执行:点击命令将其发送到终端但不执行,等待用户确认
- 📦 拖放排序:通过拖放重新排序命令和分类
- 🌍 国际化支持:支持多语言界面(目前支持英文和中文)
- 📤 导入/导出:在不同设备间共享您的命令配置
- 🔤 双语支持:支持中文和英文界面
- 🔧 环境变量支持:使用自定义和预定义变量,灵活执行命令
- 🔍 搜索功能:快速查找所需命令
- 📊 命令执行历史:记录并展示命令执行历史
安装
从 VS Code 扩展市场安装:
- 打开 VS Code
- 按下
Ctrl+P
(或 Cmd+P
on macOS)
- 输入
ext install hearhear.quick-commander
- 按 Enter 安装
使用指南
基本使用
- 在资源管理器视图中找到 "Quick Commands" 面板
- 点击 "+" 图标添加新命令
- 填写命令名称、描述和具体命令内容
- 点击命令项执行命令
管理命令
- 添加命令: 点击顶部 "+" 图标
- 编辑命令: 点击命令项旁边的 "编辑" 图标
- 删除命令: 点击命令项旁边的 "删除" 图标
- 添加分类: 点击 "文件夹" 图标
- 执行模式: 点击 "设置" 图标切换执行模式(自动/手动)
导入/导出命令
- 导出: 点击 "上传" 图标,将命令保存到JSON文件
- 导入: 点击 "下载" 图标,从JSON文件导入命令
配置选项
在设置中可以配置以下选项:
commander.executionMode
: 命令执行模式(自动/手动)
auto
: 点击即执行
manual
: 点击后需确认执行
commander.environmentVariables
: 自定义环境变量
commander.defaultExecutionPath
: 默认执行路径
commander.useWorkspaceRoot
: 是否使用工作区根路径作为执行路径
快捷键
- 可以为每个命令单独绑定快捷键
- 点击命令右键菜单中的 "绑定快捷键" 选项进行设置
使用技巧
- 创建分类整理相关命令,如 Git 操作、构建命令等
- 为常用命令绑定快捷键以提高效率
- 使用拖放功能调整命令顺序,将最常用的放在顶部
- 使用环境变量功能设置默认执行路径,避免重复输入完整路径
常见问题(FAQ)
命令执行相关
Q: 为什么有些命令执行失败?
A: 请检查以下几点:
- 命令路径是否正确
- 是否有足够的执行权限
- 环境变量是否正确设置
- 相关依赖是否已安装
解决方案:
- 使用绝对路径替代相对路径
- 检查文件权限设置
- 验证环境变量配置
- 确保所有依赖都已正确安装
Q: 如何让命令在特定目录下执行?
A: 您可以通过以下方式:
- 使用环境变量功能设置默认执行路径
- 在命令中使用
cd
命令
- 使用工作区根路径设置
具体步骤:
- 打开环境变量设置
- 设置默认执行路径
- 或在命令中添加
cd
指令
配置相关
Q: 如何备份我的命令配置?
A: 您可以通过以下方式:
- 使用导出功能将配置保存为JSON文件
- 将配置文件保存在安全的位置
- 需要时使用导入功能恢复配置
Q: 如何在不同设备间同步配置?
A: 您可以:
- 导出配置文件并传输到其他设备
- 使用版本控制系统管理配置文件
- 将配置文件存储在云存储中
反馈与交流
欢迎加入我们的QQ交流群:938380944 (点击加入)
您也可以通过邮箱联系我们:hearhear@foxmail.com
环境变量功能
Commander 扩展支持环境变量功能,让您能够更灵活地执行命令。
功能概述
环境变量功能包括:
- 自定义环境变量:创建自己的变量,在命令中使用
- 默认执行路径:设置命令默认执行的目录
- 工作区根路径:使用当前工作区作为命令执行的根路径
- 预定义变量:使用内置变量如工作区路径、当前文件信息等
如何使用
打开环境变量管理
点击 Commander 视图标题栏中的"环境变量"按钮(变量图标),或使用命令面板(F1)执行"Commander: 环境变量"命令。
管理环境变量
在环境变量管理界面中,您可以:
- 管理环境变量:添加、编辑或删除自定义环境变量
- 设置默认执行路径:指定命令默认执行的目录
- 切换工作区根路径:启用或禁用使用工作区根路径作为执行路径
在命令中使用环境变量
在命令中使用$变量名
格式引用环境变量:
# 使用自定义变量
echo $MY_VAR
# 使用预定义变量
cd $WORKSPACE_ROOT
ls $FILE_DIR
echo $FILE_NAME
cat $FILE_PATH
预定义变量
Commander 提供以下预定义变量:
变量 |
描述 |
$WORKSPACE_ROOT |
当前工作区根路径 |
$FILE_DIR |
当前文件所在目录 |
$FILE_PATH |
当前文件的完整路径 |
$FILE_NAME |
当前文件的文件名 |
执行路径设置
Commander 支持两种方式设置命令的执行路径:
- 默认执行路径:所有命令默认在此路径下执行
- 工作区根路径:所有命令在当前工作区根目录下执行
启用执行路径设置后,Commander 会自动在命令前添加cd "路径" &&
,例如:
# 原始命令
ls -la
# 使用默认执行路径(例如:/Users/username/projects)后的实际执行命令
cd "/Users/username/projects" && ls -la
# 使用工作区根路径后的实际执行命令
cd "/Users/username/workspace" && ls -la
提示
- 工作区根路径设置优先级高于默认执行路径
- 命令中已包含
cd
指令时,不会添加执行路径
- 自定义变量名称不能包含空格
- 变量引用格式为
$变量名
,不支持${变量名}
格式
Enjoy!
Introduction
Quick Commander is a VS Code extension that helps you quickly execute commonly used commands, code snippets, and macros. Through a simple interface, you can manage and execute various commands to improve your productivity.
Features
- Custom Command Management: Add, edit, and categorize your commands
- Quick Execution: Execute frequently used commands with a simple click
- Category Management: Organize commands into different categories
- Keyboard Bindings: Set shortcuts for frequently used commands
- Two Execution Modes:
- Auto Execution: Execute command immediately upon clicking
- Manual Execution: Send command to terminal without executing, waiting for user confirmation
- Drag and Drop Sorting: Reorder commands and categories through drag and drop
- Internationalization: Support for multiple language interfaces (currently English and Chinese)
- Import/Export: Share your command configurations across different devices
- Bilingual Support: Chinese and English interfaces supported
- Environment Variables: Use custom and predefined variables for flexible command execution
- Search Function: Quickly find the commands you need
- Command Execution History: Record and display command execution history
Installation
Install from VS Code Marketplace:
- Open VS Code
- Press
Ctrl+P
(or Cmd+P
on macOS)
- Type
ext install hearhear.quick-commander
- Press Enter to install
Usage Guide
Basic Usage
- Find the "Quick Commands" panel in the Explorer view
- Click the "+" icon to add a new command
- Fill in the command name, description, and specific command content
- Click on a command item to execute it
Managing Commands
- Add Command: Click the "+" icon at the top
- Edit Command: Click the "Edit" icon next to a command item
- Delete Command: Click the "Delete" icon next to a command item
- Add Category: Click the "Folder" icon
- Execution Mode: Click the "Settings" icon to toggle execution mode (auto/manual)
Import/Export Commands
- Export: Click the "Upload" icon to save commands to a JSON file
- Import: Click the "Download" icon to import commands from a JSON file
Configuration Options
The following options can be configured in settings:
commander.executionMode
: Command execution mode (auto/manual)
auto
: Execute immediately when clicked
manual
: Confirmation required after clicking
commander.environmentVariables
: Custom environment variables
commander.defaultExecutionPath
: Default execution path
commander.useWorkspaceRoot
: Whether to use workspace root path as execution path
Keyboard Shortcuts
- You can bind keyboard shortcuts to individual commands
- Click the "Bind Shortcut" option in the command's right-click menu to set up
Usage Tips
- Create categories to organize related commands, such as Git operations, build commands, etc.
- Bind shortcuts to frequently used commands to improve efficiency
- Use the drag and drop feature to adjust the order of commands, placing the most used ones at the top
- Use environment variables feature to set default execution path, avoiding repetitive input of full paths
Frequently Asked Questions (FAQ)
Command Execution
Q: Why do some commands fail to execute?
A: Please check the following:
- Is the command path correct?
- Do you have sufficient execution permissions?
- Are environment variables properly set?
- Are required dependencies installed?
Solution:
- Use absolute path instead of relative path
- Check file permission settings
- Verify environment variable configuration
- Ensure all dependencies are correctly installed
Q: How to execute commands in a specific directory?
A: You can:
- Use the environment variables feature to set default execution path
- Use
cd
command in your commands
- Use workspace root path settings
Steps:
- Open environment variables settings
- Set default execution path
- Or add
cd
instruction in your commands
Configuration
Q: How to backup my command configurations?
A: You can:
- Use the export feature to save configurations as JSON file
- Store the configuration file in a secure location
- Use the import feature to restore configurations when needed
Q: How to sync configurations across different devices?
A: You can:
- Export configuration file and transfer it to other devices
- Use version control system to manage configuration files
- Store configuration file in cloud storage
Feedback & Communication
Welcome to join our QQ group: 938380944 (Click to Join)
You can also contact us via email: hearhear@foxmail.com
Environment Variables Feature
The Commander extension supports environment variables, allowing you to execute commands more flexibly.
Feature Overview
The environment variables feature includes:
- Custom Environment Variables: Create your own variables for use in commands
- Default Execution Path: Set a default directory for command execution
- Workspace Root Path: Use the current workspace as the root path for command execution
- Predefined Variables: Use built-in variables like workspace path, current file information, etc.
How to Use
Open Environment Variables Management
Click the "Environment Variables" button (variable icon) in the Commander view title bar, or use the command palette (F1) to execute "Commander: Environment Variables".
Manage Environment Variables
In the environment variables management interface, you can:
- Manage Environment Variables: Add, edit, or delete custom environment variables
- Set Default Execution Path: Specify the default directory for command execution
- Toggle Workspace Root Path: Enable or disable using the workspace root path as the execution path
Using Environment Variables in Commands
Use the $variable_name
format to reference environment variables in commands:
# Using custom variables
echo $MY_VAR
# Using predefined variables
cd $WORKSPACE_ROOT
ls $FILE_DIR
echo $FILE_NAME
cat $FILE_PATH
Predefined Variables
Commander provides the following predefined variables:
Variable |
Description |
$WORKSPACE_ROOT |
Current workspace root path |
$FILE_DIR |
Directory of the current file |
$FILE_PATH |
Full path of the current file |
$FILE_NAME |
Filename of the current file |
Execution Path Settings
Commander supports two ways to set the execution path for commands:
- Default Execution Path: All commands are executed in this path by default
- Workspace Root Path: All commands are executed in the current workspace root directory
When execution path settings are enabled, Commander automatically adds cd "path" &&
before commands, for example:
# Original command
ls -la
# Actual command executed with default execution path (e.g., /Users/username/projects)
cd "/Users/username/projects" && ls -la
# Actual command executed with workspace root path
cd "/Users/username/workspace" && ls -la
Tips
- Workspace root path setting takes precedence over default execution path
- Execution path is not added when commands already include a
cd
instruction
- Custom variable names cannot contain spaces
- Variable reference format is
$variable_name
, the ${variable_name}
format is not supported
Enjoy!