summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rwxr-xr-xdmenu_raycast17
-rw-r--r--package.json6
-rw-r--r--src/index.tsx12
4 files changed, 45 insertions, 4 deletions
diff --git a/README.md b/README.md
index b817d26..44479d9 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,19 @@ Inspired by [this orange website commenter](https://news.ycombinator.com/item?id
Whitespace is stripped, but this might change in the future once I check if `dmenu` also does that lol.
-**TODO:** `-p` (prompt) support
+```
+usage: raycast_dmenu [-h] [-p PROMPT]
+
+dmenu-like raycast extension
+
+Provide option list as stdin, the stdout will contain the chosen option.
+If no option was chosen, the program will exit with the return code set to 1.
+
+options:
+ -h, --help show this help message and exit
+ -p PROMPT, --prompt PROMPT
+ search bar placeholder text
+```
## Installation
diff --git a/dmenu_raycast b/dmenu_raycast
index 8e91f55..219b2ec 100755
--- a/dmenu_raycast
+++ b/dmenu_raycast
@@ -4,12 +4,24 @@ import sys
import subprocess
from urllib.parse import urlencode, quote
import socket
+import argparse
+
+from argparse import RawDescriptionHelpFormatter
EXTENSION = "irth/dmenu"
COMMAND = "index"
-elements = list(sys.stdin)
+parser = argparse.ArgumentParser(
+ prog='raycast_dmenu',
+ description="""dmenu-like raycast extension
+
+Provide option list as stdin, the stdout will contain the chosen option.
+If no option was chosen, the program will exit with the return code set to 1.""", formatter_class=RawDescriptionHelpFormatter)
+parser.add_argument('-p', '--prompt', help='search bar placeholder text')
+args = parser.parse_args()
+
+elements = list(sys.stdin)
server = socket.socket()
server.bind(("127.0.0.1", 0))
@@ -22,6 +34,9 @@ arguments = {
"port": str(port),
}
+if args.prompt is not None:
+ arguments["prompt"]=args.prompt
+
query = urlencode({"arguments": json.dumps(arguments)}, quote_via=quote)
url = f"raycast://extensions/{EXTENSION}/{COMMAND}?{query}"
diff --git a/package.json b/package.json
index b0e1c9a..e53d371 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,12 @@
"placeholder": "Port",
"type": "text",
"required": true
+ },
+ {
+ "name": "prompt",
+ "placeholder": "Prompt",
+ "type": "text",
+ "required": false
}
]
}
diff --git a/src/index.tsx b/src/index.tsx
index aa7f16b..03ace88 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -3,7 +3,15 @@ import { connect, Socket } from "net";
import { showFailureToast } from "@raycast/utils";
import { useState, useEffect, useRef } from "react";
-export default function Command({ arguments: { host, port } }: { arguments: { host: string; port: string } }) {
+type Props = {
+ arguments: {
+ host: string;
+ port: string;
+ prompt?: string;
+ };
+};
+
+export default function Command({ arguments: { host, port, prompt } }: Props) {
const [elements, setElements] = useState<string[]>();
const socket = useRef<Socket>();
@@ -44,7 +52,7 @@ export default function Command({ arguments: { host, port } }: { arguments: { ho
}, [host, port]);
return (
- <List isLoading={elements === undefined}>
+ <List isLoading={elements === undefined} searchBarPlaceholder={prompt}>
{elements?.map((item, idx) => (
<List.Item
title={item}