ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Copy Relative Command

by patoui ST4

Copy's a command relative of your current active file!

Details

  • 1.0.0
  • github.​com
  • github.​com
  • 11 months ago
  • 5 minutes ago
  • 10 months ago

Installs

  • Total 69
  • Win 38
  • Mac 21
  • Linux 10
May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24
Windows 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Copy Relative Command 📋️

A helpful command to copy a command to the clipboard based on configured settings, per language!

Installation 💻️

Within Sublime Text: - open the command palette (Windows/Linux: Ctrl + Shift + P, MacOS: Cmd + Shift + P) - search for “Package Control: Install Package” and press enter - search for “Copy Relative Command” and press enter on the mactching entry

Alternative installation 💻️

Within terminal: - clone this repository into your respective operating systems Packages directory - Linux: cd ~/.config/sublime-text/Packages && git clone git@github.com:patoui/CopyRelativeCommand.git - MacOS: cd ~/Library/Application Support/Sublime Text 3/Packages && git clone git@github.com:patoui/CopyRelativeCommand.git

Quick start 🚀️

  1. open command palette and search for “Copy Relative Command Settings”
  2. add language settings, example:
{
    "languages": {
        "php": [
            {
                "glob": "**Test.php",
                "command": [
                    "vendor/bin/phpunit",
                    "{relative_path}",
                    "--filter={current_function_or_class}"
                ]
            },
            {
                "glob": "*",
                "command": ["php -l {relative_path}"],
            },
        ],
    }
}
  1. execute Copy Relative Command within the configured language, such as a php file in our above example:
    • if the open file (active view) is a file named test/Unit/ExampleTest.php and the cursor is within a function name test_it_should_be_true, the command copied to the clipboard would be:
      • vendor/bin/phpunit test/Unit/ExampleTest.php --filter=test_it_should_be_true
    • if the open file (active view) is a file named app/Http/Controllers/UserController.php the command copied to the clipboard would be:
      • php -l app/Http/Controllers/UserController.php
  2. That's it! Add your own configurations for language commands 👌️

Add a key binding 🔑️

To add a key binding, open “Preferences / Key Bindings - User” and add:

Error: language “jsonc” is not supported
// Copy Relative Command
{ "keys": ["alt+c", "alt+c"], "command": "copy_relative_command" }

With this setting pressing alt + c + c will copy the configured relative command to your system clipboard

Settings 👨‍💻️

Key Parent Description
languages N/A Contains a dictionary of all configured languages commands (e.g. php, go, python) and has a special value of * to apply to all languages
glob languages.* contains a Unix filename pattern to identify which files the current command applies to (see fnmatch and glob)
command languages.* a list (array) of strings which represent the command to be run. The command key has a few helper values:
  • {relative_path} will get the shortest relative path to the current file
  • {current_function} will get the current function which the cursor is in, defaults to an empty string if it’s unable to determine the current function
  • {current_function_or_class} will get the current function which the cursor is in, if it’s not available, it will fallback to the current class, if that’s not available it defaults to an empty string

Project Settings 📽️

  • Open your project settings
    • edit existing project settings “Project: Edit Project”
    • create new project settings “Project: Save As”
  • Add the same settings as you would in your general settings under the Copy Relative Command key
{
    "folders":
    [
        {
            "path": "."
        }
    ],
    "settings": {
        "Copy Relative Command": {
            "languages": {
                "php": [
                    {
                        "glob": "**Test.php",
                        "command": [
                            "vendor/bin/phpunit",
                            "{relative_path}",
                            "--filter={current_function_or_class}"
                        ]
                    },
                    {
                        "glob": "*",
                        "command": ["php -l {relative_path}"],
                    },
                ]
            }
        }
    }
}