git subrepo clone (merge) https://github.com/kristijanhusak/vim-carbon-now-sh.git ./dotfiles/.vim/plugged/vim-carbon-now-sh
subrepo: subdir: "dotfiles/.vim/plugged/vim-carbon-now-sh" merged: "31a18d26" upstream: origin: "https://github.com/kristijanhusak/vim-carbon-now-sh.git" branch: "master" commit: "31a18d26" git-subrepo: version: "0.4.3" origin: "???" commit: "???"
This commit is contained in:
parent
f20dba1346
commit
be93c28e01
5 changed files with 275 additions and 0 deletions
12
dotfiles/.vim/plugged/vim-carbon-now-sh/.gitrepo
Normal file
12
dotfiles/.vim/plugged/vim-carbon-now-sh/.gitrepo
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
; DO NOT EDIT (unless you know what you are doing)
|
||||||
|
;
|
||||||
|
; This subdirectory is a git "subrepo", and this file is maintained by the
|
||||||
|
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
|
||||||
|
;
|
||||||
|
[subrepo]
|
||||||
|
remote = https://github.com/kristijanhusak/vim-carbon-now-sh.git
|
||||||
|
branch = master
|
||||||
|
commit = 31a18d26fc27e7bd5786da092ed886273b4cf639
|
||||||
|
parent = f20dba134673774a62af43e0e0c923ceb4757a83
|
||||||
|
method = merge
|
||||||
|
cmdver = 0.4.3
|
21
dotfiles/.vim/plugged/vim-carbon-now-sh/LICENSE
Normal file
21
dotfiles/.vim/plugged/vim-carbon-now-sh/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Kristijan Husak
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
60
dotfiles/.vim/plugged/vim-carbon-now-sh/README.md
Normal file
60
dotfiles/.vim/plugged/vim-carbon-now-sh/README.md
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# vim-carbon-now-sh
|
||||||
|
|
||||||
|
(n)vim implementation plugin for opening selected content in [https://carbon.now.sh](https://carbon.now.sh).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### Vundle
|
||||||
|
|
||||||
|
Add the following line to your `.vimrc`
|
||||||
|
|
||||||
|
```vimL
|
||||||
|
Plugin 'kristijanhusak/vim-carbon-now-sh'
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run the following in Vim:
|
||||||
|
|
||||||
|
```
|
||||||
|
:source %
|
||||||
|
:PluginInstall
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Select some text in visual mode and run this command:
|
||||||
|
```vimL
|
||||||
|
:CarbonNowSh
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also map it to something and use it after selection:
|
||||||
|
|
||||||
|
```vimL
|
||||||
|
vnoremap <F5> :CarbonNowSh<CR>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Alternate Endpoint
|
||||||
|
To send your code snippets to a local instance of carbon.now instead of the public, shared site
|
||||||
|
(e.g. if you're doing private development, your code is internal, etc.), pass in an alternate
|
||||||
|
base URL via your Vim config:
|
||||||
|
|
||||||
|
```vimL
|
||||||
|
let g:carbon_now_sh_base_url = 'http://localhost:3000'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Browser
|
||||||
|
Plugin will try it's best to use your default browser. If it fails, or you want to customize it,
|
||||||
|
provide browser executable through this option to your vimrc. Example for google-chrome:
|
||||||
|
|
||||||
|
```vimL
|
||||||
|
let g:carbon_now_sh_browser = 'google-chrome'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
You can set the query string that will be passed to [https://carbon.now.sh](https://carbon.now.sh).
|
||||||
|
Example for setting font and line number:
|
||||||
|
|
||||||
|
```vimL
|
||||||
|
let g:carbon_now_sh_options =
|
||||||
|
\ { 'ln': 'true',
|
||||||
|
\ 'fm': 'Source Code Pro' }
|
||||||
|
```
|
|
@ -0,0 +1,60 @@
|
||||||
|
*vim-carbon-now-sh.txt* Open selected text in https://carbon.now.sh
|
||||||
|
|
||||||
|
Open selected text in https://carbon.now.sh
|
||||||
|
|
||||||
|
Author: Kristijan <husakkristijan at gmail.com>
|
||||||
|
License: MIT
|
||||||
|
|
||||||
|
vim-carbon-now-sh *vim-carbon-now-sh*
|
||||||
|
|
||||||
|
1. Introduction |vim-carbon-now-sh-introduction|
|
||||||
|
2. Install |vim-carbon-now-sh-install|
|
||||||
|
3. Commands |vim-carbon-now-sh-commands|
|
||||||
|
4. Settings |vim-carbon-now-sh-settings|
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
1. Introduction *vim-carbon-now-sh-introduction*
|
||||||
|
|
||||||
|
(n)vim implementation plugin for opening selected content in https://carbon.now.sh
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
2. Install *vim-carbon-now-sh-install*
|
||||||
|
|
||||||
|
Install with `Plug`
|
||||||
|
`Plug 'kristijanhusak/vim-carbon-now-sh'`
|
||||||
|
|
||||||
|
Add mapping:
|
||||||
|
`vnoremap <F5> :CarbonNowSh`
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
3. Commands *vim-carbon-now-sh-commands*
|
||||||
|
|
||||||
|
CarbonNowSh *:CarbonNowSh*
|
||||||
|
Used for sending seleted text to https://carbon.now.sh
|
||||||
|
|
||||||
|
`:CarbonNowSh`
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
4. Settings *vim-carbon-now-sh-settings*
|
||||||
|
|
||||||
|
*g:carbon_now_sh_options*
|
||||||
|
g:carbon_now_sh_options
|
||||||
|
Options passed as query string when opening
|
||||||
|
https://carbon.now.sh. Must not contain `?`.
|
||||||
|
|
||||||
|
Default value: `{}`
|
||||||
|
|
||||||
|
g:carbon_now_sh_base_url
|
||||||
|
Protocol, host name, and port for the carbon.now.sh
|
||||||
|
instance to send code snippets to. Note: no trailing slash.
|
||||||
|
|
||||||
|
Default value: 'https://carbon.now.sh'
|
||||||
|
|
||||||
|
g:carbon_now_sh_browser
|
||||||
|
Browser used to open url. If nothing is set, it tries to
|
||||||
|
detect default browser by operating system.
|
||||||
|
|
||||||
|
Default value: ''
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
vim:tw=78:ts=8:ft=help:norl:noet:fen:noet:
|
|
@ -0,0 +1,122 @@
|
||||||
|
if exists('g:carbon_now_sh_loaded')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let g:carbon_now_sh_loaded = 1
|
||||||
|
|
||||||
|
let g:carbon_now_sh_options = get(g:, 'carbon_now_sh_options', {})
|
||||||
|
let g:carbon_now_sh_browser = get(g:, 'carbon_now_sh_browser', '')
|
||||||
|
let g:carbon_now_sh_base_url = get(g:, 'carbon_now_sh_base_url', 'https://carbon.now.sh')
|
||||||
|
let g:carbon_now_sh_trace = get(g:, 'carbon_now_sh_trace', 0)
|
||||||
|
|
||||||
|
command! -range=% CarbonNowSh <line1>,<line2>call s:carbonNowSh()
|
||||||
|
|
||||||
|
function! s:carbonNowSh() range
|
||||||
|
let l:text = s:urlEncode(s:getVisualSelection())
|
||||||
|
let l:browser = s:getBrowser()
|
||||||
|
let l:options = type(g:carbon_now_sh_options) == v:t_dict ? s:getOptions() : g:carbon_now_sh_options
|
||||||
|
let l:filetype = &filetype
|
||||||
|
let l:url = g:carbon_now_sh_base_url .. '/?l=' .. l:filetype .. '&code=' .. l:text .. '&' .. l:options
|
||||||
|
|
||||||
|
if g:carbon_now_sh_trace
|
||||||
|
echom 'navigate to: ' . l:url
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has('win32') && l:browser ==? 'start' && &shell =~? '\<cmd\.exe$'
|
||||||
|
return system(l:browser .. ' "" "' .. l:url .. '"')
|
||||||
|
endif
|
||||||
|
|
||||||
|
call system(l:browser .. escape(' ' .. l:url, '?&%'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:getBrowser() "{{{
|
||||||
|
if g:carbon_now_sh_browser !=? ''
|
||||||
|
return g:carbon_now_sh_browser
|
||||||
|
endif
|
||||||
|
|
||||||
|
if executable('xdg-open')
|
||||||
|
return 'xdg-open'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has('win32')
|
||||||
|
return 'start'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if executable('open')
|
||||||
|
return 'open'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if executable('google-chrome')
|
||||||
|
return 'google-chrome'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if executable('firefox')
|
||||||
|
return 'firefox'
|
||||||
|
endif
|
||||||
|
|
||||||
|
throw 'Browser not found'
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:getOptions() "{{{
|
||||||
|
let l:options = g:carbon_now_sh_options
|
||||||
|
let l:result = ''
|
||||||
|
for l:key in keys(l:options)
|
||||||
|
let l:result = l:result .. '&' .. s:urlEncode(l:key) .. '=' .. s:urlEncode(l:options[key])
|
||||||
|
endfor
|
||||||
|
return l:result[1:]
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:urlEncode(string) "{{{
|
||||||
|
let l:result = ''
|
||||||
|
|
||||||
|
let l:characters = split(a:string, '.\zs')
|
||||||
|
for l:character in l:characters
|
||||||
|
if s:characterRequiresUrlEncoding(l:character)
|
||||||
|
let l:i = 0
|
||||||
|
while l:i < strlen(l:character)
|
||||||
|
let l:byte = strpart(l:character, l:i, 1)
|
||||||
|
let l:decimal = char2nr(l:byte)
|
||||||
|
let l:result = l:result .. '%' .. printf('%02x', l:decimal)
|
||||||
|
let l:i += 1
|
||||||
|
endwhile
|
||||||
|
else
|
||||||
|
let l:result = l:result .. l:character
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:result
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:characterRequiresUrlEncoding(character) "{{{
|
||||||
|
let l:ascii_code = char2nr(a:character)
|
||||||
|
|
||||||
|
if l:ascii_code >= 48 && l:ascii_code <= 57
|
||||||
|
return 0
|
||||||
|
elseif l:ascii_code >= 65 && l:ascii_code <= 90
|
||||||
|
return 0
|
||||||
|
elseif l:ascii_code >= 97 && l:ascii_code <= 122
|
||||||
|
return 0
|
||||||
|
elseif a:character ==? '-' || a:character ==? '_' || a:character ==? '.' || a:character ==? '~'
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 1
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:getVisualSelection() "{{{
|
||||||
|
let [l:line_start, l:column_start] = getpos("'<")[1:2]
|
||||||
|
let [l:line_end, l:column_end] = getpos("'>")[1:2]
|
||||||
|
let l:lines = getline(l:line_start, l:line_end)
|
||||||
|
|
||||||
|
if len(l:lines) == 0
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:lines[-1] = l:lines[-1][:l:column_end - (&selection ==? 'inclusive' ? 1 : 2)]
|
||||||
|
let l:lines[0] = l:lines[0][l:column_start - 1:]
|
||||||
|
|
||||||
|
return join(l:lines, "\n")
|
||||||
|
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
" vim:foldenable:foldmethod=marker:sw=2
|
Loading…
Reference in a new issue