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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ dmypy.json
.DS_Store
commands/
.qc.cd.path
request.txt
*_cache.json

83 changes: 83 additions & 0 deletions GEMINI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Gemini Agent Instructions for quickcmd

This document provides instructions for the Gemini agent on how to interact with, develop, and manage the `quickcmd` project.

## Project Overview

`quickcmd` is a command-line utility designed to simplify the management and execution of custom commands. It uses `fzf` for fuzzy-finding through commands defined in `.ini` files, allowing for quick, interactive execution. The core logic is written in Python, with a `bash` script acting as the main entry point and wrapper.

## Core Technologies

- **Language**: Python 2/3, Bash
- **Key Libraries**: `requests`, `urllib3`
- **Core Tools**: `fzf` (a command-line fuzzy finder)
- **Configuration**: `.ini` files for command definitions.
- **Testing**: Standard Python `unittest` module.

## Project Structure

- `quickcmd.sh`: The main entry point script that the user sources and calls via the `qc` function. It handles locating the python interpreter and executing the main python script.
- `src/`: Contains all Python source code.
- `quickcmd.py`: The main Python script that parses arguments and orchestrates the application flow.
- `command_manager.py`: Handles loading, adding, deleting, and modifying commands from `.ini` files.
- `command.py`: Represents a single command object.
- `fzf.py`: A wrapper for interacting with the `fzf` command-line tool.
- `iniparser.py`: Custom parser for the `.ini` configuration files.
- `commands/`: The default directory where user-defined command `.ini` files are stored.
- `test/`: Contains unit tests.
- `install.sh`: Script for installing `quickcmd` and its dependencies (`fzf`, python packages).
- `requirements.txt`: Python dependencies.

## Development Workflow

### 1. Install Dependencies

The project requires Python and the packages listed in `requirements.txt`. `fzf` is also a critical dependency.

To install Python dependencies:
```bash
pip install -r requirements.txt
```

### 2. Running the Application

The application is intended to be run via the `qc` function defined in `quickcmd.sh`. For development and testing, you can execute the main Python script directly:

```bash
python src/quickcmd.py
```

To list all commands without using `fzf`:
```bash
python src/quickcmd.py --list
```

### 3. Running Tests

Tests are located in the `test/` directory and can be run using Python's `unittest` module.

```bash
python -m unittest discover test
```

### 4. Managing Commands

- **Location**: Commands are stored in `.ini` files within the `commands/` directory.
- **Adding a Command**: New commands can be added by creating a new `.ini` file or adding a new section to an existing one in the `commands/` directory. The interactive way is to run `python src/quickcmd.py --addcmd`.
- **Structure of a command in `.ini`**:
```ini
[command_name]
command = echo "Hello, World!"
workdir = /tmp
tip = A simple example command.
```

## Goals for Gemini

Your primary tasks for this project will be:

1. **Bug Fixes**: Identify and fix bugs in the Python source code (`src/`) or the `quickcmd.sh` script.
2. **Feature Development**: Add new features, such as new command types, enhanced configuration options, or improved output formatting.
3. **Refactoring**: Improve code quality, such as refactoring the `iniparser.py` or improving the command execution logic in `command_manager.py`.
4. **Writing Tests**: Add new unit tests in the `test/` directory to cover new or existing functionality.
5. **Managing Commands**: Assist with creating, modifying, or deleting commands in the `commands/` directory as requested.
19 changes: 19 additions & 0 deletions config/stock_factors.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[default]
# Default investment factor if not specified by company or industry
factor = 0.85
# Default dividend payout ratio
payout_ratio = 0.50

[company]
# Supports company name or stock code
# Example for a specific stock
五粮液 = 0.85
000858 = 0.85
HK01113 = 0.90

[industry]
# Investment factors by industry
服装 = 0.5
房地产 = 0.6
银行 = 0.7
白酒 = 0.8
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
requests
urllib3<2.0
urllib3<2.0
akshare
pandas
25 changes: 18 additions & 7 deletions src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,36 @@ def __init__(self, file="", name="", items=[]):
self.tip = infos.get("tip", "")
self.api_key = infos.get("api_key", "")
self.multi_line_question = infos.get("multi_line_question", False)
self.type = infos.get("type", "")
self.file = file

if self.command:
if self.type == "stock":
self.cmd_type = "stock"
prefix = "[STOCK] "
elif self.command:
prefix = "[CMD] "
self.cmd_type = "cmd"

elif self.godir:
self.cmd_type = "cd"
prefix = "[GOTO] "

elif self.tip:
self.cmd_type = "tip"
prefix = "[TIP] "

elif self.api_key:
self.cmd_type = "chatgpt"
prefix = "[ChatGPT] "

else:
sys.exit("Unknown command")
sys.exit(f"Unknown command: {self.type}")


self.name = prefix + name
self.name = self.name.replace(" ", "-")

self.qcc = QuickCmdColor()

def get_type(self):
return self.cmd_type

def abs_path(self, path):
if path and path.startswith("~"):
# os.path.join(os.path.expanduser("~"), path[1:])
Expand Down Expand Up @@ -108,6 +112,7 @@ def complete(self):

for variable in variables:
m = re.match(r'^\${(\w+)}$', variable)
# m = re.match(r'^\${(\w+)}', variable)
name = m.group(1)

try:
Expand Down Expand Up @@ -186,6 +191,9 @@ def tostring(self):
elif self.cmd_type == "tip":
s = "%s\n[+] Tip = %s" % (s, self.tip)

elif self.cmd_type == "stock":
s = "%s\n[+] Type = Stock Analysis" % (s)

if self.file:
s = "%s\n[+] In file = %s" %(s, self.file)

Expand All @@ -199,7 +207,10 @@ def fzf_str(self, index):
res = "{}; cd {}".format(res, self.godir)
elif self.tip:
res = "{}; tip: {}".format(res, self.tip)
elif self.cmd_type == "stock":
res = "{}: {}".format(res, "Perform stock analysis")


res = "{}\r\n".format(res)
res = "{}\n".format(res)
return res

Loading