While viewing code in our IDE we often want to send a reference to the code, paste it on the specs/tasks, or just open it with an online repository. This document explains how we can do it easily using a small bridge snippet
- Copy Bridge folder to your preferred location
for example:
/Applications/Bridge/
- Add execute permissions to your program
for example:
sudo chmod +x /Applications/Bridge/bridge
- Configure the commands you want to use on configure.json:
{
commands:
[
{
"name": a unique name to be used to call the commands,
"operation": "open"/"copy"/"search",
"with": "onlineRepositories",
"repository": use a name from the onlineRepositories list
}
]
onlineRepositories:
[
{
"name": a unique name for the repository,
"one_line": link to the online repository when one line is selected
(can include {file}, {line}),
"multi_line": link to the online repository when multi line is selected
(can include {file}, {fromline}, {toline})
"search": link to the online repository's search with the selected text
(can include {file}, {text})
}
]
}
- Connect to your IDE:
- Install Bridge
- Add as PyCharm external tool : on PyCharm go to top menu option Pycharm → Preferences… → Tools → External tools → + → Fill the new external tool:
Name: Open in Github
Group: Web Viewers
Program: /Applications/Bridge/bridge
Parameters: open-bridge-github -f $FilePathRelativeToProjectRoot$ -l $LineNumber$ -a $SelectionStartLine$ -z $SelectionEndLine$ -t "$SelectedText$"
Working Directory: You can leave it empty
That’s it. You are ready to go! On the top menu go to Tools → Web viewers → Open in Github.
In order to launch different command (e.g: copy to clipboard, open with Github, etc.), add/edit your require command on configure.json (see Install Bridge), and paste its name as the first params on the Parameters list of the external tool
Different ways to invoke bridge:
a. Execute from top menu: Tools → < group name > → < tool name > b. Add as toolbar button: Right click the toolbar you want to add the button to → Customize Menus and Toolbars → Browse to the place you want to add the button → Add after.. → External Tools → < group name > → < tool name > c. Add to right click context menu: Right click the toolbar you want to add the button to → Customize Menus and Toolbars → Main Toolbar → Browse to the place you want to add the button → Add after.. → External Tools → < group name > → < tool name >
on the top menu go to PyCharm → Preferences.. → Keymap → External tools → < group name > → < tool name >.
You can use any icons you want, or the ones I used in the icons folder. Source: Open Externally icon, Link Icon, magnifier
- Install
- copy the BridgeST3Plugin folder to /Packages (the default is ~/Library/Application Support/Sublime Text 3/Packages/ )
- That’s it. Right click on the row, or multiple rows to get the bridge options:
edit configure.py: working_dirs=["/path/to/working_dir"] bin_file_path="/Applications/Bridge/bridge"
- working_dirs - as default, bridge takes the root path of your project, but if you open files independently (without project context) , you may want your roots to this list
- bin_file_path - full path to bridge executable
Add / edit commands on bridgePlugin.py - following to the bash command params
Call bridgeRunCommand.run_command(self.view, "open-bridge-github")
with the command name defined in configure.json (see Install Bridge for how to define commands).
To create a menu entry you first need to decide where you want it to be viewed. You have three choices that have corresponding file names:
- Main.sublime-menu
- Side Bar.sublime-menu
- Context.sublime-menu (the plugin is supplied with this as default)
Add json entry to your file with the following format*:
[
{
"id" : "copytogithub",
"caption" : "Copy to Github",
"command" : "bridge_copy_bridge_github"
},
{
"id" : "openingithub",
"caption" : "Open in Github",
"command" : "bridge_open_bridge_github"
},
{
"id" : "searchingithub",
"caption" : "Search in Github",
"command" : "bridge_search_bridge_github"
},
]
(OSX) “Sublime Text” -> “Preferences” -> “Key Bindings – Default” *
*For the command you’ll need to strip the “command” string off of the end and take the beginning as the actual name in lower case. Multiple capitals will result in underscore separators between words. (ex: BridgeOpenGithubCommand = bridge_open_github) See more details here on Step 3 – Creating Menus and Key Bindings
- Install Bridge
- Call from command line:
/path/to/bridge <your commande name> -l <LineNumber> -a <multi lines first line> -z <multi lines first line> -t "selected text">
for example:/Applications/Bridge/bridge open-bridge-github -a 10 -z 12