Skip to content

powershell

The community/apps/powershell directory contains files that integrate Talon with the Windows PowerShell, enabling voice control for common terminal and file management tasks.

The file README.md explains how to configure PowerShell to display the current path in the window title. It provides a PowerShell function that can be added to your PowerShell profile to achieve this. This is important because the Talon script powershell_win.py uses the window title to determine the current directory. The README.md also mentions a setting, user.powershell_always_refresh_title, that controls whether the window title is updated after every directory change.

The core logic for Talon integration is in powershell_win.py. This file defines a Talon context that activates when the application is Windows PowerShell or Windows Terminal and the window title contains "PowerShell". It maps Talon commands to actions:

  • edit.delete_line: bound to the escape key.
  • user.file_manager_refresh_title: Inserts the PowerShell command to update the window title to show the current path and executes the command.
  • user.file_manager_open_parent: Changes the directory to the parent directory using cd .. and updates the title if user.powershell_always_refresh_title is true.
  • user.file_manager_current_path: Extracts the current path from the window title, removing prefixes such as "Administrator: " or "Windows PowerShell: ". It also handles path remapping and exclusion based on directories_to_remap and directories_to_exclude variables (which are not populated in this file).
  • user.file_manager_open_directory: Navigates to the given directory using cd and updates the title if user.powershell_always_refresh_title is true.
  • user.file_manager_select_directory: Inserts the given directory path.
  • user.file_manager_new_folder: Inserts the command to create a new folder using mkdir.
  • user.file_manager_open_file: Inserts the command to execute the given file using ./.
  • user.file_manager_select_file: Inserts the given file path.
  • user.file_manager_open_volume: Navigates to the given volume using cd.

The file powershell_win.talon defines the Talon tags that activate the functionality in powershell_win.py, as well as making other commands available. It specifies that the code should activate on Windows when the application is either "Windows PowerShell" or "powershell.exe". It then activates the terminal, user.generic_windows_shell, user.git, user.anaconda, and user.file_manager tags, providing access to commands defined in other parts of the Talon configuration.