Post snippet from vim/neovim to Slack, instancely!
There are 3 features:
- Post with no options instancely.
- Set file name, line number and file-type syntax.
- Set GitHub URL as a comment (If remote repository is in Github).
- Vim 8.0 or Neovim
curl
commandgit
command (to get GitHub remote URL)
call dein#add('abekoh/snipslack.vim')
Plug 'abekoh/snipslack.vim'
You have to prepare a Slack token to use files.upload API.
Steps to get a token (last updated at Dec. 2, 2018):
- Access https://api.slack.com/apps, click "Create New App" and create an app in your workspace (or use existed app).
- Click "OAuth & Permissions", find Scopes, select "Upload and modify files as user (files:write:user)". After, click "Save Changes".
- Scroll to top, click "Install App to Workspace" and authorize.
- Then you can get "Oauth Access Token".
If you got a token, add following into your Vim/Neovim config file.
let g:snipslack_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Note: This config should not be open to the public. Handle this with care.
And you have to set channel to post snippet. If you want to post into #snippets, like this:
let g:snipslack_default_channel = '#snippets'
If you want to post as DM, like this:
let g:snipslack_default_channel = '@abekoh'
Now setup is finished, you are able to post snippets!
If you want to post all of current buffer, use like this:
:SnipSlack
If you want to post a part of current buffer, select with visual mode and type above command. As a result command will be like this:
:'<,'>SnipSlack
If it succeeds, you can see a snippet in Slack channel that you configured.
Limit of snippet's line. Default: 1000
g:snipslack_limit_lines = 500
Enable to post with GitHub URL. Set 0 to disable. Default: 1
g:snipslack_enable_github_url = 0
List of git's remote names. When it get GitHub URL, search from head of this list.
Default: ['origin']
g:snipslack_github_remotes = ['origin', 'second']
List of remote git service domains. You can set domains that is compatible to GitHub, like GitHub Enterprise.
Default: ['github.com']
g:snipslack_github_domains = ['github.com', 'my.github.enterprise.jp']