Bunch of changes inspired by r00k
This commit is contained in:
11
vim/bundle/gist-vim/Makefile
Normal file
11
vim/bundle/gist-vim/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
all : gist-vim.zip
|
||||
|
||||
remove-zip:
|
||||
-rm -f doc/tags
|
||||
-rm -f gist-vim.zip
|
||||
|
||||
gist-vim.zip: remove-zip
|
||||
zip -r gist-vim.zip autoload plugin doc README.mkd
|
||||
|
||||
release: gist-vim.zip
|
||||
vimup update-script gist.vim
|
||||
224
vim/bundle/gist-vim/README.mkd
Normal file
224
vim/bundle/gist-vim/README.mkd
Normal file
@@ -0,0 +1,224 @@
|
||||
### Gist.vim
|
||||
|
||||
This is a vimscript for creating gists (http://gist.github.com).
|
||||
|
||||
For the latest version please see https://github.com/mattn/gist-vim.
|
||||
|
||||
## Usage:
|
||||
|
||||
- Post current buffer to gist, using default privacy option.
|
||||
|
||||
:Gist
|
||||
|
||||
- Post selected text to gist, using default privacy option.
|
||||
This applies to all permutations listed below (except multi).
|
||||
|
||||
:'<,'>Gist
|
||||
|
||||
- Create a private gist.
|
||||
|
||||
:Gist -p
|
||||
|
||||
- Create a public gist.
|
||||
(Only relevant if you've set gists to be private by default.)
|
||||
|
||||
:Gist -P
|
||||
|
||||
> This is only relevant if you've set gists to be private by default;
|
||||
> if you get an empty gist list, try ":Gist --abandon".
|
||||
|
||||
- Create a gist anonymously.
|
||||
|
||||
:Gist -a
|
||||
|
||||
- Create a gist with all open buffers.
|
||||
|
||||
:Gist -m
|
||||
|
||||
- Edit the gist (you need to have opened the gist buffer first).
|
||||
You can update the gist with the ":w" command within the gist buffer.
|
||||
|
||||
:Gist -e
|
||||
|
||||
- Edit the gist with name 'foo.js' (you need to have opened the gist buffer
|
||||
first).
|
||||
|
||||
:Gist -e foo.js
|
||||
|
||||
- Post/Edit with the description " (you need to have opened the gist buffer
|
||||
first). >
|
||||
|
||||
:Gist -s something
|
||||
:Gist -e -s something
|
||||
|
||||
- Delete the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed.
|
||||
|
||||
:Gist -d
|
||||
|
||||
- Fork the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed.
|
||||
|
||||
:Gist -f
|
||||
|
||||
- Star the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed.
|
||||
|
||||
:Gist +1
|
||||
|
||||
- Unstar the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed.
|
||||
|
||||
:Gist -1
|
||||
|
||||
- Get gist XXXXX.
|
||||
|
||||
:Gist XXXXX
|
||||
|
||||
- Get gist XXXXX and add to clipboard.
|
||||
|
||||
:Gist -c XXXXX
|
||||
|
||||
- List your public gists.
|
||||
|
||||
:Gist -l
|
||||
|
||||
- List gists from user "mattn".
|
||||
|
||||
:Gist -l mattn
|
||||
|
||||
- List everyone's gists.
|
||||
|
||||
:Gist -la
|
||||
|
||||
- List gists from your starred gists.
|
||||
|
||||
:Gist -ls
|
||||
|
||||
## Tips:
|
||||
|
||||
If you set g:gist_clip_command, gist.vim will copy the gist code with option
|
||||
'-c'.
|
||||
|
||||
- Mac:
|
||||
|
||||
let g:gist_clip_command = 'pbcopy'
|
||||
|
||||
- Linux:
|
||||
|
||||
let g:gist_clip_command = 'xclip -selection clipboard'
|
||||
|
||||
- Others (cygwin?):
|
||||
|
||||
let g:gist_clip_command = 'putclip'
|
||||
|
||||
If you want to detect filetype from the filename:
|
||||
|
||||
let g:gist_detect_filetype = 1
|
||||
|
||||
If you want to open browser after the post:
|
||||
|
||||
let g:gist_open_browser_after_post = 1
|
||||
|
||||
If you want to change the browser:
|
||||
|
||||
let g:gist_browser_command = 'w3m %URL%'
|
||||
|
||||
or:
|
||||
|
||||
let g:gist_browser_command = 'opera %URL% &'
|
||||
|
||||
On windows, this should work with your user settings.
|
||||
|
||||
If you want to show your private gists with ":Gist -l":
|
||||
|
||||
let g:gist_show_privates = 1
|
||||
|
||||
If you want your gist to be private by default:
|
||||
|
||||
let g:gist_post_private = 1
|
||||
|
||||
If you want to manipulate multiple files in a gist:
|
||||
|
||||
let g:gist_get_multiplefile = 1
|
||||
|
||||
If you want to use on Github Enterprise:
|
||||
|
||||
let g:github_api_url = 'http://your-github-enterprise-domain/api/v3'
|
||||
|
||||
You need to either set global git config:
|
||||
|
||||
$ git config --global github.user Username
|
||||
|
||||
## License:
|
||||
|
||||
Copyright 2010 by Yasuhiro Matsumoto
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
## Install:
|
||||
|
||||
Copy it to your plugin directory.
|
||||
gist.vim will create a curl cookie-jar file in your runtimepath.
|
||||
|
||||
- rtp:
|
||||
- autoload/gist.vim
|
||||
- plugin/gist.vim
|
||||
|
||||
If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`.
|
||||
|
||||
You need to install webapi-vim also:
|
||||
|
||||
http://www.vim.org/scripts/script.php?script_id=4019
|
||||
|
||||
If you want to use latest one:
|
||||
|
||||
https://github.com/mattn/webapi-vim
|
||||
|
||||
### Install with [Vundle](https://github.com/gmarik/vundle)
|
||||
|
||||
Add the following lines to your `.vimrc`.
|
||||
|
||||
Bundle 'mattn/webapi-vim'
|
||||
Bundle 'mattn/gist-vim'
|
||||
|
||||
Now restart Vim and run `:BundleInstall`.
|
||||
|
||||
## Requirements:
|
||||
|
||||
- curl command (http://curl.haxx.se/)
|
||||
- webapi-vim (https://github.com/mattn/webapi-vim)
|
||||
- and if you want to use your git profile, the git command-line client.
|
||||
|
||||
## Setup:
|
||||
|
||||
This plugin uses github API v3. Setting value is stored in `~/.gist-vim`.
|
||||
gist-vim have two ways to access APIs.
|
||||
|
||||
First, you need to set your Github username in global git config:
|
||||
|
||||
$ git config --global github.user Username
|
||||
|
||||
Then, gist.vim will ask for your password to create an authorization when you
|
||||
first use it. The password is not stored and only the OAuth access token will
|
||||
be kept for later use. You can revoke the token at any time from the list of
|
||||
["Authorized applications" on Github's "Account Settings" page](https://github.com/settings/applications).
|
||||
919
vim/bundle/gist-vim/autoload/gist.vim
Normal file
919
vim/bundle/gist-vim/autoload/gist.vim
Normal file
@@ -0,0 +1,919 @@
|
||||
"=============================================================================
|
||||
" File: gist.vim
|
||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||
" Last Change: 21-Jan-2013.
|
||||
" Version: 7.1
|
||||
" WebPage: http://github.com/mattn/gist-vim
|
||||
" License: BSD
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if !exists('g:github_user') && !executable('git')
|
||||
echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
if !executable('curl')
|
||||
echohl ErrorMsg | echomsg "Gist: require 'curl' command" | echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:configfile = expand('~/.gist-vim')
|
||||
|
||||
if !exists('g:github_user')
|
||||
let s:system = function(get(g:, 'webapi#system_function', 'system'))
|
||||
let g:github_user = substitute(s:system('git config --get github.user'), "\n", '', '')
|
||||
if strlen(g:github_user) == 0
|
||||
let g:github_user = $GITHUB_USER
|
||||
end
|
||||
endif
|
||||
|
||||
if !exists('g:github_api_url')
|
||||
let g:github_api_url = 'https://api.github.com'
|
||||
endif
|
||||
|
||||
if !exists('g:gist_update_on_write')
|
||||
let g:gist_update_on_write = 1
|
||||
endif
|
||||
|
||||
function! s:get_browser_command()
|
||||
let gist_browser_command = get(g:, 'gist_browser_command', '')
|
||||
if gist_browser_command == ''
|
||||
if has('win32') || has('win64')
|
||||
let gist_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
|
||||
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
|
||||
let gist_browser_command = 'open %URL%'
|
||||
elseif executable('xdg-open')
|
||||
let gist_browser_command = 'xdg-open %URL%'
|
||||
elseif executable('firefox')
|
||||
let gist_browser_command = 'firefox %URL% &'
|
||||
else
|
||||
let gist_browser_command = ''
|
||||
endif
|
||||
endif
|
||||
return gist_browser_command
|
||||
endfunction
|
||||
|
||||
function! s:open_browser(url)
|
||||
let cmd = s:get_browser_command()
|
||||
if len(cmd) == 0
|
||||
redraw
|
||||
echohl WarningMsg
|
||||
echo "It seems that you don't have general web browser. Open URL below."
|
||||
echohl None
|
||||
echo a:url
|
||||
return
|
||||
endif
|
||||
if cmd =~ '^!'
|
||||
let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g')
|
||||
silent! exec cmd
|
||||
elseif cmd =~ '^:[A-Z]'
|
||||
let cmd = substitute(cmd, '%URL%', '\=a:url', 'g')
|
||||
exec cmd
|
||||
else
|
||||
let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g')
|
||||
call system(cmd)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:shellwords(str)
|
||||
let words = split(a:str, '\%(\([^ \t\''"]\+\)\|''\([^\'']*\)''\|"\(\%([^\"\\]\|\\.\)*\)"\)\zs\s*\ze')
|
||||
let words = map(words, 'substitute(v:val, ''\\\([\\ ]\)'', ''\1'', "g")')
|
||||
let words = map(words, 'matchstr(v:val, ''^\%\("\zs\(.*\)\ze"\|''''\zs\(.*\)\ze''''\|.*\)$'')')
|
||||
return words
|
||||
endfunction
|
||||
|
||||
function! s:format_gist(gist)
|
||||
let files = sort(keys(a:gist.files))
|
||||
if empty(files)
|
||||
return ""
|
||||
endif
|
||||
let file = a:gist.files[files[0]]
|
||||
if has_key(file, "content")
|
||||
let code = file.content
|
||||
let code = "\n".join(map(split(code, "\n"), '" ".v:val'), "\n")
|
||||
else
|
||||
let code = ""
|
||||
endif
|
||||
return printf("gist: %s %s%s", a:gist.id, type(a:gist.description)==0?"": a:gist.description, code)
|
||||
endfunction
|
||||
|
||||
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
|
||||
let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
|
||||
function! s:GistList(gistls, page)
|
||||
if a:gistls == '-all'
|
||||
let url = g:github_api_url.'/gists/public'
|
||||
elseif get(g:, 'gist_show_privates', 0) && a:gistls == 'starred'
|
||||
let url = g:github_api_url.'/gists/starred'
|
||||
elseif get(g:, 'gist_show_privates') && a:gistls == 'mine'
|
||||
let url = g:github_api_url.'/gists'
|
||||
else
|
||||
let url = g:github_api_url.'/users/'.a:gistls.'/gists'
|
||||
endif
|
||||
let winnum = bufwinnr(bufnr(s:bufprefix.a:gistls))
|
||||
if winnum != -1
|
||||
if winnum != bufwinnr('%')
|
||||
exe winnum 'wincmd w'
|
||||
endif
|
||||
setlocal modifiable
|
||||
else
|
||||
exec 'silent noautocmd split' s:bufprefix.a:gistls
|
||||
endif
|
||||
if a:page > 1
|
||||
let oldlines = getline(0, line('$'))
|
||||
let url = url . '?page=' . a:page
|
||||
endif
|
||||
|
||||
setlocal modifiable
|
||||
let old_undolevels = &undolevels
|
||||
let oldlines = []
|
||||
silent %d _
|
||||
|
||||
redraw | echon 'Listing gists... '
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
bw!
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
return
|
||||
endif
|
||||
let res = webapi#http#get(url, '', { "Authorization": auth })
|
||||
if v:shell_error != 0
|
||||
bw!
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg 'Gists not found' | echohl None
|
||||
return
|
||||
endif
|
||||
let content = webapi#json#decode(res.content)
|
||||
if type(content) == 4 && has_key(content, 'message') && len(content.message)
|
||||
bw!
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg content.message | echohl None
|
||||
if content.message == 'Bad credentials'
|
||||
call delete(s:configfile)
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
let lines = map(filter(content, '!empty(v:val.files)'), 's:format_gist(v:val)')
|
||||
call setline(1, split(join(lines, "\n"), "\n"))
|
||||
|
||||
$put='more...'
|
||||
|
||||
let b:gistls = a:gistls
|
||||
let b:page = a:page
|
||||
setlocal buftype=nofile bufhidden=hide noswapfile
|
||||
setlocal nomodified
|
||||
setlocal nomodifiable
|
||||
syntax match SpecialKey /^gist:/he=e-1
|
||||
nnoremap <silent> <buffer> <cr> :call <SID>GistListAction(0)<cr>
|
||||
nnoremap <silent> <buffer> <s-cr> :call <SID>GistListAction(1)<cr>
|
||||
|
||||
cal cursor(1+len(oldlines),1)
|
||||
nohlsearch
|
||||
redraw | echo ''
|
||||
endfunction
|
||||
|
||||
function! gist#list(user, ...)
|
||||
let page = get(a:000, 0, 0)
|
||||
if a:user == '-all'
|
||||
let url = g:github_api_url.'/gists/public'
|
||||
elseif get(g:, 'gist_show_privates', 0) && a:user == 'starred'
|
||||
let url = g:github_api_url.'/gists/starred'
|
||||
elseif get(g:, 'gist_show_privates') && a:user == 'mine'
|
||||
let url = g:github_api_url.'/gists'
|
||||
else
|
||||
let url = g:github_api_url.'/users/'.a:user.'/gists'
|
||||
endif
|
||||
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
return []
|
||||
endif
|
||||
let res = webapi#http#get(url, '', { "Authorization": auth })
|
||||
return webapi#json#decode(res.content)
|
||||
endfunction
|
||||
|
||||
function! s:GistGetFileName(gistid)
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
return ''
|
||||
endif
|
||||
let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth })
|
||||
let gist = webapi#json#decode(res.content)
|
||||
if has_key(gist, 'files')
|
||||
return sort(keys(gist.files))[0]
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! s:GistDetectFiletype(gistid)
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
return ''
|
||||
endif
|
||||
let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth })
|
||||
let gist = webapi#json#decode(res.content)
|
||||
let filename = sort(keys(gist.files))[0]
|
||||
let ext = fnamemodify(filename, ':e')
|
||||
if has_key(s:extmap, ext)
|
||||
let type = s:extmap[ext]
|
||||
else
|
||||
let type = get(gist.files[filename], "type", "text")
|
||||
endif
|
||||
silent! exec "setlocal ft=".tolower(type)
|
||||
endfunction
|
||||
|
||||
function! s:GistWrite(fname)
|
||||
if substitute(a:fname, '\\', '/', 'g') == expand("%:p:gs@\\@/@")
|
||||
if g:gist_update_on_write != 2 || v:cmdbang
|
||||
Gist -e
|
||||
else
|
||||
echohl ErrorMsg | echomsg 'Please type ":w!" to update a gist.' | echohl None
|
||||
endif
|
||||
else
|
||||
exe "w".(v:cmdbang ? "!" : "") fnameescape(v:cmdarg) fnameescape(a:fname)
|
||||
silent! exe "file" fnameescape(a:fname)
|
||||
silent! au! BufWriteCmd <buffer>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GistGet(gistid, clipboard)
|
||||
redraw | echon 'Getting gist... '
|
||||
let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() })
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
let gist = webapi#json#decode(res.content)
|
||||
if get(g:, 'gist_get_multiplefile', 0) != 0
|
||||
let num_file = len(keys(gist.files))
|
||||
else
|
||||
let num_file = 1
|
||||
endif
|
||||
redraw
|
||||
if num_file > len(keys(gist.files))
|
||||
echohl ErrorMsg | echomsg 'Gist not found' | echohl None
|
||||
return
|
||||
endif
|
||||
for n in range(num_file)
|
||||
try
|
||||
let old_undolevels = &undolevels
|
||||
let filename = sort(keys(gist.files))[n]
|
||||
|
||||
let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid."/".filename))
|
||||
if winnum != -1
|
||||
if winnum != bufwinnr('%')
|
||||
exe winnum 'wincmd w'
|
||||
endif
|
||||
setlocal modifiable
|
||||
else
|
||||
exec 'silent noautocmd new'
|
||||
setlocal noswapfile
|
||||
exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename)
|
||||
endif
|
||||
set undolevels=-1
|
||||
filetype detect
|
||||
silent %d _
|
||||
|
||||
let content = gist.files[filename].content
|
||||
call setline(1, split(content, "\n"))
|
||||
let b:gist = {
|
||||
\ "filename": filename,
|
||||
\ "id": gist.id,
|
||||
\ "description": gist.description,
|
||||
\ "private": gist.public =~ 'true',
|
||||
\}
|
||||
catch
|
||||
let &undolevels = old_undolevels
|
||||
bw!
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg 'Gist contains binary' | echohl None
|
||||
return
|
||||
endtry
|
||||
let &undolevels = old_undolevels
|
||||
setlocal buftype=acwrite bufhidden=delete noswapfile
|
||||
setlocal nomodified
|
||||
doau StdinReadPost,BufRead,BufReadPost
|
||||
let gist_detect_filetype = get(g:, 'gist_detect_filetype', 0)
|
||||
if (&ft == '' && gist_detect_filetype == 1) || gist_detect_filetype == 2
|
||||
call s:GistDetectFiletype(a:gistid)
|
||||
endif
|
||||
if a:clipboard
|
||||
if exists('g:gist_clip_command')
|
||||
exec 'silent w !'.g:gist_clip_command
|
||||
elseif has('clipboard')
|
||||
silent! %yank +
|
||||
else
|
||||
%yank
|
||||
endif
|
||||
endif
|
||||
1
|
||||
au! BufWriteCmd <buffer> call s:GistWrite(expand("<amatch>"))
|
||||
endfor
|
||||
else
|
||||
bw!
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg 'Gist not found' | echohl None
|
||||
return
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GistListAction(shift)
|
||||
let line = getline('.')
|
||||
let mx = '^gist:\s*\zs\(\w\+\)\ze.*'
|
||||
if line =~# mx
|
||||
let gistid = matchstr(line, mx)
|
||||
if a:shift
|
||||
call s:open_browser("https://gist.github.com/" . gistid)
|
||||
else
|
||||
call s:GistGet(gistid, 0)
|
||||
endif
|
||||
return
|
||||
endif
|
||||
if line =~# '^more\.\.\.$'
|
||||
call s:GistList(b:gistls, b:page+1)
|
||||
return
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GistUpdate(content, gistid, gistnm, desc)
|
||||
let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') }
|
||||
if exists('b:gist')
|
||||
if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('webapi#json#false') | endif
|
||||
if has_key(b:gist, 'description') | let gist["description"] = b:gist.description | endif
|
||||
if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif
|
||||
else
|
||||
let filename = a:gistnm
|
||||
if len(filename) == 0 | let filename = s:GistGetFileName(a:gistid) | endif
|
||||
if len(filename) == 0 | let filename = s:get_current_filename(1) | endif
|
||||
endif
|
||||
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
" Update description
|
||||
" If no new description specified, keep the old description
|
||||
if a:desc != ' '
|
||||
let gist["description"] = a:desc
|
||||
else
|
||||
let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth })
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
let old_gist = webapi#json#decode(res.content)
|
||||
let gist["description"] = old_gist.description
|
||||
endif
|
||||
endif
|
||||
|
||||
let gist.files[filename] = { "content": a:content, "filename": filename }
|
||||
|
||||
redraw | echon 'Updating gist... '
|
||||
let res = webapi#http#post(g:github_api_url.'/gists/' . a:gistid,
|
||||
\ webapi#json#encode(gist), {
|
||||
\ "Authorization": auth,
|
||||
\ "Content-Type": "application/json",
|
||||
\})
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
let obj = webapi#json#decode(res.content)
|
||||
let loc = obj["html_url"]
|
||||
redraw | echomsg 'Done: '.loc
|
||||
let b:gist = {"id": a:gistid, "filename": filename}
|
||||
setlocal nomodified
|
||||
else
|
||||
let loc = ''
|
||||
let status = matchstr(status, '^\d\+\s*\zs.*')
|
||||
echohl ErrorMsg | echomsg 'Post failed: '.status | echohl None
|
||||
endif
|
||||
return loc
|
||||
endfunction
|
||||
|
||||
function! s:GistDelete(gistid)
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
redraw | echon 'Deleting gist... '
|
||||
let res = webapi#http#post(g:github_api_url.'/gists/'.a:gistid, '', {
|
||||
\ "Authorization": auth,
|
||||
\ "Content-Type": "application/json",
|
||||
\}, 'DELETE')
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
redraw | echomsg 'Done: '
|
||||
if exists('b:gist')
|
||||
unlet b:gist
|
||||
endif
|
||||
else
|
||||
let status = matchstr(status, '^\d\+\s*\zs.*')
|
||||
echohl ErrorMsg | echomsg 'Delete failed: '.status | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:get_current_filename(no)
|
||||
let filename = expand('%:t')
|
||||
if len(filename) == 0 && &ft != ''
|
||||
let pair = filter(items(s:extmap), 'v:val[1] == &ft')
|
||||
if len(pair) > 0
|
||||
let filename = printf('gistfile%d%s', a:no, pair[0][0])
|
||||
endif
|
||||
endif
|
||||
if filename == ''
|
||||
let filename = printf('gistfile%d.txt', a:no)
|
||||
endif
|
||||
return filename
|
||||
endfunction
|
||||
|
||||
" GistPost function:
|
||||
" Post new gist to github
|
||||
"
|
||||
" if there is an embedded gist url or gist id in your file,
|
||||
" it will just update it.
|
||||
" -- by c9s
|
||||
"
|
||||
" embedded gist url format:
|
||||
"
|
||||
" Gist: https://gist.github.com/123123
|
||||
"
|
||||
" embedded gist id format:
|
||||
"
|
||||
" GistID: 123123
|
||||
"
|
||||
function! s:GistPost(content, private, desc, anonymous)
|
||||
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') }
|
||||
if a:desc != ' ' | let gist["description"] = a:desc | endif
|
||||
if a:private | let gist["public"] = function('webapi#json#false') | endif
|
||||
let filename = s:get_current_filename(1)
|
||||
let gist.files[filename] = { "content": a:content, "filename": filename }
|
||||
|
||||
let header = {"Content-Type": "application/json"}
|
||||
if !a:anonymous
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
return
|
||||
endif
|
||||
let header["Authorization"] = auth
|
||||
endif
|
||||
|
||||
redraw | echon 'Posting it to gist... '
|
||||
let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header)
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
let obj = webapi#json#decode(res.content)
|
||||
let loc = obj["html_url"]
|
||||
redraw | echomsg 'Done: '.loc
|
||||
let b:gist = {
|
||||
\ "filename": filename,
|
||||
\ "id": matchstr(loc, '[^/]\+$'),
|
||||
\ "description": gist['description'],
|
||||
\ "private": a:private,
|
||||
\}
|
||||
else
|
||||
let loc = ''
|
||||
let status = matchstr(status, '^\d\+\s*\zs.*')
|
||||
echohl ErrorMsg | echomsg 'Post failed: '.status | echohl None
|
||||
endif
|
||||
return loc
|
||||
endfunction
|
||||
|
||||
function! s:GistPostBuffers(private, desc, anonymous)
|
||||
let bufnrs = range(1, bufnr("$"))
|
||||
let bn = bufnr('%')
|
||||
let query = []
|
||||
|
||||
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') }
|
||||
if a:desc != ' ' | let gist["description"] = a:desc | endif
|
||||
if a:private | let gist["public"] = function('webapi#json#false') | endif
|
||||
|
||||
let index = 1
|
||||
for bufnr in bufnrs
|
||||
if !bufexists(bufnr) || buflisted(bufnr) == 0
|
||||
continue
|
||||
endif
|
||||
echo "Creating gist content".index."... "
|
||||
silent! exec "buffer!" bufnr
|
||||
let content = join(getline(1, line('$')), "\n")
|
||||
let filename = s:get_current_filename(index)
|
||||
let gist.files[filename] = { "content": content, "filename": filename }
|
||||
let index = index + 1
|
||||
endfor
|
||||
silent! exec "buffer!" bn
|
||||
|
||||
let header = {"Content-Type": "application/json"}
|
||||
if !a:anonymous
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
redraw
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
return
|
||||
endif
|
||||
let header["Authorization"] = auth
|
||||
endif
|
||||
|
||||
redraw | echon 'Posting it to gist... '
|
||||
let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header)
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
let obj = webapi#json#decode(res.content)
|
||||
let loc = obj["html_url"]
|
||||
redraw | echomsg 'Done: '.loc
|
||||
let b:gist = {"id": matchstr(loc, '[^/]\+$'), "filename": filename, "private": a:private}
|
||||
else
|
||||
let loc = ''
|
||||
let status = matchstr(status, '^\d\+\s*\zs.*')
|
||||
echohl ErrorMsg | echomsg 'Post failed: '.status | echohl None
|
||||
endif
|
||||
return loc
|
||||
endfunction
|
||||
|
||||
function! gist#Gist(count, line1, line2, ...)
|
||||
redraw
|
||||
if strlen(g:github_user) == 0
|
||||
echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None
|
||||
return
|
||||
endif
|
||||
let bufname = bufname("%")
|
||||
" find GistID: in content , then we should just update
|
||||
let gistid = ''
|
||||
let gistls = ''
|
||||
let gistnm = ''
|
||||
let gistdesc = ' '
|
||||
let private = get(g:, 'gist_post_private', 0)
|
||||
let multibuffer = 0
|
||||
let clipboard = 0
|
||||
let deletepost = 0
|
||||
let editpost = 0
|
||||
let anonymous = 0
|
||||
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
|
||||
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
|
||||
if bufname =~ bufnamemx
|
||||
let gistidbuf = matchstr(bufname, bufnamemx)
|
||||
else
|
||||
let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), 'GistID:\s*\zs\w\+')
|
||||
endif
|
||||
|
||||
let args = (a:0 > 0) ? s:shellwords(a:1) : []
|
||||
for arg in args
|
||||
if arg =~ '^\(-h\|--help\)$\C'
|
||||
help :Gist
|
||||
return
|
||||
elseif arg =~ '^\(-la\|--listall\)$\C'
|
||||
let gistls = '-all'
|
||||
elseif arg =~ '^\(-ls\|--liststar\)$\C'
|
||||
let gistls = 'starred'
|
||||
elseif arg =~ '^\(-l\|--list\)$\C'
|
||||
if get(g:, 'gist_show_privates')
|
||||
let gistls = 'mine'
|
||||
else
|
||||
let gistls = g:github_user
|
||||
endif
|
||||
elseif arg =~ '^\(-m\|--multibuffer\)$\C'
|
||||
let multibuffer = 1
|
||||
elseif arg =~ '^\(-p\|--private\)$\C'
|
||||
let private = 1
|
||||
elseif arg =~ '^\(-P\|--public\)$\C'
|
||||
let private = 0
|
||||
elseif arg =~ '^\(-a\|--anonymous\)$\C'
|
||||
let anonymous = 1
|
||||
elseif arg =~ '^\(-s\|--description\)$\C'
|
||||
let gistdesc = ''
|
||||
elseif arg =~ '^\(-c\|--clipboard\)$\C'
|
||||
let clipboard = 1
|
||||
elseif arg =~ '^--rawurl$\C' && gistidbuf != '' && g:github_api_url == 'https://api.github.com'
|
||||
let gistid = gistidbuf
|
||||
echo 'https://gist.github.com/raw/'.gistid
|
||||
return
|
||||
elseif arg =~ '^\(-d\|--delete\)$\C' && gistidbuf != ''
|
||||
let gistid = gistidbuf
|
||||
let deletepost = 1
|
||||
elseif arg =~ '^\(-e\|--edit\)$\C' && gistidbuf != ''
|
||||
let gistid = gistidbuf
|
||||
let editpost = 1
|
||||
elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != ''
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
else
|
||||
let gistid = gistidbuf
|
||||
let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT')
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
echomsg "Stared" gistid
|
||||
else
|
||||
echohl ErrorMsg | echomsg 'Star failed' | echohl None
|
||||
endif
|
||||
endif
|
||||
return
|
||||
elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != ''
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
else
|
||||
let gistid = gistidbuf
|
||||
let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE')
|
||||
if status =~ '^2'
|
||||
echomsg "Unstared" gistid
|
||||
else
|
||||
echohl ErrorMsg | echomsg 'Unstar failed' | echohl None
|
||||
endif
|
||||
endif
|
||||
return
|
||||
elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != ''
|
||||
let auth = s:GistGetAuthHeader()
|
||||
if len(auth) == 0
|
||||
echohl ErrorMsg | echomsg v:errmsg | echohl None
|
||||
return
|
||||
else
|
||||
let gistid = gistidbuf
|
||||
let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/fork', '', { "Authorization": auth })
|
||||
let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
|
||||
if status =~ '^2'
|
||||
let obj = webapi#json#decode(res.content)
|
||||
let gistid = obj["id"]
|
||||
else
|
||||
echohl ErrorMsg | echomsg 'Fork failed' | echohl None
|
||||
return
|
||||
endif
|
||||
endif
|
||||
elseif arg !~ '^-' && len(gistnm) == 0
|
||||
if gistdesc != ' '
|
||||
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
|
||||
elseif editpost == 1 || deletepost == 1
|
||||
let gistnm = arg
|
||||
elseif len(gistls) > 0 && arg != '^\w\+$\C'
|
||||
let gistls = arg
|
||||
elseif arg =~ '^[0-9a-z]\+$\C'
|
||||
let gistid = arg
|
||||
else
|
||||
echohl ErrorMsg | echomsg 'Invalid arguments: '.arg | echohl None
|
||||
unlet args
|
||||
return 0
|
||||
endif
|
||||
elseif len(arg) > 0
|
||||
echohl ErrorMsg | echomsg 'Invalid arguments: '.arg | echohl None
|
||||
unlet args
|
||||
return 0
|
||||
endif
|
||||
endfor
|
||||
unlet args
|
||||
"echo "gistid=".gistid
|
||||
"echo "gistls=".gistls
|
||||
"echo "gistnm=".gistnm
|
||||
"echo "gistdesc=".gistdesc
|
||||
"echo "private=".private
|
||||
"echo "clipboard=".clipboard
|
||||
"echo "editpost=".editpost
|
||||
"echo "deletepost=".deletepost
|
||||
|
||||
if gistidbuf != '' && gistid == '' && editpost == 0 && deletepost == 0
|
||||
let editpost = 1
|
||||
let gistid = gistidbuf
|
||||
endif
|
||||
|
||||
if len(gistls) > 0
|
||||
call s:GistList(gistls, 1)
|
||||
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
|
||||
call s:GistGet(gistid, clipboard)
|
||||
else
|
||||
let url = ''
|
||||
if multibuffer == 1
|
||||
let url = s:GistPostBuffers(private, gistdesc, anonymous)
|
||||
else
|
||||
if a:count < 1
|
||||
let content = join(getline(a:line1, a:line2), "\n")
|
||||
else
|
||||
let save_regcont = @"
|
||||
let save_regtype = getregtype('"')
|
||||
silent! normal! gvy
|
||||
let content = @"
|
||||
call setreg('"', save_regcont, save_regtype)
|
||||
endif
|
||||
if editpost == 1
|
||||
let url = s:GistUpdate(content, gistid, gistnm, gistdesc)
|
||||
elseif deletepost == 1
|
||||
call s:GistDelete(gistid)
|
||||
else
|
||||
let url = s:GistPost(content, private, gistdesc, anonymous)
|
||||
endif
|
||||
if a:count >= 1 && get(g:, 'gist_keep_selection', 0) == 1
|
||||
silent! normal! gv
|
||||
endif
|
||||
endif
|
||||
if len(url) > 0
|
||||
if get(g:, 'gist_open_browser_after_post', 0) == 1
|
||||
call s:open_browser(url)
|
||||
endif
|
||||
let gist_put_url_to_clipboard_after_post = get(g:, 'gist_put_url_to_clipboard_after_post', 1)
|
||||
if gist_put_url_to_clipboard_after_post > 0
|
||||
if gist_put_url_to_clipboard_after_post == 2
|
||||
let url = url . "\n"
|
||||
endif
|
||||
if exists('g:gist_clip_command')
|
||||
call system(g:gist_clip_command, url)
|
||||
elseif has('unix') && !has('xterm_clipboard')
|
||||
let @" = url
|
||||
else
|
||||
let @+ = url
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:GistGetAuthHeader()
|
||||
if get(g:, 'gist_use_password_in_gitconfig', 0) != 0
|
||||
let password = substitute(system('git config --get github.password'), "\n", '', '')
|
||||
if password =~ '^!' | let password = system(password[1:]) | endif
|
||||
return printf("basic %s", webapi#base64#b64encode(g:github_user.":".password))
|
||||
endif
|
||||
let auth = ""
|
||||
if filereadable(s:configfile)
|
||||
let str = join(readfile(s:configfile), "")
|
||||
if type(str) == 1
|
||||
let auth = str
|
||||
endif
|
||||
endif
|
||||
if len(auth) > 0
|
||||
return auth
|
||||
endif
|
||||
|
||||
redraw
|
||||
echohl WarningMsg
|
||||
echo 'Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".'
|
||||
echohl None
|
||||
let password = inputsecret("Github Password for ".g:github_user.":")
|
||||
if len(password) > 0
|
||||
let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password))
|
||||
let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({
|
||||
\ "scopes" : ["gist"],
|
||||
\ "note" : "Gist.vim on ".hostname(),
|
||||
\ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423"
|
||||
\}), {
|
||||
\ "Content-Type" : "application/json",
|
||||
\ "Authorization" : insecureSecret,
|
||||
\})
|
||||
let authorization = webapi#json#decode(res.content)
|
||||
if has_key(authorization, 'token')
|
||||
let secret = printf("token %s", authorization.token)
|
||||
call writefile([secret], s:configfile)
|
||||
if !(has('win32') || has('win64'))
|
||||
call system("chmod go= ".s:configfile)
|
||||
endif
|
||||
elseif has_key(authorization, 'message')
|
||||
let secret = ''
|
||||
let v:errmsg = authorization.message
|
||||
endif
|
||||
else
|
||||
let secret = ''
|
||||
let v:errmsg = 'Canceled'
|
||||
endif
|
||||
return secret
|
||||
endfunction
|
||||
|
||||
let s:extmap = {
|
||||
\".adb": "ada",
|
||||
\".ahk": "ahk",
|
||||
\".arc": "arc",
|
||||
\".as": "actionscript",
|
||||
\".asm": "asm",
|
||||
\".asp": "asp",
|
||||
\".aw": "php",
|
||||
\".b": "b",
|
||||
\".bat": "bat",
|
||||
\".befunge": "befunge",
|
||||
\".bmx": "bmx",
|
||||
\".boo": "boo",
|
||||
\".c-objdump": "c-objdump",
|
||||
\".c": "c",
|
||||
\".cfg": "cfg",
|
||||
\".cfm": "cfm",
|
||||
\".ck": "ck",
|
||||
\".cl": "cl",
|
||||
\".clj": "clj",
|
||||
\".cmake": "cmake",
|
||||
\".coffee": "coffee",
|
||||
\".cpp": "cpp",
|
||||
\".cppobjdump": "cppobjdump",
|
||||
\".cs": "csharp",
|
||||
\".css": "css",
|
||||
\".cw": "cw",
|
||||
\".d-objdump": "d-objdump",
|
||||
\".d": "d",
|
||||
\".darcspatch": "darcspatch",
|
||||
\".diff": "diff",
|
||||
\".duby": "duby",
|
||||
\".dylan": "dylan",
|
||||
\".e": "e",
|
||||
\".ebuild": "ebuild",
|
||||
\".eclass": "eclass",
|
||||
\".el": "lisp",
|
||||
\".erb": "erb",
|
||||
\".erl": "erlang",
|
||||
\".f90": "f90",
|
||||
\".factor": "factor",
|
||||
\".feature": "feature",
|
||||
\".fs": "fs",
|
||||
\".fy": "fy",
|
||||
\".go": "go",
|
||||
\".groovy": "groovy",
|
||||
\".gs": "gs",
|
||||
\".gsp": "gsp",
|
||||
\".haml": "haml",
|
||||
\".hs": "haskell",
|
||||
\".html": "html",
|
||||
\".hx": "hx",
|
||||
\".ik": "ik",
|
||||
\".ino": "ino",
|
||||
\".io": "io",
|
||||
\".j": "j",
|
||||
\".java": "java",
|
||||
\".js": "javascript",
|
||||
\".json": "json",
|
||||
\".jsp": "jsp",
|
||||
\".kid": "kid",
|
||||
\".lhs": "lhs",
|
||||
\".lisp": "lisp",
|
||||
\".ll": "ll",
|
||||
\".lua": "lua",
|
||||
\".ly": "ly",
|
||||
\".m": "objc",
|
||||
\".mak": "mak",
|
||||
\".man": "man",
|
||||
\".mao": "mao",
|
||||
\".matlab": "matlab",
|
||||
\".md": "markdown",
|
||||
\".minid": "minid",
|
||||
\".ml": "ml",
|
||||
\".moo": "moo",
|
||||
\".mu": "mu",
|
||||
\".mustache": "mustache",
|
||||
\".mxt": "mxt",
|
||||
\".myt": "myt",
|
||||
\".n": "n",
|
||||
\".nim": "nim",
|
||||
\".nu": "nu",
|
||||
\".numpy": "numpy",
|
||||
\".objdump": "objdump",
|
||||
\".ooc": "ooc",
|
||||
\".parrot": "parrot",
|
||||
\".pas": "pas",
|
||||
\".pasm": "pasm",
|
||||
\".pd": "pd",
|
||||
\".phtml": "phtml",
|
||||
\".pir": "pir",
|
||||
\".pl": "perl",
|
||||
\".po": "po",
|
||||
\".py": "python",
|
||||
\".pytb": "pytb",
|
||||
\".pyx": "pyx",
|
||||
\".r": "r",
|
||||
\".raw": "raw",
|
||||
\".rb": "ruby",
|
||||
\".rhtml": "rhtml",
|
||||
\".rkt": "rkt",
|
||||
\".rs": "rs",
|
||||
\".rst": "rst",
|
||||
\".s": "s",
|
||||
\".sass": "sass",
|
||||
\".sc": "sc",
|
||||
\".scala": "scala",
|
||||
\".scm": "scheme",
|
||||
\".scpt": "scpt",
|
||||
\".scss": "scss",
|
||||
\".self": "self",
|
||||
\".sh": "sh",
|
||||
\".sml": "sml",
|
||||
\".sql": "sql",
|
||||
\".st": "smalltalk",
|
||||
\".tcl": "tcl",
|
||||
\".tcsh": "tcsh",
|
||||
\".tex": "tex",
|
||||
\".textile": "textile",
|
||||
\".tpl": "smarty",
|
||||
\".twig": "twig",
|
||||
\".txt" : "text",
|
||||
\".v": "verilog",
|
||||
\".vala": "vala",
|
||||
\".vb": "vbnet",
|
||||
\".vhd": "vhdl",
|
||||
\".vim": "vim",
|
||||
\".weechatlog": "weechatlog",
|
||||
\".xml": "xml",
|
||||
\".xq": "xquery",
|
||||
\".xs": "xs",
|
||||
\".yml": "yaml",
|
||||
\}
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et:
|
||||
279
vim/bundle/gist-vim/doc/gist-vim.txt
Normal file
279
vim/bundle/gist-vim/doc/gist-vim.txt
Normal file
@@ -0,0 +1,279 @@
|
||||
*Gist.vim* Vimscript for creating gists (http://gist.github.com)
|
||||
|
||||
Usage |gist-vim-usage|
|
||||
Tips |gist-vim-tips|
|
||||
License |gist-vim-license|
|
||||
Install |gist-vim-install|
|
||||
Requirements |gist-vim-requirements|
|
||||
Setup |gist-vim-setup|
|
||||
|
||||
This is a vimscript for creating gists (http://gist.github.com)
|
||||
|
||||
For the latest version please see https://github.com/mattn/gist-vim.
|
||||
|
||||
==============================================================================
|
||||
USAGE *:Gist* *gist-vim-usage*
|
||||
|
||||
- Post current buffer to gist, using default privacy option. >
|
||||
|
||||
:Gist
|
||||
<
|
||||
- Post selected text to gist, using defualt privacy option.
|
||||
This applies to all permutations listed below (except multi). >
|
||||
|
||||
:'<,'>Gist
|
||||
<
|
||||
- Create a private gist. >
|
||||
|
||||
:Gist -p
|
||||
<
|
||||
- Create a public gist.
|
||||
(Only relevant if you've set gists to be private by default.) >
|
||||
|
||||
:Gist -P
|
||||
<
|
||||
- Post whole text to gist as public.
|
||||
This is only relevant if you've set gists to be private by default.
|
||||
>
|
||||
:Gist -P
|
||||
<
|
||||
- Create a gist anonymously. >
|
||||
|
||||
:Gist -a
|
||||
<
|
||||
- Create a gist with all open buffers. >
|
||||
|
||||
:Gist -m
|
||||
<
|
||||
- Edit the gist (you need to have opened the gist buffer first).
|
||||
You can update the gist with the {:w} command within the gist buffer. >
|
||||
|
||||
:Gist -e
|
||||
<
|
||||
- Edit the gist with name "foo.js" (you need to have opened the gist buffer
|
||||
first). >
|
||||
|
||||
:Gist -e foo.js
|
||||
<
|
||||
- Post/Edit with the description " (you need to have opened the gist buffer
|
||||
first). >
|
||||
|
||||
:Gist -s something
|
||||
:Gist -e -s something
|
||||
<
|
||||
- Delete the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed. >
|
||||
|
||||
:Gist -d
|
||||
<
|
||||
- Fork the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed. >
|
||||
|
||||
:Gist -f
|
||||
<
|
||||
- Star the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed.
|
||||
>
|
||||
:Gist +1
|
||||
<
|
||||
- Unstar the gist (you need to have opened the gist buffer first).
|
||||
Password authentication is needed.
|
||||
>
|
||||
:Gist -1
|
||||
<
|
||||
- Get gist XXXXX. >
|
||||
|
||||
:Gist XXXXX
|
||||
<
|
||||
- Get gist XXXXX and add to clipboard. >
|
||||
|
||||
:Gist -c XXXXX
|
||||
<
|
||||
- List your public gists. >
|
||||
|
||||
:Gist -l
|
||||
<
|
||||
- List gists from user "mattn". >
|
||||
|
||||
:Gist -l mattn
|
||||
<
|
||||
- List everyone's gists. >
|
||||
|
||||
:Gist -la
|
||||
<
|
||||
- List gists from your starred gists.
|
||||
>
|
||||
:Gist -ls
|
||||
<
|
||||
==============================================================================
|
||||
TIPS *gist-vim-tips*
|
||||
|
||||
If you set "g:gist_clip_command", gist.vim will copy the gist code with option
|
||||
"-c".
|
||||
|
||||
- Mac: >
|
||||
let g:gist_clip_command = 'pbcopy'
|
||||
<
|
||||
- Linux: >
|
||||
let g:gist_clip_command = 'xclip -selection clipboard'
|
||||
<
|
||||
- Others (cygwin?): >
|
||||
let g:gist_clip_command = 'putclip'
|
||||
<
|
||||
If you want to detect filetype from the filename: >
|
||||
|
||||
let g:gist_detect_filetype = 1
|
||||
<
|
||||
If you want to open the browser after the post: >
|
||||
|
||||
let g:gist_open_browser_after_post = 1
|
||||
<
|
||||
If you want to change the browser: >
|
||||
|
||||
let g:gist_browser_command = 'w3m %URL%'
|
||||
<
|
||||
or: >
|
||||
|
||||
let g:gist_browser_command = 'opera %URL% &'
|
||||
<
|
||||
On windows, this should work with your user settings.
|
||||
|
||||
If you want to show your private gists with ":Gist -l": >
|
||||
|
||||
let g:gist_show_privates = 1
|
||||
<
|
||||
If you want your gist to be private by default: >
|
||||
|
||||
let g:gist_post_private = 1
|
||||
|
||||
<
|
||||
If you want to edit all files for gists containing more than one: >
|
||||
|
||||
let g:gist_get_multiplefile = 1
|
||||
<
|
||||
|
||||
If you want to use on Github Enterprise: >
|
||||
|
||||
let g:github_api_url = 'http://your-github-enterprise-domain/api/v3'
|
||||
<
|
||||
|
||||
If you want to update a gist, embed >
|
||||
|
||||
GistID: xxxxx
|
||||
>
|
||||
in your local file, then call >
|
||||
|
||||
:Gist
|
||||
>
|
||||
|
||||
If you want to update a gist when only |:w!|: >
|
||||
|
||||
" :w and :w! update a gist.
|
||||
let g:gist_update_on_write = 1
|
||||
|
||||
" Only :w! updates a gist.
|
||||
let g:gist_update_on_write = 2
|
||||
>
|
||||
All other values are treated as 1.
|
||||
This variable's value is 1 by default.
|
||||
|
||||
==============================================================================
|
||||
LICENSE *gist-vim-license*
|
||||
|
||||
|
||||
Copyright 2010 by Yasuhiro Matsumoto
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
==============================================================================
|
||||
INSTALL *gist-vim-install*
|
||||
|
||||
Copy following files into your plugin directory.
|
||||
|
||||
rtp:
|
||||
- autoload/gist.vim
|
||||
- plugin/gist.vim
|
||||
|
||||
If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`.
|
||||
|
||||
You need to install webapi-vim also:
|
||||
|
||||
http://www.vim.org/scripts/script.php?script_id=4019
|
||||
|
||||
If you want to use latest one:
|
||||
|
||||
https://github.com/mattn/webapi-vim
|
||||
|
||||
==============================================================================
|
||||
REQUIREMENTS *gist-vim-requirements*
|
||||
|
||||
- curl command (http://curl.haxx.se/)
|
||||
- webapi-vim (https://github.com/mattn/webapi-vim)
|
||||
- and, if you want to use your git profile, the git command-line client.
|
||||
|
||||
==============================================================================
|
||||
SETUP *gist-vim-setup*
|
||||
|
||||
This plugin uses github API v3. Setting value is stored in `~/.gist.vim`.
|
||||
gist-vim have two ways to access APIs.
|
||||
|
||||
First, you need to set your Github username in global git config:
|
||||
>
|
||||
$ git config --global github.user Username
|
||||
<
|
||||
Then, gist.vim will ask for your password to create an authorization when you
|
||||
first use it. The password is not stored and only the OAuth access token will
|
||||
be kept for later use. You can revoke the token at any time from the list of
|
||||
"Authorized applications" on Github's "Account Settings" page.
|
||||
(https://github.com/settings/applications)
|
||||
|
||||
If you happen to have your password already written in ~/.gitconfig like
|
||||
below:
|
||||
>
|
||||
[github]
|
||||
password = xxxxx
|
||||
<
|
||||
Then, add following into your ~/.vimrc
|
||||
>
|
||||
let g:gist_use_password_in_gitconfig = 1
|
||||
<
|
||||
This is not secure at all, so strongly discouraged.
|
||||
|
||||
==============================================================================
|
||||
THANKS *gist-vim-thanks*
|
||||
|
||||
AD7six
|
||||
Bruno Bigras
|
||||
c9s
|
||||
Daniel Bretoi
|
||||
Jeremy Michael Cantrell
|
||||
Kien N
|
||||
kongo2002
|
||||
MATSUU Takuto
|
||||
Matthew Weier O'Phinney
|
||||
ornicar
|
||||
Roland Schilter
|
||||
steve
|
||||
tyru
|
||||
Will Gray
|
||||
netj
|
||||
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
||||
9
vim/bundle/gist-vim/doc/tags
Normal file
9
vim/bundle/gist-vim/doc/tags
Normal file
@@ -0,0 +1,9 @@
|
||||
:Gist gist-vim.txt /*:Gist*
|
||||
Gist.vim gist-vim.txt /*Gist.vim*
|
||||
gist-vim-install gist-vim.txt /*gist-vim-install*
|
||||
gist-vim-license gist-vim.txt /*gist-vim-license*
|
||||
gist-vim-requirements gist-vim.txt /*gist-vim-requirements*
|
||||
gist-vim-setup gist-vim.txt /*gist-vim-setup*
|
||||
gist-vim-thanks gist-vim.txt /*gist-vim-thanks*
|
||||
gist-vim-tips gist-vim.txt /*gist-vim-tips*
|
||||
gist-vim-usage gist-vim.txt /*gist-vim-usage*
|
||||
297
vim/bundle/gist-vim/gist.vim.vimup
Normal file
297
vim/bundle/gist-vim/gist.vim.vimup
Normal file
@@ -0,0 +1,297 @@
|
||||
script_name: Gist.vim
|
||||
script_id: '2423'
|
||||
script_type: utility
|
||||
script_package: gist-vim.zip
|
||||
script_version: '7.1'
|
||||
required_vim_version: '7.0'
|
||||
summary: vimscript for gist
|
||||
|
||||
detailed_description: |
|
||||
This is vimscript for gist (http://gist.github.com)
|
||||
|
||||
Usage:
|
||||
|
||||
:Gist
|
||||
post whole text to gist.
|
||||
|
||||
:'<,'>Gist
|
||||
post selected text to gist.
|
||||
|
||||
:Gist -p
|
||||
post whole text to gist with private.
|
||||
if you got empty gist list, try :Gist --abandon
|
||||
|
||||
:Gist -a
|
||||
post whole text to gist with anonymous.
|
||||
|
||||
:Gist -m
|
||||
post multi buffer to gist.
|
||||
|
||||
:Gist -e
|
||||
edit the gist. (shoud be work on gist buffer)
|
||||
you can update the gist with :w command on gist buffer.
|
||||
|
||||
:Gist -e foo.js
|
||||
edit the gist with name 'foo.js'. (shoud be work on gist buffer)
|
||||
|
||||
:Gist -d
|
||||
delete the gist. (should be work on gist buffer)
|
||||
authentication required.
|
||||
|
||||
:Gist -f
|
||||
fork the gist. (should be work on gist buffer)
|
||||
authentication required.
|
||||
|
||||
:Gist XXXXX
|
||||
get gist XXXXX.
|
||||
|
||||
:Gist -c XXXXX.
|
||||
get gist XXXXX and put to clipboard.
|
||||
|
||||
:Gist -l
|
||||
list gists from mine.
|
||||
|
||||
:Gist -la
|
||||
list gists from all.
|
||||
|
||||
Tips:
|
||||
if set g:gist_clip_command, gist.vim will copy the gist code
|
||||
with option '-c'.
|
||||
|
||||
# mac
|
||||
let g:gist_clip_command = 'pbcopy'
|
||||
|
||||
# linux
|
||||
let g:gist_clip_command = 'xclip -selection clipboard'
|
||||
|
||||
# others(cygwin?)
|
||||
let g:gist_clip_command = 'putclip'
|
||||
|
||||
if you want to detect filetype from filename...
|
||||
|
||||
let g:gist_detect_filetype = 1
|
||||
|
||||
if you want to open browser after the post...
|
||||
|
||||
let g:gist_open_browser_after_post = 1
|
||||
|
||||
if you want to change the browser...
|
||||
|
||||
let g:gist_browser_command = 'w3m %URL%'
|
||||
|
||||
or
|
||||
|
||||
let g:gist_browser_command = 'opera %URL% &'
|
||||
|
||||
on windows, should work with original setting.
|
||||
|
||||
Require:
|
||||
curl command (http://curl.haxx.se/)
|
||||
and if you want to use profile of git, it require git command.
|
||||
|
||||
install_details: |
|
||||
copy it to your plugin directory.
|
||||
|
||||
gist.vim leave cookie-jar file into runtimepath.
|
||||
|
||||
rtp:
|
||||
plugin/gist.vim
|
||||
cookies/github
|
||||
|
||||
See also: https://github.com/mattn/gist-vim/blob/master/README.mkd
|
||||
|
||||
versions:
|
||||
- '7.1': |
|
||||
This is an upgrade for Gist.vim: updated installation notes.
|
||||
|
||||
- '7.0': |
|
||||
This is an upgrade for Gist.vim: fixed few bugs.
|
||||
|
||||
- '6.9': |
|
||||
This is an upgrade for Gist.vim: fixed few bugs.
|
||||
|
||||
- '6.8': |
|
||||
This is an upgrade for Gist.vim: changed authentication. removed password authentication. if you want to keep using password authentication, let gist_use_password_in_gitconfig to 1.
|
||||
|
||||
- '6.7': |
|
||||
This is an upgrade for Gist.vim: fix behavior of g:gist_browser_command = ':OpenBrowser %URL%'.
|
||||
|
||||
- '6.6': |
|
||||
This is an upgrade for Gist.vim: fixed detecting filetype.
|
||||
|
||||
- '6.5': |
|
||||
This is an upgrade for Gist.vim: use webapi namespace. NOTE: please upgrade webapi-vim also.
|
||||
|
||||
- '6.4': |
|
||||
This is an upgrade for Gist.vim: fixed updating with description.
|
||||
|
||||
- '6.3': |
|
||||
This is an upgrade for Gist.vim: fixed typos.
|
||||
|
||||
- '6.2': |
|
||||
This is an upgrade for Gist.vim: fixed some bugs.
|
||||
|
||||
- '6.1': |
|
||||
This is an upgrade for Gist.vim: fixed opening browser.
|
||||
|
||||
- '6.0': |
|
||||
This is an upgrade for Gist.vim: changed to use github APIs. Note to remove cookies directory if you used.
|
||||
|
||||
- '5.9': |
|
||||
This is an upgrade for Gist.vim: add support anonymous post. fixed many bugs.
|
||||
|
||||
- '5.8': |
|
||||
This is an upgrade for Gist.vim: add support for description. you can post description using -s option.
|
||||
|
||||
- '5.7': |
|
||||
This is an upgrade for Gist.vim: post with filetype more cleverly.
|
||||
|
||||
- '5.6': |
|
||||
This is an upgrade for Gist.vim: fix '--abandon'.
|
||||
|
||||
- '5.5': |
|
||||
This is an upgrade for Gist.vim: fix: forgot to upload autoload/gist.vim.
|
||||
|
||||
- '5.4': |
|
||||
This is an upgrade for Gist.vim: fix: does not work correctly with blockwize selection.
|
||||
|
||||
- '5.3': |
|
||||
This is an upgrade for Gist.vim: upd: support autoload.
|
||||
|
||||
- '5.2': |
|
||||
This is an upgrade for Gist.vim: add: support block-wise selection.
|
||||
|
||||
- '5.1': |
|
||||
This is an upgrade for Gist.vim: fix: can't update privates.
|
||||
|
||||
- '5.0': |
|
||||
This is an upgrade for Gist.vim: follow update of gist.github.com
|
||||
|
||||
- '4.9': |
|
||||
fix: don't add new line after "Done: xxx".
|
||||
fix: show WHY FAILED' when failed to post.
|
||||
add: support for :OpenBrowser.
|
||||
add: new option 'gist_curl_options'.
|
||||
|
||||
- '4.8': |
|
||||
This is an upgrade for Gist.vim: fix: can't open private gist with ":Gist XXXXX".
|
||||
|
||||
- '4.7': |
|
||||
This is an upgrade for Gist.vim: fix: filetype detection.
|
||||
|
||||
- '4.6': |
|
||||
This is an upgrade for Gist.vim: fix: strange cookies folder.
|
||||
|
||||
- '4.5': |
|
||||
This is an upgrade for Gist.vim: fix: use gist_clip_command for copying URL to clipboard. this fix strange behavior on Mac OSX.
|
||||
|
||||
- '4.4': |
|
||||
This is an upgrade for Gist.vim: fix: gist is now only using https.
|
||||
|
||||
- '4.3': |
|
||||
This is an upgrade for Gist.vim: add new option '-f' for fork.
|
||||
|
||||
- '4.2': |
|
||||
This is an upgrade for Gist.vim: fixed code for login.
|
||||
|
||||
- '4.1': |
|
||||
This is an upgrade for Gist.vim: fixed code cleanup.
|
||||
|
||||
- '4.0': |
|
||||
This is an upgrade for Gist.vim: fixed deleting gist, listing privates.
|
||||
|
||||
- '3.9': |
|
||||
This is an upgrade for Gist.vim: fixed :w handler in gist buffer.
|
||||
|
||||
- '3.8': |
|
||||
This is an upgrade for Gist.vim: 'more...' on gist list.
|
||||
|
||||
- '3.7': |
|
||||
This is an upgrade for Gist.vim: fix problem that break "gist list" window at twice.
|
||||
|
||||
- '3.6': |
|
||||
This is an upgrade for Gist.vim: fix filetype detection for 'vimscript'.
|
||||
|
||||
- '3.5': |
|
||||
This is an upgrade for Gist.vim: fix filetype detection.
|
||||
|
||||
- '3.4': |
|
||||
This is an upgrade for Gist.vim: use '+' register on unix only if built with 'xterm_clipboard'. and some bug fixes.
|
||||
|
||||
- '3.3': |
|
||||
This is an upgrade for Gist.vim: fix problem that append empty line when getting gist.
|
||||
|
||||
- '3.2': |
|
||||
This is an upgrade for Gist.vim: added Gist header to recognize the gist. added script type header for Vimana.
|
||||
|
||||
- '3.1': |
|
||||
This is an upgrade for Gist.vim: fix checking redirect url.
|
||||
|
||||
- '3.0': |
|
||||
This is an upgrade for Gist.vim: fix for official changes(private button name was changed).
|
||||
|
||||
- '2.9': |
|
||||
This is an upgrade for Gist.vim: fix for official changes(private button name was changed).
|
||||
|
||||
- '2.8': |
|
||||
This is an upgrade for Gist.vim: be able to post multi buffer. currently updating or showing not supported. and ':Gist -d' delete the gist.
|
||||
|
||||
- '2.7': |
|
||||
This is an upgrade for Gist.vim: be able to write the gist to local file with ':w foo.txt'.
|
||||
|
||||
- '2.6': |
|
||||
This is an upgrade for Gist.vim: fixed problem that does not work 'Gist XXXX'.
|
||||
|
||||
- '2.5': |
|
||||
This is an upgrade for Gist.vim: use existing buffer when open the list or gist.
|
||||
|
||||
- '2.4': |
|
||||
This is an upgrade for Gist.vim: show error message when no any github settings.
|
||||
|
||||
- '2.3': |
|
||||
This is an upgrade for Gist.vim: added :w BufWriteCmd for GistUpdate.
|
||||
|
||||
- '2.2': |
|
||||
This is an upgrade for Gist.vim: fixed a bug for anonymous post. and new option '-a' for anonymous post.
|
||||
|
||||
- '2.1': |
|
||||
This is an upgrade for Gist.vim: support changing gist filename.
|
||||
|
||||
- '2.0': |
|
||||
This is an upgrade for Gist.vim: bugfix for listing gists in specified user.
|
||||
|
||||
- '1.9': |
|
||||
This is an upgrade for Gist.vim: added support editing the gist. and bits bug fix.
|
||||
|
||||
- '1.8': |
|
||||
This is an upgrade for Gist.vim: added new option g:gist_open_browser_after_post/g:gist_browser_command to open posted gist.
|
||||
|
||||
- '1.7': |
|
||||
This is an upgrade for Gist.vim: now changed argument for putting clipboard as ':Gist -c XXXXX'.
|
||||
|
||||
- '1.6': |
|
||||
This is an upgrade for Gist.vim: add gist's author in gist list.
|
||||
|
||||
- '1.5': |
|
||||
This is an upgrade for Gist.vim: oops. bugfix for auto-detection.
|
||||
|
||||
- '1.4': |
|
||||
This is an upgrade for Gist.vim: bugfix for auto-detection.
|
||||
|
||||
- '1.3': |
|
||||
This is an upgrade for Gist.vim: more auto-detection for filetype.
|
||||
|
||||
- '1.2': |
|
||||
This is an upgrade for Gist.vim: added new option for detect filetype from filename.
|
||||
|
||||
- '1.1': |
|
||||
This is an upgrade for Gist.vim: calling StdinReadPost.
|
||||
|
||||
- '1.0': |
|
||||
This is an upgrade for Gist.vim: treat literal "-" as part of username.
|
||||
|
||||
- '0.9': |
|
||||
This is an upgrade for Gist.vim: added new option 'g:gist_clip_command' that copy the gist code.
|
||||
|
||||
# __END__
|
||||
# vim: filetype=yaml
|
||||
16
vim/bundle/gist-vim/plugin/gist.vim
Normal file
16
vim/bundle/gist-vim/plugin/gist.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
"=============================================================================
|
||||
" File: gist.vim
|
||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||
" WebPage: http://github.com/mattn/gist-vim
|
||||
" License: BSD
|
||||
" GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim
|
||||
" script type: plugin
|
||||
|
||||
if &cp || (exists('g:loaded_gist_vim') && g:loaded_gist_vim)
|
||||
finish
|
||||
endif
|
||||
let g:loaded_gist_vim = 1
|
||||
|
||||
command! -nargs=? -range=% Gist :call gist#Gist(<count>, <line1>, <line2>, <f-args>)
|
||||
|
||||
" vim:set et:
|
||||
Reference in New Issue
Block a user