Smart Path Copy
Sublime package to build and send commands to clipboard depending on file.
Details
Installs
- Total 1K
- Win 662
- Mac 321
- Linux 202
Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | Oct 6 | Oct 5 | Oct 4 | Oct 3 | Oct 2 | Oct 1 | Sep 30 | Sep 29 | Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | Sep 22 | Sep 21 | Sep 20 | Sep 19 | Sep 18 | Sep 17 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 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 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 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 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
SmartPathCopy (Sublime Text 2/3 plugin)
When you head over to the console right after making some changes to a file, chances are that the command you will run is related to the file you were just looking at, and the type of the command will depend on the type of the file.
For example, if you're making changes to path/to/test.rb
, chances are you're going to run a command to run the tests in path/to/test.rb
.
Similarly, if you're writing a migration on rails like db/migrate/20150406132142_add_authentication_token_to_users.rb
, chances are that when you head over to the console, you just want to run either rake db:migrate
or rake db:migrate:up VERSION=20170213214913
Case scenario
You're in the zone developing and writing tests like it's nobody's business.
You think your test is ready and want to quickly run it, but you don't have a TDD mechanism in place or you haven't started it.
You head over to the console to run the test.
You start typing rspec
and realized that you forgot the path to the spec file, so you go back to sublime to Copy Path
.
While you're at it you look at the line number the test you want to run is on, so you can specify it as part of the rspec
command.
You go back to the console and you're finally ready to run rspec path/to/file:line_number
All this process takes you out of the zone. So far away from it that the zone looks like a tiny dot from where you're at now.
With SmartPathCopy, all you need to do is hit super
+shift
+c
and boom, rspec path/to/file:line_number
copied to the clipboard and ready to run from the console.
You could use the RSpec sublime package, which works fine until you put a binding.pry
somewhere, which you will.
So now you have to go back to the console and run it from there anyways. If you forget to continue
or kill the spec in the console, every test you run in sublime with RSpec will hang. Hopefully some day RSpec will support pry, until then I'll stick to the console.
Installation
Recommended way is using PackageControl package.
Usage
Hit super
+shift
+c
to send the relevant command to the clipboard. By default it will build the following commands:
- For files ending in _spec.rb
: rspec <file>:<line_number>
- For files in db/migrate
: rake db:migrate:up VERSION=<migration_version>
- For files in lib/tasks
: rake <task_name>
Configuration
The default configuration is:
{
"smart_path_copy_default_rules": [
["_spec\\.rb$", "rspec $filepath:$line_number" ],
["db/migrate/(\\d+)[^\\/]+\\.rb$", "rake db:migrate:up VERSION=$1" ],
["lib/tasks/([^\\/]+)\\.rake$", "rake $1" ]
]
}
Each element in the "smart_path_copy_default_rules"
list consists of a regex expression and a command.
The regex expression serves as a condition: If the file you're currently on satifies the condition (regex), then the command next to it will be copied to the clipboard when you hit super
+shift
+c
.
If no condition is satisfied, the whole path of the current file is copied to the clipboard.
The default configuration is useful if you're developing in rails, but you can add your own configuration in Sublime Text
> Preferences
> Settings
.
If you want to override the default configuration, just add your own "smart_path_copy_default_rules"
. If you want to keep the default configuration and add rules on top of it, use "smart_path_copy_user_rules"
.
Notice that you can add groups in the regexes and use them (as $<group_number>
) in the command.
You can also use in the command section:
- $filepath
: absolute file path of the current file.
- $line_number
: line number the cursor is on.
The default shortcut is super
+shift
+c
, but you can modify it from Sublime Text
> Preferences
> Key Bindings
.
For example, if you want the shortcut to be super
+shift
+h
, you will add:
[
# ...
{ "keys": ["super+shift+h"], "command": "smart_path_copy"},
# ...
]