Skip to content

Commit

Permalink
Merge branch 'main' into capitalize-formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
nriley authored Jul 22, 2023
2 parents a61aba5 + 7525147 commit 0eaa1dc
Show file tree
Hide file tree
Showing 35 changed files with 438 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.9-for-vscode"
rev: "v3.0.0"
hooks:
- id: prettier
- repo: https://github.com/ikamensh/flynt/
rev: "0.78"
rev: "1.0.0"
hooks:
- id: flynt
- repo: https://github.com/pycqa/isort
Expand All @@ -46,7 +46,7 @@ repos:
files: \.talon$
args: ["--whitespaces-count=4"]
- repo: https://github.com/wenkokke/talonfmt
rev: 1.9.5
rev: 1.10.1
hooks:
- id: talonfmt
args: ["--in-place"]
2 changes: 1 addition & 1 deletion BREAKING_CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This file lists known changes to knausj_talon that are likely to have broken existing
This file lists known changes to `community` that are likely to have broken existing
functionality. The file is sorted by date with the newest entries up the top.

Be aware there may be some difference between the date in this file and when the change was
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
This document attempts to list a set of principles for contributors to the knausj_talon repository to consider. The idea is to document some agreed upon approaches toward reviewing and including code so we can all more easily make consistent decisions.
This document attempts to list a set of principles for contributors to the `community` repository to consider. The idea is to document some agreed upon approaches toward reviewing and including code so we can all more easily make consistent decisions.

Each of the principles is numbered for easy referencing. The body is formatted as a short single-line summary of the principle followed by elaboration and discussion links.

# Voice command principles

- P01 - Prefer [object][verb] rather than [verb][object] for new commands. For example 'file save' is better than 'save file'. It may not sound as natural, but it helps for grouping related commands in lists and avoiding conflicting names.
- P02 - Use `browser.host` matcher for web apps. Though this matcher requires a [browser extension](https://github.com/knausj85/knausj_talon/blob/main/apps/README.md) on some operating systems it is the only unambiguous way of referring to a web app.
- P02 - Use `browser.host` matcher for web apps. Though this matcher requires a [browser extension](https://github.com/talonhub/community/blob/main/apps/README.md) on some operating systems it is the only unambiguous way of referring to a web app.

# Coding principles

Expand Down
72 changes: 37 additions & 35 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion apps/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Web apps and browser extensions

Some of the Talon files for web apps (e.g. `apps/github/github_web.talon`) use a `browser.host` matcher. These talon files should work out of the box for Safari, Chrome, Brave, on Mac, but require additional configuration on other browsers/operating systems. `knausj_talon` is set up so that if a URL is found in the titlebar of an application matching the 'browser' tag it will be used to populate the browser.host matcher (see `code/browser.py`). This probably means that you will need an extension to make the browser.host based scripts work.
Some of the Talon files for web apps (e.g. `apps/github/github_web.talon`) use a `browser.host` matcher. These talon files should work out of the box for Safari, Chrome, Brave, on Mac, but require additional configuration on other browsers/operating systems.

`community` is set up so that if a URL is found in the titlebar of an application matching the 'browser' tag it will be used to populate the browser.host matcher (see `code/browser.py`). This probably means that you will need an extension to make the browser.host based scripts work.

Browser extensions that can add the protocol and hostname or even the entire URL to the window title:

Expand Down
45 changes: 45 additions & 0 deletions apps/orion/orion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from talon import Context, Module, actions, ui
from talon.mac import applescript

ctx = Context()
mod = Module()
apps = mod.apps
mod.apps.orion = """
os: mac
app.bundle: com.kagi.kagimacOS
"""

ctx.matches = r"""
app: orion
"""


@ctx.action_class("user")
class UserActions:
def browser_open_address_in_new_tab():
actions.key("cmd-enter")


@ctx.action_class("browser")
class BrowserActions:
def bookmark_tabs():
raise NotImplementedError("Orion doesn't have a default shortcut for this")

def show_clear_cache():
actions.key("cmd-alt-e")

def reload_hard():
actions.key("cmd-alt-r")

def show_downloads():
actions.key("cmd-alt-l")

def show_extensions():
actions.key("cmd-shift-x")


@mod.action_class
class Actions:
def overview_tabs():
"Toggle tab overview in Orion"
actions.key("cmd-shift-\\")
6 changes: 6 additions & 0 deletions apps/orion/orion.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
app: orion
-
tag(): browser
tag(): user.tabs

tab overview [open | close]: user.overview_tabs()
2 changes: 1 addition & 1 deletion apps/talon_repl/talon_repl.talon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag(): user.talon_python
# uncomment user.talon_populate_lists tag to activate talon-specific lists of actions, scopes, modes etcetera.
# Do not enable this tag with dragon, as it will be unusable.
# with conformer, the latency increase may also be unacceptable depending on your cpu
# see https://github.com/knausj85/knausj_talon/issues/600
# see https://github.com/talonhub/community/issues/600
# tag(): user.talon_populate_lists

^test last$:
Expand Down
9 changes: 6 additions & 3 deletions apps/tmux/tmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
setting_tmux_prefix_key = mod.setting(
"tmux_prefix_key",
type=str,
default="b",
default="ctrl-b",
desc="The key used to prefix all tmux commands",
)

Expand All @@ -19,7 +19,7 @@
class TmuxActions:
def tmux_prefix():
"""press control and the configured tmux prefix key"""
actions.key(f"ctrl-{setting_tmux_prefix_key.get()}")
actions.key(f"{setting_tmux_prefix_key.get()}")

def tmux_keybind(key: str):
"""press tmux prefix followed by a key bind"""
Expand Down Expand Up @@ -60,7 +60,10 @@ def tab_previous():
@ctx.action_class("user")
class UserActions:
def tab_jump(number: int):
actions.user.tmux_execute_command(f"select-window -t {number}")
if number < 10:
actions.user.tmux_keybind(f"{number}")
else:
actions.user.tmux_execute_command(f"select-window -t {number}")

def tab_close_wrapper():
actions.user.tmux_execute_command_with_confirmation(
Expand Down
6 changes: 4 additions & 2 deletions apps/vscode/command_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ This directory contains the client code for communicating with the [VSCode comma

## Contributing

The source of truth is in https://github.com/knausj85/knausj_talon/tree/main/apps/vscode/command_client, but the code is also maintained as a subtree at https://github.com/pokey/talon-vscode-command-client.
The source of truth is in https://github.com/talonhub/community/tree/main/apps/vscode/command_client, but the code is also maintained as a subtree at https://github.com/pokey/talon-vscode-command-client.

To contribute, first open a PR on knausj. Once the PR is merged, you can push the changes to the subtree by running the following commands on an up-to-date knausj main: (need write access)
To contribute, first open a PR on `community`.

Once the PR is merged, you can push the changes to the subtree by running the following commands on an up-to-date `community` main: (need write access)

```sh
git subtree split --prefix=apps/vscode/command_client --annotate="[split] " -b split
Expand Down
59 changes: 57 additions & 2 deletions core/app_switcher/app_switcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shlex
import subprocess
import time
from pathlib import Path
Expand All @@ -9,7 +10,7 @@
# Construct at startup a list of overides for application names (similar to how homophone list is managed)
# ie for a given talon recognition word set `one note`, recognized this in these switcher functions as `ONENOTE`
# the list is a comma seperated `<Recognized Words>, <Overide>`
# TODO: Consider put list csv's (homophones.csv, app_name_overrides.csv) files together in a seperate directory,`knausj_talon/lists`
# TODO: Consider put list csv's (homophones.csv, app_name_overrides.csv) files together in a seperate directory,`community/lists`
overrides_directory = os.path.dirname(os.path.realpath(__file__))
override_file_name = f"app_name_overrides.{talon.app.platform}.csv"
override_file_path = os.path.join(overrides_directory, override_file_name)
Expand All @@ -33,6 +34,14 @@
"/System/Applications/Utilities",
]

linux_application_directories = [
"/usr/share/applications",
"/usr/local/share/applications",
os.path.expandvars("/home/$USER/.local/share/applications"),
"/var/lib/flatpak/exports/share/applications",
"/var/lib/snapd/desktop/applications",
]

words_to_exclude = [
"zero",
"one",
Expand Down Expand Up @@ -162,6 +171,45 @@ def get_windows_apps():
return items


if app.platform == "linux":
import configparser
import re

def get_linux_apps():
# app shortcuts in program menu are contained in .desktop files. This function parses those files for the app name and command
items = {}
# find field codes in exec key with regex
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables
args_pattern = re.compile(r" \%[UufFcik]")
for base in linux_application_directories:
if os.path.isdir(base):
for entry in os.scandir(base):
if entry.name.endswith(".desktop"):
try:
config = configparser.ConfigParser(interpolation=None)
config.read(entry.path)
# only parse shortcuts that are not hidden
if config.has_option("Desktop Entry", "NoDisplay") == False:
name_key = config["Desktop Entry"]["Name"]
exec_key = config["Desktop Entry"]["Exec"]
# remove extra quotes from exec
if exec_key[0] == '"' and exec_key[-1] == '"':
exec_key = re.sub('"', "", exec_key)
# remove field codes and add full path if necessary
if exec_key[0] == "/":
items[name_key] = re.sub(args_pattern, "", exec_key)
else:
items[name_key] = "/usr/bin/" + re.sub(
args_pattern, "", exec_key
)
except:
print(
"get_linux_apps: skipped parsing application file ",
entry.name,
)
return items


@mod.capture(rule="{self.running}") # | <user.text>)")
def running_applications(m) -> str:
"Returns a single application name"
Expand Down Expand Up @@ -280,7 +328,10 @@ def switcher_focus_window(window: ui.Window):
def switcher_launch(path: str):
"""Launch a new application by path (all OSes), or AppUserModel_ID path on Windows"""
if app.platform != "windows":
ui.launch(path=path)
# separate command and arguments
cmd = shlex.split(path)[0]
args = shlex.split(path)[1:]
ui.launch(path=cmd, args=args)
else:
is_valid_path = False
try:
Expand Down Expand Up @@ -337,6 +388,10 @@ def update_launch_list():

elif app.platform == "windows":
launch = get_windows_apps()

elif app.platform == "linux":
launch = get_linux_apps()

# actions.user.talon_pretty_print(launch)

ctx.lists["self.launch"] = actions.user.create_spoken_forms_from_map(
Expand Down
4 changes: 2 additions & 2 deletions core/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
be an important part of people's workflows providing a warning before removing
functionality is encouraged.
The normal deprecation process in knausj_talon is as follows:
The normal deprecation process in `community` is as follows:
1. For 6 months from deprecation a deprecated action or command should
continue working. Put an entry in the BREAKING_CHANGES.txt file in the
Expand Down Expand Up @@ -46,7 +46,7 @@ def legacy_capture(m) -> str:
actions.user.deprecate_capture("2023-09-03", "user.legacy_capture")
# implement capture
See https://github.com/knausj85/knausj_talon/issues/940 for original discussion
See https://github.com/talonhub/community/issues/940 for original discussion
"""

import datetime
Expand Down
2 changes: 1 addition & 1 deletion core/edit/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def line_clone():
actions.edit.paste()

# # This simpler implementation of select_word mostly works, but in some apps it doesn't.
# # See https://github.com/knausj85/knausj_talon/issues/1084.
# # See https://github.com/talonhub/community/issues/1084.
# def select_word():
# actions.edit.right()
# actions.edit.word_left()
Expand Down
5 changes: 3 additions & 2 deletions core/edit/edit_mac.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from talon import Context, actions
from talon import Context, actions, clip

ctx = Context()
ctx.matches = r"""
Expand Down Expand Up @@ -90,8 +90,9 @@ def file_start():
actions.key("cmd-up")

def find(text: str = None):
if text is not None:
clip.set_text(text, mode="find")
actions.key("cmd-f")
# actions.insert(text)

def find_next():
actions.key("cmd-g")
Expand Down
2 changes: 1 addition & 1 deletion core/edit_text_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from talon import Context, Module, app

# path to knausj root directory
# path to community/knausj root directory
REPO_DIR = os.path.dirname(os.path.dirname(__file__))
SETTINGS_DIR = os.path.join(REPO_DIR, "settings")

Expand Down
3 changes: 3 additions & 0 deletions core/file_extension/file_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"dot g zip": ".gzip",
"dot zip": ".zip",
"dot toml": ".toml",
"dot java": ".java",
"dot class": ".class",
"dot log": ".log",
}

file_extensions = get_list_from_csv(
Expand Down
2 changes: 1 addition & 1 deletion core/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from talon import resource

# NOTE: This method requires this module to be one folder below the top-level
# knausj folder.
# community/knausj folder.
SETTINGS_DIR = Path(__file__).parents[1] / "settings"

if not SETTINGS_DIR.is_dir():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
open {user.website}: user.open_url(website)
open that: user.open_url(edit.selected_text())
open paste: user.open_url(clip.text())

{user.search_engine} hunt <user.text>$:
user.search_with_search_engine(search_engine, user.text)
{user.search_engine} (that | this):
text = edit.selected_text()
user.search_with_search_engine(search_engine, text)
{user.search_engine} paste: user.search_with_search_engine(search_engine, clip.text())
9 changes: 0 additions & 9 deletions lang/java/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,6 @@ def code_define_class():
def code_import():
actions.insert("import ")

def code_private_function(text: str):
actions.insert("private")

def code_protected_function(text: str):
actions.user.code_private_function()

def code_public_function(text: str):
actions.insert("public ")

def code_state_return():
actions.insert("return ")

Expand Down
2 changes: 1 addition & 1 deletion lang/talon/talon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# is active to prevent them from being active in contexts where they are not wanted.
# Do not enable this tag with dragon, as it will be unusable.
# with conformer, the latency increase may also be unacceptable depending on your cpu
# see https://github.com/knausj85/knausj_talon/issues/600
# see https://github.com/talonhub/community/issues/600
ctx_talon_lists.matches = r"""
tag: user.talon_populate_lists
"""
Expand Down
2 changes: 1 addition & 1 deletion lang/talon/talon.talon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tag(): user.code_functions_common
# uncomment user.talon_populate_lists tag to activate talon-specific lists of actions, scopes, modes etcetera.
# Do not enable this tag with dragon, as it will be unusable.
# with conformer, the latency increase may also be unacceptable depending on your cpu
# see https://github.com/knausj85/knausj_talon/issues/600
# see https://github.com/talonhub/community/issues/600
# tag(): user.talon_populate_lists

dot talon: insert(".talon")
Expand Down
Loading

0 comments on commit 0eaa1dc

Please sign in to comment.