Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for GitHub and Jujitsu CLIs #1551

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 apps/git/git.talon
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ git stash [push] [<user.git_arguments>] message [<user.prose>]:
git status$: "git status\n"
git add patch$: "git add --patch\n"
git show head$: "git show HEAD\n"
git diff$: "git diff\n"
git diff head$: "git diff\n"
git diff (cached | cashed)$: "git diff --cached\n"

# Convenience
Expand Down
37 changes: 37 additions & 0 deletions apps/github/cli/github_arguments.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Option, Spoken form
--help, help
cancel
checkout
checks
clone
close
comment
create
delete
diff
disable
download
edit
enable
fork
list
lock
login
logout
merge
ready
refresh
rename
reopen
rerun
review
run
setup-git, setup get
status
switch
sync
token
unlock
upload
view
watch
42 changes: 42 additions & 0 deletions apps/github/cli/github_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import csv
from pathlib import Path

from talon import Context, Module, resource

mod = Module()
ctx = Context()

mod.list("github_command", desc="Github commands.")
mod.list("github_argument", desc="Command-line github options and arguments.")

dirpath = Path(__file__).parent
arguments_csv_path = str(dirpath / "github_arguments.csv")
commands_csv_path = str(dirpath / "github_commands.csv")


def make_list(path):
with resource.open(path, "r") as f:
rows = list(csv.reader(f))
mapping = {}
# ignore header row
for row in rows[1:]:
if len(row) == 0:
continue
if len(row) == 1:
row = row[0], row[0]
if len(row) > 2:
print("{path!r}: More than two values in row: {row}. Ignoring the extras.")
output, spoken_form = row[:2]
spoken_form = spoken_form.strip()
mapping[spoken_form] = output
return mapping


ctx.lists["self.github_argument"] = make_list(arguments_csv_path)
ctx.lists["self.github_command"] = make_list(commands_csv_path)


@mod.capture(rule="{user.github_argument}+")
def github_arguments(m) -> str:
"""A non-empty sequence of github command arguments, preceded by a space."""
return " " + " ".join(m.github_argument_list)
12 changes: 12 additions & 0 deletions apps/github/cli/github_cli.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tag: terminal
and tag: user.git
-
get hub {user.github_command} [<user.github_arguments>]:
args = github_arguments or ""
"gh {github_command}{args} "

# Convenience
github repo clone clipboard:
insert("gh repo clone ")
edit.paste()
key(enter)
13 changes: 13 additions & 0 deletions apps/github/cli/github_commands.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Subcommand, Spoken form (optional)
auth, authenticate
browse
codespace, code space
gist
issue
org
project
release
pr, request
repo
run
workflow
43 changes: 43 additions & 0 deletions apps/jujitsu/jujitsu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import csv
import os
from pathlib import Path

from talon import Context, Module, resource

mod = Module()
ctx = Context()

mod.list("jujitsu_command", desc="jujitsu commands.")
mod.list("jujitsu_argument", desc="Command-line jujitsu options and arguments.")

dirpath = Path(__file__).parent
arguments_csv_path = str(dirpath / "jujitsu_arguments.csv")
commands_csv_path = str(dirpath / "jujitsu_commands.csv")


def make_list(path):
with resource.open(path, "r") as f:
rows = list(csv.reader(f))
mapping = {}
# ignore header row
for row in rows[1:]:
if len(row) == 0:
continue
if len(row) == 1:
row = row[0], row[0]
if len(row) > 2:
print("{path!r}: More than two values in row: {row}. Ignoring the extras.")
output, spoken_form = row[:2]
spoken_form = spoken_form.strip()
mapping[spoken_form] = output
return mapping


ctx.lists["self.jujitsu_argument"] = make_list(arguments_csv_path)
ctx.lists["self.jujitsu_command"] = make_list(commands_csv_path)


@mod.capture(rule="{user.jujitsu_argument}+")
def jujitsu_arguments(m) -> str:
"""A non-empty sequence of jujitsu command arguments, preceded by a space."""
return " " + " ".join(m.jujitsu_argument_list)
24 changes: 24 additions & 0 deletions apps/jujitsu/jujitsu.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
tag: terminal
and tag: user.git
-
jojo {user.jujitsu_command} [<user.jujitsu_arguments>]:
args = jujitsu_arguments or ""
"jj {jujitsu_command}{args} "
jojo describe [<user.jujitsu_arguments>] message [<user.prose>]:
args = jujitsu_arguments or ""
message = prose or ""
user.insert_between('jj describe{args} --message "{message}', '"')
jojo new [<user.jujitsu_arguments>] message [<user.prose>]:
args = jujitsu_arguments or ""
message = prose or ""
user.insert_between('jj new{args} --message "{message}', '"')
jojo commit [<user.jujitsu_arguments>] message [<user.prose>]:
args = jujitsu_arguments or ""
message = prose or ""
user.insert_between('jj commit{args} --message "{message}', '"')

# Optimistic execution for frequently used commands that are harmless (don't
# change repository or index state).
jojo status$: "jj status\n"
jojo show head$: "jj show HEAD\n"
jojo diff head$: "jj diff\n"
35 changes: 35 additions & 0 deletions apps/jujitsu/jujitsu_arguments.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Option, Spoken form
--add, add
--allow-backwards, allow backwards
--clear, clear
--colocate, colocate
--destination, destination
--dry-run, dry run
--from, from
--ignore-immutable, ignore immutable
--ignore-working-copy, ignore working copy
--insert-after, insert after
--insert-before, insert before
--interactive, interactive
--into, into
-h, help
--help, more help
--limit, limit
--no-edit, no edit
--no-pager, no pager
--patch, patch
--quiet, quiet
--remove, remove
--repo, repo
--repository, repository
--reset-author, reset author
--reversed, reversed
-r, revision
-r, revisions
--skip-empty, skip empty
--source, source
--stdin, standard in
--summary, summary
--to, to
--user, user
--what, what
79 changes: 79 additions & 0 deletions apps/jujitsu/jujitsu_commands.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Subcommand, Spoken form (optional)
abandon
backout, back out
branch
branch create
branch delete
branch forget
branch list
branch rename
branch set
branch track
branch untrack, branch un track
cat
chmod, change mod
config
config edit
config get
config list
config path
config set
describe
diff
diffedit
duplicate
edit
files
fix
git
git clone
git export
git fetch
git import
git init, git initialize
git push
git remote
git remote add
git remote list
git remote remove
git remote rename
help
init, in it
interdiff, intersect diff
log
new
next
obslog, object log
operation
operation abandon
operation log
operation restore
operation undo
parallelize
prev, previous
rebase
resolve
restore
root
show
sparse
sparse edit
sparse list
sparse reset
sparse set
split
squash
status
Subcommand, Spoken form (optional)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting subcommand

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 auto sort.

tag
tag list
undo
unsquash, un squash
untrack, un track
version
workspace
workspace add
workspace forget
workspace list
workspace root
workspace update-stale, workspace update stale